Skip to content

Use official endpoints for discovering latest Swift releases #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ jobs:
path: |
*.log

static-linux-build:
name: Build Static Linux image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build Docker images
working-directory: swift-ci/sdks/static-linux
run: ./build

android-build:
name: Build Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} SDK
strategy:
Expand All @@ -45,7 +35,7 @@ jobs:
#arch: ['x86_64']
# build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs
#arch: ['x86_64', '']
swift-version: ['release', 'devel', 'trunk']
swift-version: ['release', 'swift-6.2-branch', 'development']
runs-on: ubuntu-24.04
steps:
- name: Free Disk Space
Expand All @@ -62,7 +52,7 @@ jobs:
run: |
# these variabes are used by build-docker and build-local
# to determine which Swift version to build for
echo "BUILD_VERSION=${{ matrix.swift-version }}" >> $GITHUB_ENV
echo "BUILD_SCHEME=${{ matrix.swift-version }}" >> $GITHUB_ENV
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV
- name: Checkout repository
Expand All @@ -72,12 +62,12 @@ jobs:
working-directory: swift-ci/sdks/android
run: |
sudo apt install -q ninja-build patchelf
./build-local ${BUILD_VERSION} ${WORKDIR}
./build-local ${BUILD_SCHEME} ${WORKDIR}
- name: Build Android SDK (Docker)
if: ${{ matrix.build-type == 'docker' }}
working-directory: swift-ci/sdks/android
run: |
./build-docker ${BUILD_VERSION} ${WORKDIR}
./build-docker ${BUILD_SCHEME} ${WORKDIR}
- name: Install Host Toolchain
if: ${{ matrix.build-type == 'docker' }}
working-directory: swift-ci/sdks/android
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.*.swp
static-swift-linux-sources
Empty file removed .gitmodules
Empty file.
31 changes: 23 additions & 8 deletions swift-ci/sdks/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ Android NDK that will be used for cross-compilation.

The `version` argument can be one of the following values:

| version | Swift version |
| version | Swift version example |
| --- | --- |
| `release` | swift-6.1-RELEASE |
| `devel` | swift-6.2-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
| `trunk` | swift-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
| `swift-6.2-branch` | swift-6.2-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |
| `development` | swift-DEVELOPMENT-SNAPSHOT-yyyy-mm-dd |

> [!WARNING]
> The workdir argument must not be located in a git repository (e.g., it cannot be the
> current directory)

## Running

Expand All @@ -39,13 +43,14 @@ fetch tagged sources for libxml2, curl, boringssl, and swift.

It then applies some patches and invokes `scripts/build.sh`,
which will build the sources for each of the specified
architectures. Finally, it combines the NDK and the newly built
SDKs into a single artifactbundle.
architectures and then combines the SDKs into a single
artifactbundle with targetTriples for each of the supported
architectures (`aarch64`, `x86_64`, `aarmv7`)
and Android API levels (28-35).

## Specifying Architectures

By default all the supported Android architectures
(`aarch64`, `x86_64`, `aarmv7`)
will be built, but this can be reduced in order to speed
up the build. This can be useful, e.g., as part of a CI that
validates a pull request, as building a single architecture
Expand All @@ -55,7 +60,7 @@ whereas building for all the architectures takes over an hour.
To build an artifactbundle for just the `x86_64` architecture, run:

```
TARGET_ARCHS=aarch64 ./build-docker release /tmp/android-sdk
TARGET_ARCHS=x86_64 ./build-docker release /tmp/android-sdk
```

## Installing and validating the SDK
Expand All @@ -64,7 +69,17 @@ The `.github/workflows/pull_request.yml` workflow
will create and upload an installable SDK named something like:
`swift-6.1-RELEASE_android-0.1.artifactbundle.tar.gz`

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

## Building locally

Instead of building within a Docker container, the script can also
perform the build locally on an Ubuntu 24.04 machine with all the
build prerequisites already installed. This will generate
the same artifacts in approximately half the time, and
may be suitable to an already containerized envrionment (such as
a GitHub runner).

2 changes: 1 addition & 1 deletion swift-ci/sdks/android/build-docker
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
ANDROID_NDK_VERSION=android-ndk-r27c
ANDROID_API=28

export BUILD_VERSION=${1}
export BUILD_SCHEME=${1}
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
WORKDIR=${2}
if [[ "${WORKDIR}" == '' ]]; then
Expand Down
2 changes: 1 addition & 1 deletion swift-ci/sdks/android/build-local
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TARGET_ARCHS=${TARGET_ARCHS:-aarch64,x86_64,armv7}
ANDROID_NDK_VERSION=android-ndk-r27c
ANDROID_API=28

export BUILD_VERSION=${1}
export BUILD_SCHEME=${1}
# note that WORKDIR must not be under the current checkout or the patches will fail to apply
WORKDIR=${2}
if [[ "${WORKDIR}" == '' ]]; then
Expand Down
8 changes: 4 additions & 4 deletions swift-ci/sdks/android/scripts/patch-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ perl -pi -e 's;dispatch android-execinfo;dispatch;g' $swift_android_patch
perl -pi -e 's;call ln -sf;call ln -svf;g' $swift_android_patch
perl -pi -e 's%linux-x86_64/sysroot/usr/lib"%linux-x86_64/sysroot/usr/lib"; echo "VALIDATING SYMBOLIC LINK"; ls -la "\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib"; ls -la "\${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/swift"; %g' $swift_android_patch

case "${BUILD_VERSION}" in
case "${BUILD_SCHEME}" in
release)
testing_patch="${patches_dir}/swift-android-testing-release.patch"
;;
devel)
swift-*-branch)
testing_patch="${patches_dir}/swift-android-testing-except-release.patch"
;;
trunk)
development)
testing_patch="${patches_dir}/swift-android-testing-except-release.patch"
dispatch_patch="${patches_dir}/swift-android-trunk-libdispatch.patch"
;;
*)
echo "$0: invalid BUILD_VERSION=${BUILD_VERSION}"
echo "$0: invalid BUILD_SCHEME=${BUILD_SCHEME}"
exit 1
;;
esac
Expand Down
34 changes: 16 additions & 18 deletions swift-ci/sdks/android/scripts/toolchain-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,36 @@
# ===----------------------------------------------------------------------===

# This script is meant to be sourced from another script that sets the
# BUILD_VERSION environment variable to one of "release", "devel", or "trunk"
# BUILD_SCHEME environment variable to one of "release", "swift-VERSION-branch", or "development"
# and will set check the latest builds for each build type in order
# to provide information about the Swift tag name in use and where to
# obtain the latest toolchain for building.

# TODO: we could instead use the latest-build.yml files for this, like:
# https://download.swift.org/swift-6.2-branch/ubuntu2404/latest-build.yml
# https://download.swift.org/development/ubuntu2404/latest-build.yml
# but there doesn't seem to be one for the current release build.
OS=$(echo $HOST_OS | tr -d '.')

case "${BUILD_VERSION}" in
case "${BUILD_SCHEME}" in
release)
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/swiftlang/swift/releases | grep -m1 swift-6.1 | cut -d- -f2)
SWIFT_TAG="swift-${LATEST_TOOLCHAIN_VERSION}-RELEASE"
SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-release"
# e.g., "swift-6.1-RELEASE"
SWIFT_TAG=$(curl -fsSL https://www.swift.org/api/v1/install/releases.json | jq -r '.[-1].tag')
# e.g., "swift-6.1-release"
SWIFT_BRANCH=$(echo "${SWIFT_TAG}" | tr '[A-Z]' '[a-z]')
;;
devel)
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/swiftlang/swift/tags | grep -m1 swift-6.2-DEV | cut -d- -f8-10)
SWIFT_TAG="swift-6.2-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
SWIFT_BRANCH="swift-$(echo $SWIFT_TAG | cut -d- -f2)-branch"
swift-*-branch)
# e.g., swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-15-a
SWIFT_TAG=$(curl -fsSL https://download.swift.org/$BUILD_SCHEME/$OS/latest-build.yml | grep '^dir: ' | cut -f 2 -d ' ')
SWIFT_BRANCH=$BUILD_SCHEME
;;
trunk)
LATEST_TOOLCHAIN_VERSION=$(curl -sL https://github.com/swiftlang/swift/tags | grep -m1 swift-DEV | cut -d- -f7-9)
SWIFT_TAG="swift-DEVELOPMENT-SNAPSHOT-${LATEST_TOOLCHAIN_VERSION}-a"
development)
# e.g., swift-DEVELOPMENT-SNAPSHOT-2025-05-14-a
SWIFT_TAG=$(curl -fsSL https://download.swift.org/development/$OS/latest-build.yml | grep '^dir: ' | cut -f 2 -d ' ')
SWIFT_BRANCH="development"
;;
*)
echo "$0: invalid BUILD_VERSION=${BUILD_VERSION}"
echo "$0: invalid BUILD_SCHEME=${BUILD_SCHEME}"
exit 1
;;
esac

SWIFT_BASE=$SWIFT_TAG-$HOST_OS
export SWIFT_TOOLCHAIN_URL="https://download.swift.org/$SWIFT_BRANCH/$(echo $HOST_OS | tr -d '.')/$SWIFT_TAG/$SWIFT_BASE.tar.gz"
export SWIFT_TOOLCHAIN_URL="https://download.swift.org/$SWIFT_BRANCH/$OS/$SWIFT_TAG/$SWIFT_BASE.tar.gz"

Loading