Skip to content

Commit 8d2f6b9

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 aa760b9 commit 8d2f6b9

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

CMakeLists.txt

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

911907
#
912908
# Auxiliary build and test utils.
@@ -954,6 +950,59 @@ endif()
954950
#
955951
add_subdirectory(tools)
956952

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

runtime/CMakeLists.txt

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ if(NOT LDC_EXE)
1717
if(NOT DEFINED DMDFE_MINOR_VERSION OR NOT DEFINED DMDFE_PATCH_VERSION)
1818
message(FATAL_ERROR "Please define the CMake variables DMDFE_MINOR_VERSION and DMDFE_PATCH_VERSION.")
1919
endif()
20-
if(NOT DEFINED LDC_WITH_LLD)
21-
message(FATAL_ERROR "Please define the CMake variable LDC_WITH_LLD.")
22-
endif()
2320
endif()
2421

2522
#
@@ -272,26 +269,6 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
272269
list(APPEND switches "-link-defaultlib-shared=false")
273270
endif()
274271

275-
# LLVM 16: Disable function specializations by default.
276-
# They cause miscompiles of e.g. the frontend for some targets (macOS x86_64 and Windows x64).
277-
if(LDC_LLVM_VER GREATER 1599 AND LDC_LLVM_VER LESS 1700)
278-
list(APPEND switches "-func-specialization-size-threshold=1000000000")
279-
endif()
280-
281-
list(APPEND switches "-defaultlib=phobos2-ldc,druntime-ldc")
282-
283-
# Directory filled with auto-generated import files
284-
set(LDC_GCCBUILTINS_IMPORT_DIR "${CMAKE_BINARY_DIR}/import")
285-
list(APPEND build_post_switches
286-
"-I${RUNTIME_DIR}/src"
287-
"-I${LDC_GCCBUILTINS_IMPORT_DIR}"
288-
"-I${JITRT_DIR}/d"
289-
)
290-
if(PHOBOS2_DIR)
291-
list(APPEND build_post_switches "-I${PHOBOS2_DIR}")
292-
endif()
293-
set(install_post_switches "-I${INCLUDE_INSTALL_DIR}")
294-
295272
set(build_libdir "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
296273
set(install_libdir "${CMAKE_INSTALL_LIBDIR}")
297274

@@ -306,34 +283,15 @@ makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
306283

307284
BUILD
308285
SWITCHES ${switches}
309-
POST_SWITCHES OVERRIDE ${build_post_switches}
310286
LIB_DIRS OVERRIDE ${build_libdir}
311287
RPATH ${build_rpath}
312288

313289
INSTALL
314290
SWITCHES ${switches}
315-
POST_SWITCHES OVERRIDE ${install_post_switches}
316291
LIB_DIRS OVERRIDE ${install_libdir}
317292
RPATH ${install_rpath}
318293
)
319294

320-
list(APPEND wasm_switches -defaultlib=)
321-
# Default wasm stack is only 64kb, this is rather small, let's bump it to 1mb
322-
list(APPEND wasm_switches -L-z -Lstack-size=1048576)
323-
# Protect from stack overflow overwriting global memory
324-
list(APPEND wasm_switches -L--stack-first)
325-
if(LDC_WITH_LLD)
326-
list(APPEND wasm_switches -link-internally)
327-
endif()
328-
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023).
329-
list(APPEND wasm_switches -L--export-dynamic)
330-
331-
makeConfSection(NAME "40-ldc-wasm"
332-
SECTION "^wasm(32|64)-"
333-
SWITCHES ${wasm_switches}
334-
LIB_DIRS OVERRIDE
335-
)
336-
337295
# macOS has fat libraries; otherwise, append a separate config file section for the
338296
# multilib target and override the lib directory.
339297
if(MULTILIB AND NOT "${TARGET_SYSTEM}" MATCHES "APPLE")

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)