Skip to content

Commit 14e8a43

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 14e8a43

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

runtime/CMakeLists.txt

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -268,48 +268,28 @@ 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()
279-
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-
)
271+
# comp_args are arguments passed to ldc2 to change the triple
272+
function(makeTripleConfig comp_args suffix build_libdir install_libdir)
273+
set(name "30-ldc-runtime-lib${suffix}")
274+
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
293275

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}")
276+
# Default -rpath linker option when linking against shared libraries.
299277
if(SHARED_LIBS_SUPPORTED)
300278
set(build_rpath "${build_libdir}")
301279
set(install_rpath "${install_libdir}")
302280
endif()
303281

304-
set(name "31-ldc-runtime-lib${MULTILIB_SUFFIX}")
305-
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
306282
makeConfSection(NAME "${name}"
307283
SECTION "${sectionPlaceholder}"
284+
308285
BUILD
286+
SWITCHES ${switches}
309287
LIB_DIRS OVERRIDE ${build_libdir}
310288
RPATH ${build_rpath}
289+
311290
INSTALL
312-
LIB_DIRS OVERRIDE ${install_libdir}
291+
SWITCHES ${switches}
292+
LIB_DIRS ${install_libdir}
313293
RPATH ${install_rpath}
314294
)
315295

@@ -325,13 +305,13 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
325305
"${conf}"
326306
"${sectionPlaceholder}"
327307
# Next arguments are a compiler invocation for the desired triple
328-
"${LDC_EXE_FULL}" -m${MULTILIB_SUFFIX}
308+
"${LDC_EXE_FULL}" ${D_FLAGS} ${comp_args}
329309
)
330310
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
311+
# We need to get the target triple but the compiler is not
312+
# built yet. We can't depend on LDC_EXE since that would
313+
# cause a cycle so pass-through the needed commands up to
314+
# the root project and let it run them as POST_BUILD
335315
# commands. This avoids adding the config_files as
336316
# transitive dependencies to all compiled D files.
337317
#
@@ -345,6 +325,22 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
345325
execute_process(COMMAND ${fill_cmd})
346326
endif()
347327
endforeach()
328+
329+
set(_ALL_CONF_INSTALL_FILES "${_ALL_CONF_INSTALL_FILES}" PARENT_SCOPE)
330+
set(_LDC_POST_BUILD_COMMANDS "${_LDC_POST_BUILD_COMMANDS}" PARENT_SCOPE)
331+
set(_LDC_POST_BUILD_BYPRODUCTS "${_LDC_POST_BUILD_BYPRODUCTS}" PARENT_SCOPE)
332+
endfunction()
333+
334+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
335+
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
336+
makeTripleConfig("" "${LIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
337+
338+
# macOS has fat libraries; otherwise, append a separate config file section for the
339+
# multilib target and override the lib directory.
340+
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
341+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${MULTILIB_SUFFIX}")
342+
set(install_libdir "${CMAKE_INSTALL_PREFIX}/lib${MULTILIB_SUFFIX}")
343+
makeTripleConfig("-m${MULTILIB_SUFFIX}" "${MULTILIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
348344
endif()
349345

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