Skip to content

Commit b15cbe9

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 ce49fb9 commit b15cbe9

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
#
@@ -274,26 +271,6 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
274271
set(switches "-link-defaultlib-shared=false")
275272
endif()
276273

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

@@ -308,34 +285,15 @@ makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
308285

309286
BUILD
310287
SWITCHES ${switches}
311-
POST_SWITCHES OVERRIDE ${build_post_switches}
312288
LIB_DIRS OVERRIDE ${build_libdir}
313289
RPATH ${build_rpath}
314290

315291
INSTALL
316292
SWITCHES ${switches}
317-
POST_SWITCHES OVERRIDE ${install_post_switches}
318293
LIB_DIRS OVERRIDE ${install_libdir}
319294
RPATH ${install_rpath}
320295
)
321296

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