Skip to content

Commit 30d32eb

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 d2ad4a3 commit 30d32eb

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

runtime/CMakeLists.txt

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -277,51 +277,29 @@ endif()
277277
set(build_switches "-defaultlib=${build_defaultlib}" ${switches})
278278
set(install_switches ${switches})
279279

280-
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
281-
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
282-
283-
# Default -rpath linker option when linking against shared libraries.
284-
if(SHARED_LIBS_SUPPORTED)
285-
set(build_rpath "${build_libdir}")
286-
set(install_rpath "${install_libdir}")
287-
endif()
288-
289-
makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
290-
SECTION "default"
291-
292-
BUILD
293-
SWITCHES ${build_switches}
294-
LIB_DIRS OVERRIDE ${build_libdir}
295-
RPATH ${build_rpath}
296-
297-
INSTALL
298-
SWITCHES ${install_switches}
299-
LIB_DIRS OVERRIDE ${install_libdir}
300-
RPATH ${install_rpath}
301-
)
280+
# comp_args are arguments passed to ldc2 to change the triple
281+
function(makeTripleConfig comp_args suffix build_libdir install_libdir)
282+
set(name "30-ldc-runtime-lib${suffix}")
283+
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
302284

303-
# macOS has fat libraries; otherwise, append a separate config file section for the
304-
# multilib target and override the lib directory.
305-
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
306-
set(build_libdir "${CMAKE_BINARY_DIR}/lib${MULTILIB_SUFFIX}")
307-
set(install_libdir "${CMAKE_INSTALL_PREFIX}/lib${MULTILIB_SUFFIX}")
285+
# Default -rpath linker option when linking against shared libraries.
308286
if(SHARED_LIBS_SUPPORTED)
309287
set(build_rpath "${build_libdir}")
310288
set(install_rpath "${install_libdir}")
311289
endif()
312290

313-
set(name "31-ldc-runtime-lib${MULTILIB_SUFFIX}")
314-
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
315291
makeConfSection(NAME "${name}"
316292
SECTION "${sectionPlaceholder}"
317293

318294
BUILD
295+
SWITCHES ${build_switches}
319296
LIB_DIRS OVERRIDE ${build_libdir}
320297
RPATH ${build_rpath}
321298

322299
INSTALL
323-
LIB_DIRS OVERRIDE ${install_libdir}
324-
RPATH ${install_rpath}
300+
SWITCHES ${install_switches}
301+
LIB_DIRS ${install_libdir}
302+
RPATH ${install_rpath}
325303
)
326304

327305
set(build_conf "${LDC2_BUILD_CONF}/${name}.conf")
@@ -336,13 +314,13 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
336314
"${conf}"
337315
"${sectionPlaceholder}"
338316
# Next arguments are a compiler invocation for the desired triple
339-
"${LDC_EXE_FULL}" -m${MULTILIB_SUFFIX}
317+
"${LDC_EXE_FULL}" ${D_FLAGS} ${comp_args}
340318
)
341319
if(LDC_EXE)
342-
# We need to get the -m32 target triple but the compiler
343-
# is not built yet. We can't depend on LDC_EXE since that
344-
# would cause a cycle so pass-through the needed commands
345-
# up to the root project and let it run them as POST_BUILD
320+
# We need to get the target triple but the compiler is not
321+
# built yet. We can't depend on LDC_EXE since that would
322+
# cause a cycle so pass-through the needed commands up to
323+
# the root project and let it run them as POST_BUILD
346324
# commands. This avoids adding the config_files as
347325
# transitive dependencies to all compiled D files.
348326
#
@@ -356,6 +334,22 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
356334
execute_process(COMMAND ${fill_cmd})
357335
endif()
358336
endforeach()
337+
338+
set(_ALL_CONF_INSTALL_FILES "${_ALL_CONF_INSTALL_FILES}" PARENT_SCOPE)
339+
set(_LDC_POST_BUILD_COMMANDS "${_LDC_POST_BUILD_COMMANDS}" PARENT_SCOPE)
340+
set(_LDC_POST_BUILD_BYPRODUCTS "${_LDC_POST_BUILD_BYPRODUCTS}" PARENT_SCOPE)
341+
endfunction()
342+
343+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
344+
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
345+
makeTripleConfig("" "${LIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
346+
347+
# macOS has fat libraries; otherwise, append a separate config file section for the
348+
# multilib target and override the lib directory.
349+
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
350+
set(build_libdir "${CMAKE_BINARY_DIR}/lib${MULTILIB_SUFFIX}")
351+
set(install_libdir "${CMAKE_INSTALL_PREFIX}/lib${MULTILIB_SUFFIX}")
352+
makeTripleConfig("-m${MULTILIB_SUFFIX}" "${MULTILIB_SUFFIX}" "${build_libdir}" "${install_libdir}")
359353
endif()
360354

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