Skip to content

Commit 92b96c1

Browse files
committed
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.
1 parent b2b2b25 commit 92b96c1

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
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_triple[@]}" ; do
667+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk ${sdk_name} --triple ${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: 7 additions & 8 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) }}
@@ -560,7 +559,7 @@ jobs:
560559
exit 1
561560
fi
562561
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 }}
562+
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 }}
564563
565564
windows-build:
566565
name: Windows (${{ matrix.swift_version }} - windows-2022)

0 commit comments

Comments
 (0)