Skip to content

Commit 68ecf81

Browse files
committed
1 parent 736570b commit 68ecf81

File tree

5 files changed

+56
-23
lines changed

5 files changed

+56
-23
lines changed

.github/workflows/pull_request.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ jobs:
6161
sudo docker builder prune -a
6262
df -h
6363
- name: Setup
64+
id: config
6465
run: |
6566
# these variabes are used by build-docker and build-local
6667
# to determine which Swift version to build for
6768
echo "BUILD_VERSION=${{ matrix.swift-version }}" >> $GITHUB_ENV
6869
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV
70+
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV
6971
- name: Checkout repository
7072
uses: actions/checkout@v4
7173
with:
@@ -75,12 +77,12 @@ jobs:
7577
working-directory: swift-ci/sdks/android
7678
run: |
7779
sudo apt install -q ninja-build patchelf
78-
./build-local
80+
./build-local ${BUILD_VERSION} ${WORKDIR}
7981
- name: Build Android SDK (Docker)
8082
if: ${{ matrix.build-type == 'docker' }}
8183
working-directory: swift-ci/sdks/android
8284
run: |
83-
./build-docker
85+
./build-docker ${BUILD_VERSION} ${WORKDIR}
8486
- name: Install Host Toolchain
8587
if: ${{ matrix.build-type == 'docker' }}
8688
working-directory: swift-ci/sdks/android
@@ -89,20 +91,20 @@ jobs:
8991
# but we need one in order to run the SDK validation tests, so we install it now
9092
HOST_OS=ubuntu$(lsb_release -sr)
9193
source ./scripts/toolchain-vars.sh
92-
mkdir -p ${{ runner.temp }}/swift-android-sdk/host-toolchain
93-
./scripts/install-swift.sh ${{ runner.temp }}/swift-android-sdk/host-toolchain/$SWIFT_BASE/usr
94-
ls ${{ runner.temp }}/swift-android-sdk/host-toolchain
95-
${{ runner.temp }}/swift-android-sdk/host-toolchain/*/usr/bin/swift --version
94+
mkdir -p ${WORKDIR}/host-toolchain
95+
./scripts/install-swift.sh ${WORKDIR}/host-toolchain/$SWIFT_BASE/usr
96+
ls ${WORKDIR}/host-toolchain
97+
${WORKDIR}/host-toolchain/*/usr/bin/swift --version
9698
- name: Get artifact info
9799
id: info
98100
shell: bash
99101
run: |
100102
set -ex
101-
SWIFT_ROOT=$(dirname ${{ runner.temp }}/swift-android-sdk/host-toolchain/*/usr)
103+
SWIFT_ROOT=$(dirname ${WORKDIR}/host-toolchain/*/usr)
102104
echo "swift-root=${SWIFT_ROOT}" >> $GITHUB_OUTPUT
103105
echo "swift-path=${SWIFT_ROOT}/usr/bin/swift" >> $GITHUB_OUTPUT
104106
105-
ARTIFACT_PATH=$(realpath ${{ runner.temp }}/swift-android-sdk/products/*.artifactbundle.tar.gz)
107+
ARTIFACT_PATH=$(realpath ${WORKDIR}/products/*.artifactbundle.tar.gz)
106108
echo "artifact-path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT
107109
echo "sdk-id=x86_64-unknown-linux-android28" >> $GITHUB_OUTPUT
108110
@@ -133,7 +135,7 @@ jobs:
133135
run: |
134136
# need to free up some space or else when installing we get: No space left on device
135137
df -h
136-
rm -rf ${{ runner.temp }}/swift-android-sdk/{build,src}
138+
rm -rf ${WORKDIR}/{build,src}
137139
df -h
138140
- name: Install artifactbundle
139141
shell: bash

swift-ci/sdks/android/README.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22

33
This is a Dockerfile-based build set-up for the Swift Android SDK.
44

5-
To build the Docker container and run the
5+
The top-level `./build-docker` script will create a
6+
Docker container and install a host toolchain and the
7+
Android NDK, and then invoke `scripts/fetch-source.sh` which will
8+
fetch tagged sources for libxml2, curl, boringssl, and swift.
9+
10+
It can be run with:
11+
12+
```
13+
$ ./build-docker <version> <workdir>
14+
```
15+
16+
for example:
617

718
```
8-
$ docker build -t swift-android .
19+
$ ./build-docker release /tmp/android-sdk
920
```
1021

11-
This folder contains scripts to build a Swift Android SDK
12-
in the form of an artifactbundle.
22+
This will create an Ubuntu 24.04 container with the necessary dependencies
23+
to build the Android SDK, including a Swift host toolchain and the
24+
Android NDK that will be used for cross-compilation.
25+
26+
The `version` argument can be one of the following values:
27+
28+
| version | Swift version |
29+
| --- | --- |
30+
| `release` | swift-6.1-RELEASE |
31+
| `devel` | swift-6.2-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
32+
| `trunk` | swift-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
1333

1434
## Running
1535

@@ -35,7 +55,7 @@ whereas building for all the architectures takes over an hour.
3555
To build an artifactbundle for just the `x86_64` architecture, run:
3656

3757
```
38-
TARGET_ARCHS=aarch64 ./build-docker
58+
TARGET_ARCHS=aarch64 ./build-docker release /tmp/android-sdk
3959
```
4060

4161
## Installing and validating the SDK
@@ -46,6 +66,5 @@ will create and upload an installable SDK named something like:
4666

4767
The workflow will also install the SDK locally and use
4868
[swift-android-action](https://github.com/marketplace/actions/swift-android-action)
49-
to build and test various Swift packages in an Android emulator.
50-
51-
69+
to build and test various Swift packages in an Android emulator using the
70+
freshly-created SDK bundle.

swift-ci/sdks/android/build-docker

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash -e
22
#
33
# ===----------------------------------------------------------------------===
44
#
@@ -12,9 +12,15 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
1212
ANDROID_NDK_VERSION=android-ndk-r27c
1313
ANDROID_API=28
1414

15+
export BUILD_VERSION=${1}
1516
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
16-
WORKDIR=${RUNNER_TEMP:-${TMPDIR:-'/tmp'}}/swift-android-sdk
17+
WORKDIR=${2}
18+
if [[ "${WORKDIR}" == '' ]]; then
19+
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
20+
exit 1
21+
fi
1722
mkdir -p ${WORKDIR}
23+
WORKDIR=$(realpath ${WORKDIR})
1824

1925
HOST_OS=ubuntu24.04
2026
source ./scripts/toolchain-vars.sh

swift-ci/sdks/android/build-local

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash -e
22
#
33
# ===----------------------------------------------------------------------===
44
#
@@ -12,16 +12,22 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
1212
ANDROID_NDK_VERSION=android-ndk-r27c
1313
ANDROID_API=28
1414

15+
export BUILD_VERSION=${1}
1516
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
16-
WORKDIR=${RUNNER_TEMP:-${TMPDIR:-'/tmp'}}/swift-android-sdk
17+
WORKDIR=${1}
18+
if [[ "${WORKDIR}" == '' ]]; then
19+
echo "Usage: $(basename $0) <release/devel/trunk> <work directory>"
20+
exit 1
21+
fi
1722
mkdir -p ${WORKDIR}
23+
WORKDIR=$(realpath ${WORKDIR})
1824

1925
HOST_OS=ubuntu$(lsb_release -sr)
2026
source ./scripts/toolchain-vars.sh
2127

2228
SWIFT_ROOT=${WORKDIR}/host-toolchain
2329
HOST_TOOLCHAIN=$SWIFT_ROOT/$SWIFT_BASE/usr
24-
if [[ ! -d "$SWIFT_ROOT/$SWIFT_BASE" ]]; then
30+
if [[ ! -d "$HOST_TOOLCHAIN" ]]; then
2531
./scripts/install-swift.sh ${HOST_TOOLCHAIN}
2632
fi
2733

swift-ci/sdks/android/scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# Swift SDK for Android: Build Script
3-
set -ex
3+
set -e
44

55
# Docker sets TERM to xterm if using a pty; we probably want
66
# xterm-256color, otherwise we only get eight colors

0 commit comments

Comments
 (0)