Skip to content

Commit 7b00ad9

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 <[email protected]>
1 parent 25301bb commit 7b00ad9

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
#
@@ -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 & 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)