Skip to content

Commit 6f90334

Browse files
committed
Switch over to using explicit tags and branches when invoking build-docker/local
Also, force the full Swift compiler to be built from source when building from a branch, since there are no existing toolchain builds of arbitrary commits that we can download.
1 parent df84969 commit 6f90334

File tree

5 files changed

+72
-62
lines changed

5 files changed

+72
-62
lines changed

swift-ci/sdks/android/README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ $ ./build-docker <version> <workdir>
1616
for example:
1717

1818
```
19-
$ ./build-docker release /tmp/android-sdk
19+
$ ./build-docker tag:swift-6.2-RELEASE /tmp/android-sdk
2020
```
2121

2222
This will create an Ubuntu 24.04 container with the necessary dependencies
2323
to build the Android SDK, including a Swift host toolchain and the
2424
Android NDK that will be used for cross-compilation.
2525

26-
The `version` argument can be one of the following values:
27-
28-
| version | Swift version example |
29-
| --- | --- |
30-
| `release` | swift-6.1-RELEASE |
31-
| `swift-6.2-branch` | swift-6.2-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
32-
| `development` | swift-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
26+
The `version` argument can be a branch scheme, like "scheme:release/6.2", or a
27+
tag, like "tag:swift-6.2-DEVELOPMENT-SNAPSHOT-2025-09-04-a".
3328

3429
> [!WARNING]
3530
> The workdir argument must not be located in a git repository (e.g., it cannot be the
@@ -41,7 +36,7 @@ The top-level `./build-docker` script installs a host toolchain and the
4136
Android NDK, and then invokes `scripts/fetch-source.sh` which will
4237
fetch tagged sources for libxml2, curl, boringssl, and swift.
4338

44-
It then applies some patches and invokes `scripts/build.sh`,
39+
It then applies some perl substitutions and invokes `scripts/build.sh`,
4540
which will build the sources for each of the specified
4641
architectures and then combines the SDKs into a single
4742
artifactbundle with targetTriples for each of the supported
@@ -50,7 +45,7 @@ and Android API levels (28-35).
5045

5146
## Specifying Architectures
5247

53-
By default all the supported Android architectures
48+
By default, all the supported Android architectures
5449
will be built, but this can be reduced in order to speed
5550
up the build. This can be useful, e.g., as part of a CI that
5651
validates a pull request, as building a single architecture
@@ -60,19 +55,20 @@ whereas building for all the architectures takes over an hour.
6055
To build an artifactbundle for just the `x86_64` architecture, run:
6156

6257
```
63-
TARGET_ARCHS=x86_64 ./build-docker release /tmp/android-sdk
58+
TARGET_ARCHS=x86_64 ./build-docker scheme:main /tmp/android-sdk
6459
```
6560

66-
## Installing and validating the SDK
61+
## Building the Swift compiler from source and running the validation suite
6762

68-
The `.github/workflows/pull_request.yml` workflow
69-
will create and upload an installable SDK named something like:
70-
`swift-6.1-RELEASE_android-0.1.artifactbundle.tar.gz`
63+
All tags that are specified will download the official release or snapshot
64+
toolchain and build only the bundle by default, while building from a branch
65+
scheme always builds the full Swift compiler from the latest commit in that
66+
branch. If you want to build the Swift compiler from source for a tag also and
67+
run the compiler validation suite, specify the `BUILD_COMPILER` variable:
7168

72-
The GitHub workflow will also install the SDK locally and use
73-
[swift-android-action](https://github.com/marketplace/actions/swift-android-action)
74-
to build and test various Swift packages in an Android emulator using the
75-
freshly-created SDK bundle.
69+
```
70+
BUILD_COMPILER=yes ./build-docker tag:swift-DEVELOPMENT-SNAPSHOT-2025-09-04-a /tmp/android-sdk
71+
```
7672

7773
## Building locally
7874

@@ -85,5 +81,5 @@ a GitHub runner). A local build can be run with the
8581
`build-local` script, such as:
8682

8783
```
88-
./build-local swift-6.2-branch /tmp/android-sdk-devel
84+
./build-local scheme:release/6.2 /tmp/android-sdk
8985
```

swift-ci/sdks/android/build-docker

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ANDROID_API=28
2323
BASEPATH=$(dirname $(realpath $0))
2424
cd ${BASEPATH}
2525

26-
export BUILD_SCHEME=${1}
26+
export SWIFT_VERSION=${1}
2727
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
2828
WORKDIR=${2}
2929
if [[ "${WORKDIR}" == '' ]]; then
@@ -34,18 +34,15 @@ mkdir -p ${WORKDIR}
3434
WORKDIR=$(realpath ${WORKDIR})
3535

3636
HOST_OS=ubuntu24.04
37+
if [[ $SWIFT_VERSION == scheme:* ]]; then
38+
BUILD_COMPILER=yes
39+
echo "Branch scheme builds always build the Swift compiler from source and take much longer."
40+
fi
41+
3742
source ./scripts/toolchain-vars.sh
3843

3944
# Check-out and patch the sources
40-
if [[ "${BUILD_COMPILER}" != "1" ]]; then
41-
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source --swift-tag ${SWIFT_TAG}
42-
else
43-
if [[ "${BUILD_SCHEME}" == "development" ]]; then
44-
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source --swift-scheme main
45-
else
46-
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source --swift-scheme release/6.2
47-
fi
48-
fi
45+
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source
4946

5047
# This `git grep` invocation in a trunk test fails in our Docker for some
5148
# reason, so just turn it into a plain `grep` again.

swift-ci/sdks/android/build-local

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ANDROID_API=28
2323
BASEPATH=$(dirname $(realpath $0))
2424
cd ${BASEPATH}
2525

26-
export BUILD_SCHEME=${1}
26+
export SWIFT_VERSION=${1}
2727
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
2828
WORKDIR=${2}
2929
if [[ "${WORKDIR}" == '' ]]; then
@@ -34,20 +34,29 @@ mkdir -p ${WORKDIR}
3434
WORKDIR=$(realpath ${WORKDIR})
3535

3636
HOST_OS=ubuntu$(lsb_release -sr)
37+
if [[ $SWIFT_VERSION == scheme:* ]]; then
38+
BUILD_COMPILER=yes
39+
echo "Branch scheme builds always build the Swift compiler from source and take much longer."
40+
fi
41+
3742
source ./scripts/toolchain-vars.sh
3843

39-
if [[ "${BUILD_COMPILER}" != "1" ]]; then
40-
SWIFT_ROOT=${WORKDIR}/host-toolchain
41-
HOST_TOOLCHAIN=$SWIFT_ROOT/$SWIFT_BASE/usr
42-
if [[ ! -d "$HOST_TOOLCHAIN" ]]; then
43-
./scripts/install-swift.sh ${HOST_TOOLCHAIN}
44-
fi
44+
case $BUILD_COMPILER in
45+
1|true|yes|YES)
46+
;;
47+
*)
48+
SWIFT_ROOT=${WORKDIR}/host-toolchain
49+
HOST_TOOLCHAIN=$SWIFT_ROOT/$SWIFT_BASE/usr
50+
if [[ ! -d "$HOST_TOOLCHAIN" ]]; then
51+
./scripts/install-swift.sh ${HOST_TOOLCHAIN}
52+
fi
4553

46-
$HOST_TOOLCHAIN/bin/swift --version
54+
$HOST_TOOLCHAIN/bin/swift --version
4755

48-
# ensure the correct Swift is first in the PATH
49-
export PATH=$HOST_TOOLCHAIN/bin:$PATH
50-
fi
56+
# ensure the correct Swift is first in the PATH
57+
export PATH=$HOST_TOOLCHAIN/bin:$PATH
58+
;;
59+
esac
5160

5261
export ANDROID_NDK_HOME=${WORKDIR}/ndk/${ANDROID_NDK_VERSION}
5362

@@ -62,7 +71,7 @@ fi
6271

6372

6473
# Check-out and patch the sources
65-
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source --swift-tag ${SWIFT_TAG}
74+
./scripts/fetch-source.sh --source-dir ${WORKDIR}/source
6675
# This `git grep` invocation in a trunk test fails in our Docker for some
6776
# reason, so just turn it into a plain `grep` again.
6877
perl -pi -e 's:"git",:#:' ${WORKDIR}/source/swift-project/swift/test/Misc/verify-swift-feature-testing.test-sh

swift-ci/sdks/android/scripts/fetch-source.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ EOF
8686
}
8787

8888
# Defaults
89-
if [[ -z "${SWIFT_VERSION}" ]]; then
90-
SWIFT_VERSION=scheme:release/6.1
89+
if [[ -z "${SWIFT_VERSION}" || ($SWIFT_VERSION != scheme:* && $SWIFT_VERSION != tag:*) ]]; then
90+
SWIFT_VERSION=scheme:release/6.2
9191
fi
9292
if [[ -z "${BORINGSSL_VERSION}" ]]; then
9393
BORINGSSL_VERSION=fips-20220613

swift-ci/sdks/android/scripts/toolchain-vars.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# This source file is part of the Swift.org open source project
88
#
9-
# Copyright (c) 2024 Apple Inc. and the Swift project authors
9+
# Copyright (c) 2025 Apple Inc. and the Swift project authors
1010
# Licensed under Apache License v2.0 with Runtime Library Exception
1111
#
1212
# See https://swift.org/LICENSE.txt for license information
@@ -15,10 +15,9 @@
1515
# ===----------------------------------------------------------------------===
1616

1717
# This script is meant to be sourced from another script that sets the
18-
# BUILD_SCHEME environment variable to one of "release", "swift-VERSION-branch", or "development"
19-
# and will set check the latest builds for each build type in order
20-
# to provide information about the Swift tag name in use and where to
21-
# obtain the latest toolchain for building.
18+
# SWIFT_VERSION environment variable to one of "scheme:release/6.2" or
19+
# "tag:swift-6.2-RELEASE" and will get the latest builds for each build
20+
# type.
2221

2322
OS=$(echo $HOST_OS | tr -d '.')
2423
# e.g., "swift-6.1-RELEASE"
@@ -27,22 +26,31 @@ RELEASE_TAG=$(curl -fsSL https://www.swift.org/api/v1/install/releases.json | jq
2726
# e.g., "swift-6.1-release"
2827
RELEASE_BRANCH=$(echo "${RELEASE_TAG}" | tr '[A-Z]' '[a-z]')
2928

30-
case "${BUILD_SCHEME}" in
31-
release)
32-
export SWIFT_TAG=$RELEASE_TAG
33-
export SWIFT_BRANCH=$RELEASE_BRANCH
34-
;;
35-
development|swift-*-branch)
36-
# e.g., swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-15-a
37-
# e.g., swift-DEVELOPMENT-SNAPSHOT-2025-05-14-a
38-
export SWIFT_TAG=$(curl -fsSL https://download.swift.org/$BUILD_SCHEME/$OS/latest-build.yml | grep '^dir: ' | cut -f 2 -d ' ')
39-
export SWIFT_BRANCH=$BUILD_SCHEME
40-
;;
29+
if [[ $SWIFT_VERSION == tag:* ]]; then
30+
SWIFT_TAG=${SWIFT_VERSION#tag:}
31+
case "${SWIFT_TAG}" in
32+
swift-*-RELEASE)
33+
SWIFT_BRANCH=$(echo "${SWIFT_TAG}" | tr '[A-Z]' '[a-z]')
34+
;;
35+
swift-6.*-DEVELOPMENT-SNAPSHOT-*)
36+
# e.g., swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-15-a
37+
SWIFT_BRANCH=${SWIFT_TAG//DEVEL*/branch}
38+
;;
39+
swift-DEVELOPMENT-SNAPSHOT-*)
40+
# e.g., swift-DEVELOPMENT-SNAPSHOT-2025-05-14-a
41+
SWIFT_BRANCH=development
42+
;;
4143
*)
42-
echo "$0: invalid BUILD_SCHEME=${BUILD_SCHEME}"
44+
echo "$0: invalid tag=${SWIFT_TAG}"
4345
exit 1
4446
;;
45-
esac
47+
esac
48+
elif [[ $SWIFT_VERSION == scheme:* ]]; then
49+
echo "Building $SWIFT_VERSION with prebuilt Swift $RELEASE_TAG compiler"
50+
else
51+
echo "Invalid Swift version=${SWIFT_VERSION}"
52+
exit 1
53+
fi
4654

4755
SWIFT_BASE=$SWIFT_TAG-$HOST_OS
4856

0 commit comments

Comments
 (0)