Skip to content

Commit f1f7373

Browse files
committed
runtime/CMakeLists.txt: Always use target triple in ldc2.conf for libdir
Don't use the string "default" in the configuration file for the native libraries, instead prefer the target triple (x86_64-.*-linux-gnu for example), similarly to what is done for the MULTILIB build. This is done for two reasons: 1. Keeps the filenames consistent as, now, we can name all the config files 30-ldc-runtime... instead of forcing the native one to be 30 and all the cross ones to be 31. 2. It allows simpler plug-and-play for cross runtime builds (through ldc-build-runtime for example) as the configuration file can now be installed alongside the compiler without its libdirs conflicting with the native ones. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
1 parent 16bc6fd commit f1f7373

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

runtime/CMakeLists.txt

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -268,48 +268,31 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
268268
list(APPEND switches "-link-defaultlib-shared=false")
269269
endif()
270270

271-
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
272-
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
273-
274-
# Default -rpath linker option when linking against shared libraries.
275-
if(SHARED_LIBS_SUPPORTED)
276-
set(build_rpath "${build_libdir}")
277-
set(install_rpath "${install_libdir}")
278-
endif()
271+
# For windows, to call fill-multilib-section.sh we need an explicit bash.exe call
272+
find_program(BASH bash REQUIRED)
279273

280-
makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
281-
SECTION "default"
282-
283-
BUILD
284-
SWITCHES ${switches}
285-
LIB_DIRS OVERRIDE ${build_libdir}
286-
RPATH ${build_rpath}
287-
288-
INSTALL
289-
SWITCHES ${switches}
290-
LIB_DIRS OVERRIDE ${install_libdir}
291-
RPATH ${install_rpath}
292-
)
274+
# comp_args are arguments passed to ldc2 to change the triple
275+
function(makeTripleConfig comp_args suffix build_libdir install_libdir)
276+
set(name "30-ldc-runtime-lib${suffix}")
277+
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
293278

294-
# macOS has fat libraries; otherwise, append a separate config file section for the
295-
# multilib target and override the lib directory.
296-
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
297-
set(build_libdir "${CMAKE_BINARY_DIR}/lib${MULTILIB_SUFFIX}")
298-
set(install_libdir "${CMAKE_INSTALL_PREFIX}/lib${MULTILIB_SUFFIX}")
279+
# Default -rpath linker option when linking against shared libraries.
299280
if(SHARED_LIBS_SUPPORTED)
300281
set(build_rpath "${build_libdir}")
301282
set(install_rpath "${install_libdir}")
302283
endif()
303284

304-
set(name "31-ldc-runtime-lib${MULTILIB_SUFFIX}")
305-
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
306285
makeConfSection(NAME "${name}"
307286
SECTION "${sectionPlaceholder}"
287+
308288
BUILD
289+
SWITCHES ${switches}
309290
LIB_DIRS OVERRIDE ${build_libdir}
310291
RPATH ${build_rpath}
292+
311293
INSTALL
312-
LIB_DIRS OVERRIDE ${install_libdir}
294+
SWITCHES ${switches}
295+
LIB_DIRS ${install_libdir}
313296
RPATH ${install_rpath}
314297
)
315298

@@ -320,18 +303,19 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
320303
# Rename the just-generated config files in order to replace sectionPlaceholder
321304
file(RENAME "${conf}" "${conf}.in")
322305
set(fill_cmd
306+
"${BASH}"
323307
"${PROJECT_PARENT_DIR}/tools/fill-multilib-triple.sh"
324308
"${conf}.in"
325309
"${conf}"
326310
"${sectionPlaceholder}"
327311
# Next arguments are a compiler invocation for the desired triple
328-
"${LDC_EXE_FULL}" -m${MULTILIB_SUFFIX}
312+
"${LDC_EXE_FULL}" ${D_FLAGS} ${comp_args}
329313
)
330314
if(LDC_EXE)
331-
# We need to get the -m32 target triple but the compiler
332-
# is not built yet. We can't depend on LDC_EXE since that
333-
# would cause a cycle so pass-through the needed commands
334-
# up to the root project and let it run them as POST_BUILD
315+
# We need to get the target triple but the compiler is not
316+
# built yet. We can't depend on LDC_EXE since that would
317+
# cause a cycle so pass-through the needed commands up to
318+
# the root project and let it run them as POST_BUILD
335319
# commands. This avoids adding the config_files as
336320
# transitive dependencies to all compiled D files.
337321
#
@@ -345,6 +329,22 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
345329
execute_process(COMMAND ${fill_cmd})
346330
endif()
347331
endforeach()
332+
333+
set(_ALL_CONF_INSTALL_FILES "${_ALL_CONF_INSTALL_FILES}" PARENT_SCOPE)
334+
set(_LDC_POST_BUILD_COMMANDS "${_LDC_POST_BUILD_COMMANDS}" PARENT_SCOPE)
335+
set(_LDC_POST_BUILD_BYPRODUCTS "${_LDC_POST_BUILD_BYPRODUCTS}" PARENT_SCOPE)
336+
endfunction()
337+
338+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
339+
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
340+
makeTripleConfig("" "${LIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
341+
342+
# macOS has fat libraries; otherwise, append a separate config file section for the
343+
# multilib target and override the lib directory.
344+
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
345+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${MULTILIB_SUFFIX}")
346+
set(install_libdir "${CMAKE_INSTALL_PREFIX}/lib${MULTILIB_SUFFIX}")
347+
makeTripleConfig("-m${MULTILIB_SUFFIX}" "${MULTILIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
348348
endif()
349349

350350
if(LDC_EXE)

runtime/ldc-build-runtime.d.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ void runCMake() {
175175
args ~= [
176176
"-DCMAKE_INSTALL_PREFIX=" ~ config.ldcExecutable.dirName.dirName,
177177
"-DLIB_SUFFIX=" ~ config.installWithSuffix,
178-
"-DCONF_INST_DIR=", // don't install/overwrite existing etc/ldc2.conf!
179178
];
179+
if (config.confPreferDir && hostHasDirConfig) {
180+
// All fine, the config files won't conflict
181+
} else {
182+
// don't install/overwrite existing etc/ldc2.conf!
183+
args ~= "-DCONF_INST_DIR=";
184+
}
180185
}
181186
if (config.confPreferDir) args ~= "-DCONF_PREFER_DIR=ON";
182187

0 commit comments

Comments
 (0)