Skip to content

Commit 3d82ec7

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 3d82ec7

File tree

5 files changed

+64
-51
lines changed

5 files changed

+64
-51
lines changed

.github/actions/3-build-cross/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ runs:
142142
--dFlags="${DFLAGS// /;}" \
143143
--ldcSrcDir="$PWD/ldc" \
144144
--installWithSuffix "" \
145+
--confPreferDir \
145146
CMAKE_INSTALL_PREFIX="$PWD/install" \
146147
INCLUDE_INSTALL_DIR="$PWD/install/import" \
147-
CONF_INST_DIR="$PWD/install/etc" \
148148
"${flags[@]}"
149149
150150
- name: Cross-compile LDC executables
@@ -156,6 +156,7 @@ runs:
156156
specify_install_dir: true
157157
cmake_flags: >-
158158
-DCMAKE_CROSSCOMPILING=True
159+
-DCONF_PREFER_DIR=ON
159160
${{ inputs.os == 'osx' && '-DALTERNATIVE_MALLOC_O="$PWD/../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o"' || '' }}
160161
${{ inputs.cmake_flags }}
161162
${{ inputs.with_pgo == 'true' && '-DDFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata' || '' }}

.github/actions/5-install/action.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ runs:
2020
else
2121
# the cross-compiled runtime libs have already been installed:
2222
# * lib/: runtime library artifacts
23-
# * etc/ldc2.conf
23+
# * etc/ldc2.conf/30-ldc-runtime-lib.conf
2424
2525
# now extend by installing the cross-compiled compiler:
2626
# * bin/: executables
@@ -50,8 +50,14 @@ runs:
5050
# /d/a/1/install => D:/a/1/install
5151
absInstallDir=$(cygpath --mixed "$absInstallDir")
5252
fi
53-
perl -pi -e "s|$absInstallDir/|%%ldcbinarypath%%/../|g" install/etc/ldc2.conf
54-
cat install/etc/ldc2.conf
53+
# ldc2.conf is either a regular file (native builds) or a directory (cross builds)
54+
if [[ -f install/etc/ldc2.conf ]]; then
55+
confs=( install/etc/ldc2.conf )
56+
else
57+
confs=( install/etc/ldc2.conf/* )
58+
fi
59+
perl -pi -e "s|$absInstallDir/|%%ldcbinarypath%%/../|g" "${confs[@]}"
60+
cat "${confs[@]}"
5561
5662
- name: Rename the installation dir to test portability
5763
shell: bash

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)