Skip to content

Commit 00b19f5

Browse files
De-matrix Android triples (#176)
* De-matrix Android triples Building for multiple ABIs at once is something the swift-build frontend does for macOS and should eventually do for other platforms. Don't "lift" the triple into a new matrix axis. This also renames the android_sdk_triple and android_ndk_version properties to plurals, since they support multiple versions. This is breaking, but the Android workflow is only a couple of days old, so this should be fine. * Always use the current version of the Android script
1 parent 457d77c commit 00b19f5

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

.github/workflows/scripts/install-and-build-with-sdk.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BUILD_EMBEDDED_WASM=false
2525
SWIFT_VERSION_INPUT=""
2626
SWIFT_BUILD_FLAGS=""
2727
SWIFT_BUILD_COMMAND="swift build"
28+
ANDROID_SDK_TRIPLES=()
2829

2930
while [[ $# -gt 0 ]]; do
3031
case $1 in
@@ -37,7 +38,7 @@ while [[ $# -gt 0 ]]; do
3738
shift
3839
;;
3940
--android-sdk-triple=*)
40-
ANDROID_SDK_TRIPLE="${1#*=}"
41+
ANDROID_SDK_TRIPLES+=("${1#*=}")
4142
shift
4243
;;
4344
--static)
@@ -660,23 +661,27 @@ build() {
660661
local sdk_name="${ANDROID_SDK_TAG}${ANDROID_SDK_PATH_SEP}android${ANDROID_SDK_PATH_SUFFIX}"
661662

662663
alias swift='$SWIFT_EXECUTABLE_FOR_ANDROID_SDK'
663-
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk ${ANDROID_SDK_TRIPLE:-$sdk_name}"
664-
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
665-
build_command="$build_command $SWIFT_BUILD_FLAGS"
666-
fi
667664

668-
log "Running: $build_command"
665+
# This can become a single invocation in the future when `swift build` supports multiple Android triples at once
666+
for android_sdk_triple in "${ANDROID_SDK_TRIPLES[@]}" ; do
667+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk ${android_sdk_triple}"
668+
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
669+
build_command="$build_command $SWIFT_BUILD_FLAGS"
670+
fi
669671

670-
# clear the ANDROID_NDK_ROOT environment variable if it is set
671-
# due to https://github.com/swiftlang/swift-driver/pull/1879
672-
# otherwise build error: missing required module 'SwiftAndroid'
673-
export ANDROID_NDK_ROOT=""
672+
log "Running: $build_command"
674673

675-
if eval "$build_command"; then
676-
log "✅ Swift build with Android Swift SDK completed successfully"
677-
else
678-
fatal "Swift build with Android Swift SDK failed"
679-
fi
674+
# clear the ANDROID_NDK_ROOT environment variable if it is set
675+
# due to https://github.com/swiftlang/swift-driver/pull/1879
676+
# otherwise build error: missing required module 'SwiftAndroid'
677+
export ANDROID_NDK_ROOT=""
678+
679+
if eval "$build_command"; then
680+
log "✅ Swift build with Android Swift SDK completed successfully"
681+
else
682+
fatal "Swift build with Android Swift SDK failed"
683+
fi
684+
done
680685
fi
681686

682687
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then

.github/workflows/swift_package_test.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ on:
139139
type: string
140140
description: "Command to use when building the package with the Swift SDK for Android"
141141
default: "swift build"
142-
android_sdk_triple:
142+
android_sdk_triples:
143143
type: string
144-
description: "The triple to use when building with the Swift SDK for Android"
145-
default: "[\"x86_64-unknown-linux-android28\"]"
146-
android_ndk_version:
144+
description: "The triples to use when building with the Swift SDK for Android"
145+
default: "[\"aarch64-unknown-linux-android28\", \"x86_64-unknown-linux-android28\"]"
146+
android_ndk_versions:
147147
type: string
148-
description: "The NDK version to use when building with the Swift SDK for Android"
148+
description: "The NDK versions to use when building with the Swift SDK for Android"
149149
default: "[\"r27d\"]"
150150
windows_pre_build_command:
151151
type: string
@@ -511,8 +511,7 @@ jobs:
511511
fail-fast: false
512512
matrix:
513513
swift_version: ${{ fromJson(inputs.android_sdk_versions) }}
514-
sdk_triple: ${{ fromJson(inputs.android_sdk_triple) }}
515-
ndk_version: ${{ fromJson(inputs.android_ndk_version) }}
514+
ndk_version: ${{ fromJson(inputs.android_ndk_versions) }}
516515
os_version: ${{ fromJson(inputs.linux_os_versions) }}
517516
exclude:
518517
- ${{ fromJson(inputs.android_exclude_swift_versions) }}
@@ -529,6 +528,26 @@ jobs:
529528
- name: Checkout repository
530529
uses: actions/checkout@v1
531530
if: ${{ matrix.os_version == 'amazonlinux2' }}
531+
- name: Checkout swiftlang/github-workflows repository
532+
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
533+
uses: actions/checkout@v4
534+
with:
535+
repository: swiftlang/github-workflows
536+
path: github-workflows
537+
- name: Checkout swiftlang/github-workflows repository
538+
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
539+
uses: actions/checkout@v1
540+
with:
541+
repository: swiftlang/github-workflows
542+
path: github-workflows
543+
- name: Determine script-root path
544+
id: script_path
545+
run: |
546+
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
547+
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
548+
else
549+
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
550+
fi
532551
- name: Provide token
533552
if: ${{ inputs.needs_token }}
534553
run: |
@@ -559,8 +578,8 @@ jobs:
559578
echo "Unknown package manager (tried apt-get, dnf, yum)" >&2
560579
exit 1
561580
fi
562-
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
563-
bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple="${{ matrix.sdk_triple }}" --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}
581+
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh | \
582+
bash -s -- --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }} --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}
564583
565584
windows-build:
566585
name: Windows (${{ matrix.swift_version }} - windows-2022)

0 commit comments

Comments
 (0)