Skip to content

Commit 0b457f5

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 8d2f6b9 commit 0b457f5

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
@@ -269,48 +269,31 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
269269
list(APPEND switches "-link-defaultlib-shared=false")
270270
endif()
271271

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

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

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

305-
set(name "31-ldc-runtime-lib${MULTILIB_SUFFIX}")
306-
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
307286
makeConfSection(NAME "${name}"
308287
SECTION "${sectionPlaceholder}"
288+
309289
BUILD
290+
SWITCHES ${switches}
310291
LIB_DIRS OVERRIDE ${build_libdir}
311292
RPATH ${build_rpath}
293+
312294
INSTALL
313-
LIB_DIRS OVERRIDE ${install_libdir}
295+
SWITCHES ${switches}
296+
LIB_DIRS ${install_libdir}
314297
RPATH ${install_rpath}
315298
)
316299

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

351351
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)