Skip to content

Commit 0f47829

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 79d3f1a commit 0f47829

File tree

4 files changed

+54
-50
lines changed

4 files changed

+54
-50
lines changed

CMakeLists.txt

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ set(DMD_VERSION ${DMDFE_MAJOR_VERSION}.${DMDFE_MINOR_VERSION}.${DMDFE_PATCH_VERS
122122
set(D_VERSION ${DMDFE_MAJOR_VERSION} CACHE STRING "D language version")
123123
set(PROGRAM_PREFIX "" CACHE STRING "Prepended to ldc/ldmd binary names")
124124
set(PROGRAM_SUFFIX "" CACHE STRING "Appended to ldc/ldmd binary names")
125+
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
125126

126127
# Note: LIB_SUFFIX should perhaps be renamed to LDC_LIBDIR_SUFFIX.
127128
set(LIB_SUFFIX "" CACHE STRING "Appended to the library installation directory. Set to '64' to install libraries into ${PREFIX}/lib64.")
@@ -902,10 +903,6 @@ if(NOT DEFINED COMPILER_RT_LIBDIR_CONFIG)
902903
set(COMPILER_RT_LIBDIR_CONFIG "${COMPILER_RT_LIBDIR}")
903904
endif()
904905
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()
909906

910907
#
911908
# Auxiliary build and test utils.
@@ -953,6 +950,59 @@ endif()
953950
#
954951
add_subdirectory(tools)
955952

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+
9561006
#
9571007
# Test and runtime targets. Note that enable_testing() is order-sensitive!
9581008
#

cmake/Modules/LdcConfig.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,5 @@ else()
229229
set(DONT_INSTALL_CONF FALSE)
230230
endif()
231231

232-
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
233-
234232
defineIfUnset(LDC_BUILD_CONF "${CMAKE_BINARY_DIR}/etc/ldc2.conf")
235233
defineIfUnset(LDC_INSTALL_CONF "${CMAKE_BINARY_DIR}/etc/ldc2_install.conf")

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

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

@@ -307,34 +284,15 @@ makeConfSection(NAME "30-ldc-runtime-lib${LIB_SUFFIX}"
307284

308285
BUILD
309286
SWITCHES ${switches}
310-
POST_SWITCHES OVERRIDE ${build_post_switches}
311287
LIB_DIRS OVERRIDE ${build_libdir}
312288
RPATH ${build_rpath}
313289

314290
INSTALL
315291
SWITCHES ${switches}
316-
POST_SWITCHES OVERRIDE ${install_post_switches}
317292
LIB_DIRS OVERRIDE ${install_libdir}
318293
RPATH ${install_rpath}
319294
)
320295

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

runtime/ldc-build-runtime.d.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ void runCMake() {
159159
"-DLDMD_EXE_FULL=" ~ ldmdExecutable,
160160
"-DDMDFE_MINOR_VERSION=@DMDFE_MINOR_VERSION@",
161161
"-DDMDFE_PATCH_VERSION=@DMDFE_PATCH_VERSION@",
162-
"-DLDC_WITH_LLD=@LDC_WITH_LLD@",
163-
"-DINCLUDE_INSTALL_DIR=@INCLUDE_INSTALL_DIR@",
164162
];
165163

166164
if (config.targetSystem.length) args ~= "-DTARGET_SYSTEM=" ~ config.targetSystem.join(";");

0 commit comments

Comments
 (0)