Skip to content

Commit d49d748

Browse files
authored
Bundle arm64-ios-simulator libraries with arm64/universal macOS packages (#4974)
1 parent 789efab commit d49d748

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

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

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,41 @@ runs:
1515
1616
arch='${{ inputs.arch }}'
1717
deployment_target='${{ inputs.ios_deployment_target }}'
18-
triple="$arch-apple-ios$deployment_target${{ inputs.arch == 'x86_64' && '-simulator' || '' }}"
18+
19+
function add_runtime {
20+
local is_simulator="$1"
21+
22+
local triple="$arch-apple-ios$deployment_target"
23+
local sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'
24+
local install_suffix="-ios-$arch"
25+
local triple_regex="$arch-apple-ios[^-]*\$"
26+
if [[ "$is_simulator" == 1 ]]; then
27+
triple+='-simulator'
28+
sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'
29+
install_suffix="-ios-simulator-$arch"
30+
triple_regex="$arch-apple-ios.*-simulator"
31+
fi
32+
33+
install/bin/ldc-build-runtime --ninja \
34+
--dFlags="-mtriple=$triple" \
35+
--ldcSrcDir="$PWD/ldc" \
36+
--installWithSuffix="$install_suffix" \
37+
RT_CONF_TRIPLE_REGEX="$triple_regex" \
38+
CMAKE_SYSTEM_NAME=iOS \
39+
CMAKE_OSX_SYSROOT="$sysroot" \
40+
CMAKE_OSX_ARCHITECTURES="$arch" \
41+
CMAKE_OSX_DEPLOYMENT_TARGET="$deployment_target" \
42+
BUILD_LTO_LIBS=ON
43+
44+
# append cross-compile flags to generated .conf file
45+
sed -i "" "s|^{\$|{\n switches ~= [\n \"-Xcc=-isysroot\",\n \"-Xcc=${sysroot}\",\n ];|" install/etc/ldc2.conf/55-target${install_suffix}.conf
46+
}
47+
1948
if [[ "$arch" == arm64 ]]; then
20-
sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk'
49+
add_runtime 0 # ios-arm64
50+
add_runtime 1 # ios-simulator-arm64
2151
else
22-
sysroot='/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'
52+
add_runtime 1 # ios-simulator-x86_64
2353
fi
2454
25-
install/bin/ldc-build-runtime --ninja \
26-
--dFlags="-mtriple=$triple" \
27-
--ldcSrcDir="$PWD/ldc" \
28-
--installWithSuffix="-ios-$arch" \
29-
RT_CONF_TRIPLE_REGEX="$arch-apple-ios" \
30-
CMAKE_SYSTEM_NAME=iOS \
31-
CMAKE_OSX_SYSROOT="$sysroot" \
32-
CMAKE_OSX_ARCHITECTURES="$arch" \
33-
CMAKE_OSX_DEPLOYMENT_TARGET="$deployment_target" \
34-
BUILD_LTO_LIBS=ON
35-
36-
# append cross-compile flags to generated .conf file
37-
sed -i "" "s|^{\$|{\n switches ~= [\n \"-Xcc=-isysroot\",\n \"-Xcc=${sysroot}\",\n ];|" install/etc/ldc2.conf/55-target-ios-$arch.conf
38-
cat install/etc/ldc2.conf/*
55+
cat install/etc/ldc2.conf/55-target-ios*.conf

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ runs:
2626
mv lib lib-x86_64
2727
cp -R ../ldc2-arm64/lib lib-arm64
2828
cp -R ../ldc2-arm64/lib-ios-arm64 ./
29+
cp -R ../ldc2-arm64/lib-ios-simulator-arm64 ./
2930
3031
# merge executables to universal ones
3132
for exe in bin/*; do
@@ -40,9 +41,9 @@ runs:
4041
4142
# ldc2.conf:
4243
43-
# 1) x86_64 iOS: already present (55-target-ios-x86_64.conf)
44-
# 2) arm64 iOS config
45-
cp ../ldc2-arm64/etc/ldc2.conf/55-target-ios-arm64.conf etc/ldc2.conf/
44+
# 1) x86_64 iOS-simulator: already present (55-target-ios-simulator-x86_64.conf)
45+
# 2) arm64 iOS and iOS-simulator
46+
cp ../ldc2-arm64/etc/ldc2.conf/55-target-ios*-arm64.conf etc/ldc2.conf/
4647
# 3) x86_64 & arm64 macOS
4748
rm etc/ldc2.conf/50-target-default.conf # the original x86_64 config
4849
for arch in x86_64 arm64; do
@@ -64,7 +65,7 @@ runs:
6465
run: |
6566
set -eux
6667
echo 'void main() { import std.stdio; writefln("Hello world, %d bits", size_t.sizeof * 8); }' > hello.d
67-
for triple in x86_64-apple-macos11.0 arm64-apple-macos11.0 x86_64-apple-ios12.0-simulator arm64-apple-ios12.0; do
68+
for triple in x86_64-apple-macos11.0 arm64-apple-macos11.0 x86_64-apple-ios12.0-simulator arm64-apple-ios12.0-simulator arm64-apple-ios12.0; do
6869
ldc2-universal/bin/ldc2 -mtriple="$triple" hello.d
6970
ldc2-universal/bin/ldc2 -mtriple="$triple" hello.d -link-defaultlib-shared
7071
ldc2-universal/bin/ldc2 -mtriple="$triple" hello.d -O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto

.github/workflows/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@ jobs:
217217
run: |
218218
set -eux
219219
cd ..
220-
triple='${{ matrix.arch }}-apple-ios12.0${{ matrix.arch == 'x86_64' && '-simulator' || '' }}'
221-
installed/bin/ldc2 -mtriple="$triple" hello.d -of=hello_ios
222-
installed/bin/ldc2 -mtriple="$triple" hello.d -of=hello_ios_shared -link-defaultlib-shared
220+
if [[ '${{matrix.arch}}' == 'arm64' ]]; then
221+
triples=('arm64-apple-ios12.0' 'arm64-apple-ios12.0-simulator')
222+
else
223+
triples=('x86_64-apple-ios12.0-simulator')
224+
fi
225+
for triple in "${triples[@]}"; do
226+
installed/bin/ldc2 -mtriple="$triple" hello.d -of=hello_ios
227+
installed/bin/ldc2 -mtriple="$triple" hello.d -of=hello_ios_shared -link-defaultlib-shared
228+
done
223229
224230
- name: Create package & upload artifact(s)
225231
uses: ./.github/actions/7-package

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- ldc2.conf can now be a directory. All the files inside it, ordered naturally, will be concatenated and treated like a big config. (#4954)
77
- Running `ldc-build-runtime --installWithSuffix` now includes installing a target-specific .conf file to that directory. (#4978)
88
- **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)
9+
- The prebuilt arm64/universal macOS packages additionally bundle the arm64 iOS-*simulator* libraries, for out-of-the-box cross-compilation support via e.g. `-mtriple=arm64-apple-ios12.0-simulator`. (#4974)
910

1011
#### Platform support
1112

0 commit comments

Comments
 (0)