Skip to content

Commit d2ad4a3

Browse files
committed
Configure ldc2.conf compiler-specific settings in root CMakeLists.txt
Some settings like the default wasm switches or the compiler-rt lib-dir don't have anything to do with the runtime and, on top of that, some are conditioned by build settings that only affect the compiler. Moving them out of the runtime directory improves the support for cross-compiling because, in the scenario, some variables may be unset in the runtime directory as there is no longer a higher-level project to set them. Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
1 parent 730d9b7 commit d2ad4a3

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

CMakeLists.txt

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,6 @@ if(NOT DEFINED COMPILER_RT_LIBDIR_CONFIG)
902902
set(COMPILER_RT_LIBDIR_CONFIG "${COMPILER_RT_LIBDIR}")
903903
endif()
904904
endif()
905-
if(DEFINED COMPILER_RT_LIBDIR_CONFIG)
906-
message(STATUS "Adding ${COMPILER_RT_LIBDIR_CONFIG} to lib-dirs in configuration file")
907-
makeConfSection(NAME "35-ldc-compiler-rt" SECTION "default" LIB_DIRS "${COMPILER_RT_LIBDIR}")
908-
endif()
909905

910906
#
911907
# Auxiliary build and test utils.
@@ -953,6 +949,57 @@ endif()
953949
#
954950
add_subdirectory(tools)
955951

952+
#
953+
# Compiler ldc2.conf configuration
954+
#
955+
956+
set(switches)
957+
958+
# LLVM 16: Disable function specializations by default.
959+
# They cause miscompiles of e.g. the frontend for some targets (macOS x86_64 and Windows x64).
960+
if(LDC_LLVM_VER GREATER 1599 AND LDC_LLVM_VER LESS 1700)
961+
list(APPEND switches "-func-specialization-size-threshold=1000000000")
962+
endif()
963+
964+
if(DEFINED COMPILER_RT_LIBDIR_CONFIG)
965+
message(STATUS "Adding ${COMPILER_RT_LIBDIR_CONFIG} to lib-dirs in configuration file")
966+
endif()
967+
968+
makeConfSection(NAME "35-ldc-compiler" SECTION "default"
969+
BUILD
970+
SWITCHES ${switches}
971+
# -defaultlib is configure in runtime/CMakeLists.txt
972+
POST_SWITCHES
973+
"-I${PROJECT_SOURCE_DIR}/runtime/druntime/src"
974+
"-I${PROJECT_BINARY_DIR}/import"
975+
"-I${PROJECT_SOURCE_DIR}/runtime/phobos"
976+
"-I${PROJECT_SOURCE_DIR}/runtime/jit-rt/d"
977+
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG}
978+
979+
INSTALL
980+
SWITCHES ${switches} -defaultlib=phobos2-ldc,druntime-ldc
981+
POST_SWITCHES "-I${INCLUDE_INSTALL_DIR}"
982+
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG}
983+
)
984+
985+
set(wasm_switches)
986+
list(APPEND wasm_switches -defaultlib=)
987+
# Default wasm stack is only 64kb, this is rather small, let's bump it to 1mb
988+
list(APPEND wasm_switches -L-z -Lstack-size=1048576)
989+
# Protect from stack overflow overwriting global memory
990+
list(APPEND wasm_switches -L--stack-first)
991+
if(LDC_WITH_LLD)
992+
list(APPEND wasm_switches -link-internally)
993+
endif()
994+
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023).
995+
list(APPEND wasm_switches -L--export-dynamic)
996+
997+
makeConfSection(NAME "40-ldc-wasm"
998+
SECTION "^wasm(32|64)-"
999+
SWITCHES ${wasm_switches}
1000+
LIB_DIRS OVERRIDE
1001+
)
1002+
9561003
#
9571004
# Test and runtime targets. Note that enable_testing() is order-sensitive!
9581005
#

runtime/CMakeLists.txt

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ if(NOT LDC_EXE)
1616
if(NOT DEFINED DMDFE_MINOR_VERSION OR NOT DEFINED DMDFE_PATCH_VERSION)
1717
message(FATAL_ERROR "Please define the CMake variables DMDFE_MINOR_VERSION and DMDFE_PATCH_VERSION.")
1818
endif()
19-
if(NOT DEFINED LDC_WITH_LLD)
20-
message(FATAL_ERROR "Please define the CMake variable LDC_WITH_LLD.")
21-
endif()
2219
endif()
2320

2421
#
@@ -263,13 +260,6 @@ endif()
263260
# Create configuration files.
264261
#
265262

266-
if(PHOBOS2_DIR)
267-
set(build_defaultlib "phobos2-ldc,druntime-ldc")
268-
else()
269-
set(build_defaultlib "druntime-ldc")
270-
endif()
271-
set(install_defaultlib "phobos2-ldc,druntime-ldc")
272-
273263
# Only have either shared or static libs?
274264
# Then explicitly default to linking against them via default LDC switch.
275265
if(${BUILD_SHARED_LIBS} STREQUAL "ON")
@@ -278,26 +268,14 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
278268
list(APPEND switches "-link-defaultlib-shared=false")
279269
endif()
280270

281-
# LLVM 16: Disable function specializations by default.
282-
# They cause miscompiles of e.g. the frontend for some targets (macOS x86_64 and Windows x64).
283-
if(LDC_LLVM_VER GREATER 1599 AND LDC_LLVM_VER LESS 1700)
284-
list(APPEND switches "-func-specialization-size-threshold=1000000000")
271+
if(PHOBOS2_DIR)
272+
set(build_defaultlib "phobos2-ldc,druntime-ldc")
273+
else()
274+
set(build_defaultlib "druntime-ldc")
285275
endif()
286276

287277
set(build_switches "-defaultlib=${build_defaultlib}" ${switches})
288-
set(install_switches "-defaultlib=${install_defaultlib}" ${switches})
289-
290-
# Directory filled with auto-generated import files
291-
set(LDC_GCCBUILTINS_IMPORT_DIR "${CMAKE_BINARY_DIR}/import")
292-
list(APPEND build_post_switches
293-
"-I${RUNTIME_DIR}/src"
294-
"-I${LDC_GCCBUILTINS_IMPORT_DIR}"
295-
"-I${JITRT_DIR}/d"
296-
)
297-
if(PHOBOS2_DIR)
298-
list(APPEND build_post_switches "-I${PHOBOS2_DIR}")
299-
endif()
300-
set(install_post_switches "-I${INCLUDE_INSTALL_DIR}")
278+
set(install_switches ${switches})
301279

302280
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
303281
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
@@ -313,34 +291,15 @@ makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
313291

314292
BUILD
315293
SWITCHES ${build_switches}
316-
POST_SWITCHES OVERRIDE ${build_post_switches}
317294
LIB_DIRS OVERRIDE ${build_libdir}
318295
RPATH ${build_rpath}
319296

320297
INSTALL
321298
SWITCHES ${install_switches}
322-
POST_SWITCHES OVERRIDE ${install_post_switches}
323299
LIB_DIRS OVERRIDE ${install_libdir}
324300
RPATH ${install_rpath}
325301
)
326302

327-
list(APPEND wasm_switches -defaultlib=)
328-
# Default wasm stack is only 64kb, this is rather small, let's bump it to 1mb
329-
list(APPEND wasm_switches -L-z -Lstack-size=1048576)
330-
# Protect from stack overflow overwriting global memory
331-
list(APPEND wasm_switches -L--stack-first)
332-
if(LDC_WITH_LLD)
333-
list(APPEND wasm_switches -link-internally)
334-
endif()
335-
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023).
336-
list(APPEND wasm_switches -L--export-dynamic)
337-
338-
makeConfSection(NAME "40-ldc-wasm"
339-
SECTION "^wasm(32|64)-"
340-
SWITCHES ${wasm_switches}
341-
LIB_DIRS OVERRIDE
342-
)
343-
344303
# macOS has fat libraries; otherwise, append a separate config file section for the
345304
# multilib target and override the lib directory.
346305
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
@@ -355,9 +314,11 @@ if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")
355314
set(sectionPlaceholder "LDC_CONF_MULTILIB_TRIPLE_REGEX")
356315
makeConfSection(NAME "${name}"
357316
SECTION "${sectionPlaceholder}"
317+
358318
BUILD
359319
LIB_DIRS OVERRIDE ${build_libdir}
360-
RPATH ${build_rpath}
320+
RPATH ${build_rpath}
321+
361322
INSTALL
362323
LIB_DIRS OVERRIDE ${install_libdir}
363324
RPATH ${install_rpath}

runtime/ldc-build-runtime.d.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ void runCMake() {
163163
"-DLDMD_EXE_FULL=" ~ ldmdExecutable,
164164
"-DDMDFE_MINOR_VERSION=@DMDFE_MINOR_VERSION@",
165165
"-DDMDFE_PATCH_VERSION=@DMDFE_PATCH_VERSION@",
166-
"-DLDC_WITH_LLD=@LDC_WITH_LLD@",
167166
"-DINCLUDE_INSTALL_DIR=@INCLUDE_INSTALL_DIR@",
168167
];
169168

0 commit comments

Comments
 (0)