Skip to content

Commit fae3672

Browse files
committed
ldc-build-runtime: Add --installWithSuffix option
To simplify copying the libraries to an existing LDC installation.
1 parent 18bdc2a commit fae3672

File tree

9 files changed

+47
-36
lines changed

9 files changed

+47
-36
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ runs:
8080
cd ..
8181
arch='${{ inputs.arch }}'
8282
triple="$arch-apple-macos$MACOSX_DEPLOYMENT_TARGET"
83-
echo "DFLAGS=-mtriple=$triple -L-L$PWD/build-cross-libs/lib -Xcc=-target -Xcc=$triple -Xcc=-isysroot -Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" >> $GITHUB_ENV
83+
echo "DFLAGS=-mtriple=$triple -L-L$PWD/install/lib -Xcc=-target -Xcc=$triple -Xcc=-isysroot -Xcc=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" >> $GITHUB_ENV
8484
echo "CROSS_TRIPLE=$triple" >> $GITHUB_ENV
8585
echo "CROSS_CMAKE_FLAGS=-DCMAKE_OSX_ARCHITECTURES=$arch" >> $GITHUB_ENV
8686
@@ -113,9 +113,9 @@ runs:
113113
cmakeFlags+=" -DANDROID_STL=c++_static"
114114
cmakeFlags+=" -DCMAKE_TOOLCHAIN_FILE=$PWD/android-ndk/build/cmake/android.toolchain.cmake"
115115
cmakeFlags+=" -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF"
116-
cmakeFlags+=" -DLDC_LINK_MANUALLY=ON -DD_LINKER_ARGS='-L$PWD/build-cross-libs/lib;-lphobos2-ldc;-ldruntime-ldc'"
116+
cmakeFlags+=" -DLDC_LINK_MANUALLY=ON -DD_LINKER_ARGS='-L$PWD/install/lib;-lphobos2-ldc;-ldruntime-ldc'"
117117
118-
echo "DFLAGS=-mtriple=$triple -L-L$PWD/build-cross-libs/lib -gcc=$PWD/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/$triple-clang" >> $GITHUB_ENV
118+
echo "DFLAGS=-mtriple=$triple -L-L$PWD/install/lib -gcc=$PWD/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/$triple-clang" >> $GITHUB_ENV
119119
echo "CROSS_TRIPLE=$triple" >> $GITHUB_ENV
120120
echo "CROSS_CMAKE_FLAGS=$cmakeFlags" >> $GITHUB_ENV
121121
@@ -125,7 +125,7 @@ runs:
125125
with:
126126
cmake_flags: ${{ env.CROSS_CMAKE_FLAGS }}
127127

128-
- name: Cross-compile default libraries
128+
- name: Cross-compile and install default libraries
129129
shell: bash
130130
run: |
131131
set -euxo pipefail
@@ -136,12 +136,15 @@ runs:
136136
# convert to array, stripping all `-D` prefixes
137137
IFS=$'\n' flags=( $(xargs -n1 <<<"$flags" | cut -b3-) )
138138
139+
# install libs into install/lib/, and ldc2.conf into install/etc/
139140
bootstrap-ldc/bin/ldc-build-runtime --ninja \
140-
--buildDir="build-cross-libs" \
141+
--buildDir="build-cross-runtime" \
141142
--dFlags="${DFLAGS// /;}" \
142143
--ldcSrcDir="$PWD/ldc" \
144+
--installWithSuffix "" \
143145
CMAKE_INSTALL_PREFIX="$PWD/install" \
144146
INCLUDE_INSTALL_DIR="$PWD/install/import" \
147+
CONF_INST_DIR="$PWD/install/etc" \
145148
"${flags[@]}"
146149
147150
- name: Cross-compile LDC executables

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
using: composite
1010
steps:
1111

12-
- name: Install LDC
12+
- name: Install LDC # into ../install/
1313
shell: bash
1414
run: |
1515
set -eux
@@ -18,18 +18,17 @@ runs:
1818
if [[ '${{ inputs.cross_compiling }}' != true ]]; then
1919
ninja -C build install >/dev/null
2020
else
21-
# populate first subdirs by installing the cross-compiled compiler:
21+
# the cross-compiled runtime libs have already been installed:
22+
# * lib/: runtime library artifacts
23+
# * etc/ldc2.conf
24+
25+
# now extend by installing the cross-compiled compiler:
2226
# * bin/: executables
23-
# * lib/: LTO plugin and compiler-rt libs only
27+
# * lib/: LTO plugin and compiler-rt libs
2428
# * etc/bash_completion.d/
25-
# * import/: missing ldc/gccbuiltins_*.di
29+
# * import/: all runtime imports except for ldc/gccbuiltins_*.di
2630
ninja -C build-cross install
2731
28-
# install the cross-compiled libs to populate:
29-
# * lib/: runtime library artifacts
30-
# * etc/ldc2.conf
31-
ninja -C build-cross-libs install
32-
3332
# copy gccbuiltins from bootstrap compiler
3433
cp bootstrap-ldc/import/ldc/gccbuiltins_*.di install/import/ldc/
3534
fi

.github/actions/5a-android-x86/action.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ runs:
2222
2323
# use bootstrap-ldc, which is guaranteed to be native
2424
bootstrap-ldc/bin/ldc-build-runtime --ninja \
25-
--buildDir="build-libs-$arch" \
2625
--dFlags="-mtriple=$triple" \
2726
--ldcSrcDir="$PWD/ldc" \
27+
--installWithSuffix="-$arch" \
28+
CMAKE_INSTALL_PREFIX="$PWD/installed" \
2829
"${flags[@]}" \
2930
ANDROID_ABI="$abi" # override the one in CROSS_CMAKE_FLAGS
30-
31-
mkdir "installed/lib-$arch"
32-
cp "build-libs-$arch"/lib/* "installed/lib-$arch/"

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ runs:
2323
fi
2424
2525
installed/bin/ldc-build-runtime --ninja \
26-
--buildDir=build-libs-ios \
2726
--dFlags="-mtriple=$triple" \
2827
--ldcSrcDir="$PWD/ldc" \
28+
--installWithSuffix="-ios-$arch" \
2929
CMAKE_SYSTEM_NAME=iOS \
3030
CMAKE_OSX_SYSROOT="$sysroot" \
3131
CMAKE_OSX_ARCHITECTURES="$arch" \
3232
CMAKE_OSX_DEPLOYMENT_TARGET="$deployment_target" \
3333
BUILD_LTO_LIBS=ON
3434
35-
mkdir "installed/lib-ios-$arch"
36-
cp -a build-libs-ios/lib/*.{a,dylib,o} "installed/lib-ios-$arch/"
37-
3835
section="
3936
\"$arch-apple-ios\":
4037
{

.github/actions/7-package/action.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ runs:
1919
cd ..
2020
if [[ '${{ inputs.cross_target_triple }}' != '' ]]; then
2121
DMD="$PWD/bootstrap-ldc/bin/ldmd2"
22+
ln -s installed install # the DFLAGS still reference install/lib/
2223
else
2324
DMD="$PWD/installed/bin/ldmd2"
2425
fi

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,10 @@ runs:
8080
call "%VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=arm64 -host_arch=x64 || exit /b
8181
echo on
8282
ldc2-multilib\bin\ldc-build-runtime --ninja ^
83-
--buildDir=build-libs-arm64 ^
8483
--dFlags=-mtriple=aarch64-windows-msvc ^
8584
"--ldcSrcDir=%CD%" ^
85+
--installWithSuffix=arm64 ^
8686
BUILD_LTO_LIBS=ON
87-
- name: Copy arm64 libraries
88-
shell: bash
89-
run: |
90-
set -eux
91-
cp -R build-libs-arm64/lib ldc2-multilib/libarm64
92-
rm ldc2-multilib/libarm64/*.{exp,ilk}
93-
rm ldc2-multilib/libarm64/{druntime,phobos2}-ldc-shared.pdb
9487
- name: Add arm64 section to ldc2.conf
9588
shell: pwsh
9689
run: |

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Big news
44
- ldc2.conf: Arrays can now be appended to via the `~=` operator. (#4848, #4856)
5+
- New `--installWithSuffix` command-line option for the `ldc-build-runtime` tool, to simplify copying the libraries to an existing LDC installation. (#4870)
56

67
#### Platform support
78

runtime/CMakeLists.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ endif()
365365
if(NOT DEFINED CONF_INST_DIR) # set by parent LDC build
366366
set(CONF_INST_DIR "${CMAKE_INSTALL_PREFIX}/etc")
367367
endif()
368-
install(FILES ${install_conf_path} DESTINATION ${CONF_INST_DIR} RENAME ${CONFIG_BASE}.conf)
368+
if(NOT CONF_INST_DIR STREQUAL "") # allow skipping the ldc2.conf installation
369+
install(FILES ${install_conf_path} DESTINATION ${CONF_INST_DIR} RENAME ${CONFIG_BASE}.conf)
370+
endif()
369371

370372
#
371373
# druntime/Phobos compilation helpers.
@@ -858,13 +860,17 @@ foreach(libname ${libs_to_install})
858860
# import .lib in regular lib dir
859861
install(FILES $<TARGET_LINKER_FILE:${libname}>
860862
DESTINATION ${destination_dir})
861-
# .dll in bin dir
863+
# when included from the LDC parent build, install .dll and .pdb into bin/
864+
if(LDC_EXE)
865+
set(destination_dir ${CMAKE_INSTALL_PREFIX}/bin)
866+
endif()
867+
# .dll in bin or lib dir
862868
install(FILES $<TARGET_FILE:${libname}>
863-
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
864-
# .pdb of debug DLLs in bin dir
869+
DESTINATION ${destination_dir})
870+
# .pdb of debug DLLs in bin or lib dir
865871
if(${libname} MATCHES "-debug")
866872
install(FILES $<TARGET_PDB_FILE:${libname}>
867-
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
873+
DESTINATION ${destination_dir})
868874
endif()
869875
else()
870876
install(TARGETS ${libname}

runtime/ldc-build-runtime.d.in

+14-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct Config {
2222
uint numBuildJobs;
2323
bool systemZlib;
2424
string[string] cmakeVars;
25+
string installWithSuffix;
2526
}
2627

2728
version (Windows) enum exeSuffix = ".exe";
@@ -167,6 +168,13 @@ void runCMake() {
167168
if (config.cFlags.length) args ~= "-DRT_CFLAGS=" ~ config.cFlags.join(" ");
168169
if (config.linkerFlags.length) args ~= "-DLD_FLAGS=" ~ config.linkerFlags.join(" ");
169170
if (config.systemZlib) args ~= "-DPHOBOS_SYSTEM_ZLIB=ON";
171+
if (config.installWithSuffix.ptr) {
172+
args ~= [
173+
"-DCMAKE_INSTALL_PREFIX=" ~ config.ldcExecutable.dirName.dirName,
174+
"-DLIB_SUFFIX=" ~ config.installWithSuffix,
175+
"-DCONF_INST_DIR=", // don't install/overwrite existing etc/ldc2.conf!
176+
];
177+
}
170178

171179
foreach (pair; config.cmakeVars.byPair)
172180
args ~= "-D" ~ pair[0] ~ '=' ~ pair[1];
@@ -182,7 +190,8 @@ void runCMake() {
182190
void build() {
183191
const wd = WorkingDirScope(config.buildDir);
184192

185-
string[] args = [ config.ninja ? "ninja" : "make" ];
193+
const buildTool = config.ninja ? "ninja" : "make";
194+
string[] args = [ buildTool ];
186195
if (config.numBuildJobs != 0) {
187196
import std.conv : to;
188197
args ~= "-j" ~ config.numBuildJobs.to!string;
@@ -192,6 +201,9 @@ void build() {
192201
args ~= "all-test-runners";
193202

194203
exec(args);
204+
205+
if (config.installWithSuffix.ptr)
206+
exec([buildTool, "install"]);
195207
}
196208

197209
/**
@@ -333,6 +345,7 @@ void parseCommandLine(string[] args) {
333345
"linkerFlags", "Extra C linker flags for shared libraries and testrunner executables (separated by ';')", &config.linkerFlags,
334346
"j", "Number of parallel build jobs", &config.numBuildJobs,
335347
"systemZlib", "Use system zlib instead of Phobos' vendored version", &config.systemZlib,
348+
"installWithSuffix", "Install the built libraries to '<directory containing LDC executable>/../lib<suffix>/'", &config.installWithSuffix,
336349
);
337350

338351
// getopt() has removed all consumed args from `args`

0 commit comments

Comments
 (0)