Skip to content

Commit 16bc6fd

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 dc11ebb commit 16bc6fd

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
@@ -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,59 @@ 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+
list(APPEND switches "-defaultlib=phobos2-ldc,druntime-ldc")
969+
970+
makeConfSection(NAME "35-ldc-compiler" SECTION "default"
971+
BUILD
972+
SWITCHES ${switches}
973+
# -defaultlib is configure in runtime/CMakeLists.txt
974+
POST_SWITCHES
975+
"-I${PROJECT_SOURCE_DIR}/runtime/druntime/src"
976+
"-I${PROJECT_BINARY_DIR}/import"
977+
"-I${PROJECT_SOURCE_DIR}/runtime/phobos"
978+
"-I${PROJECT_SOURCE_DIR}/runtime/jit-rt/d"
979+
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG}
980+
981+
INSTALL
982+
SWITCHES ${switches}
983+
POST_SWITCHES "-I${INCLUDE_INSTALL_DIR}"
984+
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG}
985+
)
986+
987+
set(wasm_switches)
988+
list(APPEND wasm_switches -defaultlib=)
989+
# Default wasm stack is only 64kb, this is rather small, let's bump it to 1mb
990+
list(APPEND wasm_switches -L-z -Lstack-size=1048576)
991+
# Protect from stack overflow overwriting global memory
992+
list(APPEND wasm_switches -L--stack-first)
993+
if(LDC_WITH_LLD)
994+
list(APPEND wasm_switches -link-internally)
995+
endif()
996+
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023).
997+
list(APPEND wasm_switches -L--export-dynamic)
998+
999+
makeConfSection(NAME "40-ldc-wasm"
1000+
SECTION "^wasm(32|64)-"
1001+
SWITCHES ${wasm_switches}
1002+
LIB_DIRS OVERRIDE
1003+
)
1004+
9561005
#
9571006
# Test and runtime targets. Note that enable_testing() is order-sensitive!
9581007
#

runtime/CMakeLists.txt

Lines changed: 0 additions & 42 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
#
@@ -271,26 +268,6 @@ elseif(${BUILD_SHARED_LIBS} STREQUAL "OFF")
271268
list(APPEND switches "-link-defaultlib-shared=false")
272269
endif()
273270

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

@@ -305,34 +282,15 @@ makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
305282

306283
BUILD
307284
SWITCHES ${switches}
308-
POST_SWITCHES OVERRIDE ${build_post_switches}
309285
LIB_DIRS OVERRIDE ${build_libdir}
310286
RPATH ${build_rpath}
311287

312288
INSTALL
313289
SWITCHES ${switches}
314-
POST_SWITCHES OVERRIDE ${install_post_switches}
315290
LIB_DIRS OVERRIDE ${install_libdir}
316291
RPATH ${install_rpath}
317292
)
318293

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