Skip to content

Commit 1c36311

Browse files
authored
Merge pull request #4954 from the-horo/ldc2-conf
Support ldc2.conf as a directory
2 parents a4b1271 + 23df3e9 commit 1c36311

26 files changed

+860
-440
lines changed

.cirrus.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,17 @@ packaging_steps_template: &PACKAGING_STEPS_TEMPLATE
6565
cd build
6666
ninja install > /dev/null
6767
cd ..
68-
perl -pi -e s?$PWD/install/?%%ldcbinarypath%%/../?g install/etc/ldc2.conf
68+
perl -pi -e s?$PWD/install/?%%ldcbinarypath%%/../?g install/etc/ldc2.conf/*
6969
if [[ "$CI_OS" == "freebsd" ]]; then
70-
perl -pi -e "s?,druntime-ldc\",?,druntime-ldc\", \"-gcc=$CC\",?" install/etc/ldc2.conf
70+
cat > install/etc/ldc2.conf/35-ldc-default-CC.conf <<EOF
71+
"default":
72+
{
73+
switches ~= [ "-gcc=${CC}" ];
74+
}
75+
EOF
7176
fi
7277
cp $CIRRUS_WORKING_DIR/{LICENSE,packaging/README} install
73-
cat install/etc/ldc2.conf
78+
cat install/etc/ldc2.conf/*
7479
# Now rename the installation dir to test portability
7580
mv install installed
7681
# Run hello-world integration test with shared libs

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

Lines changed: 4 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,9 @@ 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+
confs=( install/etc/ldc2.conf/* )
54+
perl -pi -e "s|$absInstallDir/|%%ldcbinarypath%%/../|g" "${confs[@]}"
55+
cat "${confs[@]}"
5556
5657
- name: Rename the installation dir to test portability
5758
shell: bash

.github/actions/5a-ios/action.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ runs:
3232
CMAKE_OSX_DEPLOYMENT_TARGET="$deployment_target" \
3333
BUILD_LTO_LIBS=ON
3434
35-
section="
36-
\"$arch-apple-ios\":
35+
section="\"$arch-apple-ios\":
3736
{
3837
switches ~= [
3938
\"-Xcc=-isysroot\",
@@ -44,5 +43,5 @@ runs:
4443
];
4544
rpath = \"%%ldcbinarypath%%/../lib-ios-$arch\";
4645
};"
47-
echo "$section" >> installed/etc/ldc2.conf
48-
cat installed/etc/ldc2.conf
46+
echo "$section" >> installed/etc/ldc2.conf/31-ldc-runtime-lib-ios-$arch.conf
47+
cat installed/etc/ldc2.conf/*

.github/actions/merge-macos/action.yml

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,77 +39,26 @@ runs:
3939
rm lib-{x86_64,arm64}/libLTO.dylib
4040
4141
# ldc2.conf:
42-
# 1) make a backup copy
43-
cp etc/ldc2.conf /tmp/ldc2.conf.bak
44-
# 2) strip to the header comments (remove all existing sections, only keep `default:` line)
45-
sed -i '' '/^default:$/q' etc/ldc2.conf
46-
# 3) append all sections (except for wasm)
47-
cat >>etc/ldc2.conf <<EOF
48-
{
49-
// default switches injected before all explicit command-line switches
50-
switches = [
51-
"-defaultlib=phobos2-ldc,druntime-ldc",
52-
];
53-
// default switches appended after all explicit command-line switches
54-
post-switches = [
55-
"-I%%ldcbinarypath%%/../import",
56-
];
57-
// default directories to be searched for libraries when linking
58-
lib-dirs = [];
59-
// default rpath when linking against the shared default libs
60-
rpath = "";
61-
};
6242
63-
// macOS:
64-
65-
"x86_64-apple-":
43+
# 1) x86_64 ios config
44+
# already present
45+
# 2) arm64 ios config
46+
cp ../ldc2-arm64/etc/ldc2.conf/31-ldc-runtime-lib-ios-arm64.conf etc/ldc2.conf
47+
# 3) x86_64 & arm64 macos
48+
rm etc/ldc2.conf/30-ldc-runtime-lib.conf # the old ldc2-x86_64 config
49+
for arch in x86_64 arm64; do
50+
cat > etc/ldc2.conf/30-ldc-runtime-lib-${arch}.conf <<EOF
51+
"${arch}-apple-":
6652
{
6753
lib-dirs = [
68-
"%%ldcbinarypath%%/../lib-x86_64",
54+
"%%ldcbinarypath%%/../lib-${arch}",
6955
];
70-
rpath = "%%ldcbinarypath%%/../lib-x86_64";
56+
rpath = "%%ldcbinarypath%%/../lib-${arch}";
7157
};
72-
73-
"arm64-apple-":
74-
{
75-
lib-dirs = [
76-
"%%ldcbinarypath%%/../lib-arm64",
77-
];
78-
rpath = "%%ldcbinarypath%%/../lib-arm64";
79-
};
80-
81-
// iOS:
82-
83-
"x86_64-apple-ios":
84-
{
85-
switches ~= [
86-
"-Xcc=-isysroot",
87-
"-Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk",
88-
];
89-
lib-dirs = [
90-
"%%ldcbinarypath%%/../lib-ios-x86_64",
91-
];
92-
rpath = "%%ldcbinarypath%%/../lib-ios-x86_64";
93-
};
94-
95-
"arm64-apple-ios":
96-
{
97-
switches ~= [
98-
"-Xcc=-isysroot",
99-
"-Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk",
100-
];
101-
lib-dirs = [
102-
"%%ldcbinarypath%%/../lib-ios-arm64",
103-
];
104-
rpath = "%%ldcbinarypath%%/../lib-ios-arm64";
105-
};
106-
107-
// WebAssembly
10858
EOF
109-
# 4) append the wasm section from the backup
110-
sed -n '/^"\^wasm/,$p' /tmp/ldc2.conf.bak | sed '/^\};$/q' >> etc/ldc2.conf
59+
done
11160
112-
cat etc/ldc2.conf
61+
cat etc/ldc2.conf/*
11362
11463
- name: Run x86_64/arm64 macOS/iOS cross-compilation smoke tests
11564
shell: bash

.github/actions/merge-windows/action.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ runs:
2020
mv ldc2-*-x64 ldc2-multilib
2121
cd ldc2-multilib
2222
mv lib lib64
23+
mv etc/ldc2.conf/30-ldc-runtime-{lib,lib64}.conf
2324
cp -R ../ldc2-x86/lib lib32
2425
cp ../ldc2-x86/bin/{*.dll,*.pdb,curl-ca-bundle.crt} lib32/
2526
- name: Merge ldc2.conf
2627
shell: pwsh
2728
run: |
2829
cd ldc2-multilib
29-
(cat etc\ldc2.conf).replace('%%ldcbinarypath%%/../lib', '%%ldcbinarypath%%/../lib64') | Set-Content etc\ldc2.conf
30-
$conf32 = '
31-
"i[3-6]86-.*-windows-msvc":
30+
(cat etc\ldc2.conf\30-ldc-runtime-lib64.conf).replace('%%ldcbinarypath%%/../lib', '%%ldcbinarypath%%/../lib64') | Set-Content etc\ldc2.conf\30-ldc-runtime-lib64.conf
31+
$conf32 = '"i[3-6]86-.*-windows-msvc":
3232
{
3333
lib-dirs = [
3434
"%%ldcbinarypath%%/../lib32",
3535
];
3636
};
3737
'
38-
Add-Content etc\ldc2.conf $conf32 -NoNewline
39-
cat etc\ldc2.conf
38+
Set-Content etc\ldc2.conf\31-ldc-runtime-lib32.conf $conf32
39+
cat etc\ldc2.conf\*
4040
4141
- name: Generate hello.d
4242
shell: bash
@@ -86,16 +86,15 @@ runs:
8686
shell: pwsh
8787
run: |
8888
cd ldc2-multilib
89-
$conf = '
90-
"(aarch|arm)64-.*-windows-msvc":
89+
$conf = '"(aarch|arm)64-.*-windows-msvc":
9190
{
9291
lib-dirs = [
9392
"%%ldcbinarypath%%/../libarm64",
9493
];
9594
};
9695
'
97-
Add-Content etc\ldc2.conf $conf -NoNewline
98-
cat etc\ldc2.conf
96+
Set-Content etc\ldc2.conf\31-ldc-runtime-libarm64.conf $conf
97+
cat etc\ldc2.conf\*
9998
- name: Run arm64 hello-world cross-compilation smoke tests
10099
shell: cmd
101100
run: |

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#### Big news
44
- Frontend, druntime and Phobos are at version ~[2.112.0](https://dlang.org/changelog/2.112.0.html), incl. new command-line options `-extI`, `-dllimport=externalOnly` and `-edition`. (#4949, #4962)
5-
- **Breaking change for dcompute**: The special `@kernel` UDA is now a function and _**requires**_ parentheses as in `@kernel() void foo(){}`. Optionally you can provide launch dimensions, `@kernel([2,4,8])`, to specify to the compute runtime how the kernel is intended to be launched.
5+
- **Breaking change for dcompute**: The special `@kernel` UDA is now a function and _**requires**_ parentheses as in `@kernel() void foo(){}`. Optionally you can provide launch dimensions, `@kernel([2,4,8])`, to specify to the compute runtime how the kernel is intended to be launched.
6+
- ldc2.conf can now be a directory. All the files inside it, ordered naturally, will be concatenated and treated like a big config. (#4954)
7+
- **Breaking change for ldc2.conf cmake generation**: The `cmake` build process now generates the `ldc2.conf` and `ldc2_install.conf` as directories. `ldc2*.conf.in` and `ADDITIONAL_DEFAULT_LDC_SWITCHES` have been removed, if you need to add switches check out `makeConfSection` in `LdcConfig.cmake`. (#4954)
68

79
#### Platform support
810

CMakeLists.txt

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,14 @@ project(ldc)
1717

1818
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
1919

20+
include(LdcCommon)
21+
2022
include(FindDCompiler)
2123
include(CheckCXXCompilerFlag)
2224
include(CheckDSourceCompiles)
2325
include(CheckLinkFlag)
2426
include(BuildDExecutable)
2527

26-
# Helper function
27-
function(append value)
28-
foreach(variable ${ARGN})
29-
if(${variable} STREQUAL "")
30-
set(${variable} "${value}" PARENT_SCOPE)
31-
else()
32-
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
33-
endif()
34-
endforeach(variable)
35-
endfunction()
36-
3728
#
3829
# Locate LLVM.
3930
#
@@ -128,20 +119,9 @@ set(DMDFE_PATCH_VERSION 0)
128119

129120
set(DMD_VERSION ${DMDFE_MAJOR_VERSION}.${DMDFE_MINOR_VERSION}.${DMDFE_PATCH_VERSION})
130121

131-
# Generally, we want to install everything into CMAKE_INSTALL_PREFIX, but when
132-
# it is /usr, put the config files into /etc to meet common practice.
133-
if(NOT DEFINED SYSCONF_INSTALL_DIR)
134-
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr")
135-
set(SYSCONF_INSTALL_DIR "/etc")
136-
else()
137-
set(SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc")
138-
endif()
139-
endif()
140-
141122
set(D_VERSION ${DMDFE_MAJOR_VERSION} CACHE STRING "D language version")
142123
set(PROGRAM_PREFIX "" CACHE STRING "Prepended to ldc/ldmd binary names")
143124
set(PROGRAM_SUFFIX "" CACHE STRING "Appended to ldc/ldmd binary names")
144-
set(CONF_INST_DIR ${SYSCONF_INSTALL_DIR} CACHE PATH "Directory ldc2.conf is installed to")
145125
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
146126

147127
# Note: LIB_SUFFIX should perhaps be renamed to LDC_LIBDIR_SUFFIX.
@@ -923,10 +903,6 @@ if(NOT DEFINED COMPILER_RT_LIBDIR_CONFIG)
923903
set(COMPILER_RT_LIBDIR_CONFIG "${COMPILER_RT_LIBDIR}")
924904
endif()
925905
endif()
926-
if(DEFINED COMPILER_RT_LIBDIR_CONFIG)
927-
message(STATUS "Adding ${COMPILER_RT_LIBDIR_CONFIG} to lib-dirs in configuration file")
928-
set(OPTIONAL_COMPILER_RT_DIR "\n \"${COMPILER_RT_LIBDIR_CONFIG}\", // compiler-rt directory")
929-
endif()
930906

931907
#
932908
# Auxiliary build and test utils.
@@ -974,6 +950,59 @@ endif()
974950
#
975951
add_subdirectory(tools)
976952

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+
9771006
#
9781007
# Test and runtime targets. Note that enable_testing() is order-sensitive!
9791008
#
@@ -1006,6 +1035,15 @@ option(LDC_BUILD_RUNTIME "Build the runtime libraries" ${_LDC_BUILD_RUNTIME_DEFA
10061035

10071036
if(LDC_BUILD_RUNTIME)
10081037
add_subdirectory(runtime)
1038+
1039+
# POST_BUILD can't be used for targets in a different directory so
1040+
# runtime/CMakeLists.txt can't directly add the commands.
1041+
if(_LDC_POST_BUILD_COMMANDS)
1042+
add_custom_command(TARGET ${LDC_EXE} POST_BUILD
1043+
${_LDC_POST_BUILD_COMMANDS}
1044+
BYPRODUCTS ${_LDC_POST_BUILD_BYPRODUCTS}
1045+
)
1046+
endif()
10091047
else()
10101048
message(STATUS "NOT building the runtime libraries (LDC_BUILD_RUNTIME=OFF)")
10111049
endif()
@@ -1045,6 +1083,11 @@ if(${BUILD_SHARED})
10451083
install(TARGETS ${LDC_LIB} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
10461084
endif()
10471085

1086+
# Add some documentation to the installed config files
1087+
if(NOT DONT_INSTALL_CONF)
1088+
install(FILES "ldc2.conf.header" DESTINATION "${CONF_INST_DIR}/ldc2.conf" RENAME 00-docs.conf)
1089+
endif()
1090+
10481091
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
10491092
if(NOT DEFINED BASH_COMPLETION_COMPLETIONSDIR)
10501093
find_package(bash-completion QUIET)

cmake/Modules/LdcCommon.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Common functionality shared by the compiler and the runtime build system.
2+
3+
function(append value)
4+
foreach(variable ${ARGN})
5+
if(${variable} STREQUAL "")
6+
set(${variable} "${value}" PARENT_SCOPE)
7+
else()
8+
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
9+
endif()
10+
endforeach(variable)
11+
endfunction()
12+
13+
include(LdcConfig)

0 commit comments

Comments
 (0)