|
| 1 | +#!/bin/bash -e |
| 2 | +# Example usage: ./scripts/release_toolchain.sh ~/Downloads/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-12-a-android-24-0.1.artifactbundle.tar.gz.zip |
| 3 | +# download SDK artifact from https://github.com/swift-android-sdk/swift-android-sdk/actions |
| 4 | + |
| 5 | +PROG=$(basename $0) |
| 6 | + |
| 7 | +#RELEASE_REPO=skiptools/swift-android-toolchain |
| 8 | +#RELEASE_REPO=swift-android-sdk/swift-android-sdk |
| 9 | + |
| 10 | +# e.g., override with: |
| 11 | +# RELEASE_REPO=skiptools/swift-android-toolchain release_toolchain.sh |
| 12 | + |
| 13 | +RELEASE_REPO=${RELEASE_REPO:-"swift-android-sdk/swift-android-sdk"} |
| 14 | +#RELEASE_REPO=${RELEASE_REPO:-"skiptools/swift-android-toolchain"} |
| 15 | + |
| 16 | +ARTIFACTBUNDLE=$1 |
| 17 | +SUFFIX="_android.artifactbundle.tar.gz" |
| 18 | + |
| 19 | +if [ -z $ARTIFACTBUNDLE ]; then |
| 20 | + echo "Usage: $PROG <zip of artifact>" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +WD=`mktemp -d` |
| 25 | +cp -s ${ARTIFACTBUNDLE} ${WD} |
| 26 | +cd ${WD} |
| 27 | +ARTIFACTBUNDLE=$(basename ${ARTIFACTBUNDLE}) |
| 28 | + |
| 29 | +if [[ $ARTIFACTBUNDLE == *.zip ]]; then |
| 30 | + unzip -o $ARTIFACTBUNDLE |
| 31 | + #ARTIFACTBUNDLE=$(basename $ARTIFACTBUNDLE .zip) |
| 32 | + ARTIFACTBUNDLE=$(ls -1 *.tar.gz | tail -n 1) |
| 33 | +fi |
| 34 | + |
| 35 | +if [[ $ARTIFACTBUNDLE != swift-* || $ARTIFACTBUNDLE != *${SUFFIX} ]]; then |
| 36 | + echo "$PROG: Invalid SDK name: $ARTIFACTBUNDLE" |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +# TODO: run verification |
| 41 | +#~/bin/swift-android-sdk-verify.sh ${ARTIFACTBUNDLE} |
| 42 | + |
| 43 | +CHECKSUM=$(shasum -a 256 ${ARTIFACTBUNDLE} | cut -f 1 -d ' ') |
| 44 | +SDKNAME=$(basename ${ARTIFACTBUNDLE} ${SUFFIX} | cut -c 7-) |
| 45 | +LOCAL_ARTIFACTNAME=$(basename ${ARTIFACTBUNDLE} .tar.gz) |
| 46 | + |
| 47 | +# trim trailing "-RELEASE" for full releases |
| 48 | +SDKNAME=$(echo ${SDKNAME} | sed 's;-RELEASE$;;g') |
| 49 | + |
| 50 | +# the swiftly name for the SDK release |
| 51 | +SWIFTLY_NAME=$(echo "${SDKNAME}" | tr '[A-Z]' '[a-z]' | sed 's;-development-snapshot-;-snapshot-;g' | sed 's;development-snapshot-;main-snapshot-;g' | sed 's;-a-.*;-a;g') |
| 52 | + |
| 53 | +echo "$PROG: Creating release for SDK: $SDKNAME" |
| 54 | + |
| 55 | +NOTES_FILE=$(mktemp) |
| 56 | +cat > ${NOTES_FILE} << EOF |
| 57 | +### Installing the Swift SDK for Android |
| 58 | +
|
| 59 | +First install the matching Swift \`${SWIFTLY_NAME}\` toolchain from https://swift.org/download/#releases and add it to your PATH, or by using [swiftly](https://www.swift.org/install/): |
| 60 | +
|
| 61 | +\`\`\` |
| 62 | +swiftly install ${SWIFTLY_NAME} |
| 63 | +\`\`\` |
| 64 | +
|
| 65 | +Then install the Swift SDK for Android by running the command: |
| 66 | +
|
| 67 | +\`\`\` |
| 68 | +swift sdk install https://github.com/${RELEASE_REPO}/releases/download/${SDKNAME}/${ARTIFACTBUNDLE} --checksum ${CHECKSUM} |
| 69 | +\`\`\` |
| 70 | +
|
| 71 | +### Installing the Android NDK |
| 72 | +
|
| 73 | +The Swift SDK for Android requires the Android Native Development Toolkit ([NDK](https://developer.android.com/ndk/)) to function, which must be installed separately. Download and unzip the r27c LTS release and set the \`ANDROID_NDK_HOME\` environment variable to the local NDK installation and run the setup script. |
| 74 | +
|
| 75 | +#### macOS configuration command for [android-ndk-r27c-darwin.zip](https://dl.google.com/android/repository/android-ndk-r27c-darwin.zip): |
| 76 | +
|
| 77 | +\`\`\` |
| 78 | +ANDROID_NDK_HOME=~/Downloads/android-ndk-r27c ~/Library/org.swift.swiftpm/swift-sdks/${LOCAL_ARTIFACTNAME}/swift-android/scripts/setup-android-sdk.sh |
| 79 | +\`\`\` |
| 80 | +
|
| 81 | +#### Linux configuration command for [android-ndk-r27c-linux.zip](https://dl.google.com/android/repository/android-ndk-r27c-linux.zip): |
| 82 | +
|
| 83 | +\`\`\` |
| 84 | +ANDROID_NDK_HOME=~/android-ndk-r27c ~/.swiftpm/swift-sdks/${LOCAL_ARTIFACTNAME}/swift-android/scripts/setup-android-sdk.sh |
| 85 | +\`\`\` |
| 86 | +
|
| 87 | +#### GitHub Actions: |
| 88 | +
|
| 89 | +\`\`\` |
| 90 | +~/.swiftpm/swift-sdks/${LOCAL_ARTIFACTNAME}/swift-android/scripts/setup-android-sdk.sh |
| 91 | +\`\`\` |
| 92 | +
|
| 93 | +> [!NOTE] |
| 94 | +> GitHub Actions already includes the Android NDK and defines \`ANDROID_NDK_HOME\`, so there is no need to install the NDK separately. Alternatively, you can use the [swift-android-action](https://github.com/marketplace/actions/swift-android-action) to build Swift packages and run Android tests from a GitHub workflow. |
| 95 | +
|
| 96 | +### Building Swift Packages for Android |
| 97 | +
|
| 98 | +Now you can compile a Swift package for Android with: |
| 99 | +
|
| 100 | +\`\`\` |
| 101 | +$ git clone https://github.com/apple/swift-algorithms.git |
| 102 | +$ cd swift-algorithms/ |
| 103 | +$ swiftly run swift build --swift-sdk aarch64-unknown-linux-android28 +${SWIFTLY_NAME} |
| 104 | +\`\`\` |
| 105 | +
|
| 106 | +### Running Swift Executables on Android |
| 107 | +
|
| 108 | +If you have a connected Android device with [USB debugging enabled](https://developer.android.com/studio/debug/dev-options#Enable-debugging), or are running an [Android emulator](https://developer.android.com/studio/run/emulator), you can create and run a Swift executable with the following commands: |
| 109 | +
|
| 110 | +\`\`\` |
| 111 | +$ mkdir ExecutableDemo |
| 112 | +$ cd ExecutableDemo |
| 113 | +$ swift package init --type executable |
| 114 | +$ swiftly run swift build --static-swift-stdlib --swift-sdk aarch64-unknown-linux-android28 +${SWIFTLY_NAME} |
| 115 | +$ adb push .build/debug/ExecutableDemo /data/local/tmp/ |
| 116 | +$ adb push \${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/*/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp/ |
| 117 | +$ adb shell /data/local/tmp/ExecutableDemo |
| 118 | +\`\`\` |
| 119 | +
|
| 120 | +EOF |
| 121 | + |
| 122 | +cat ${NOTES_FILE} |
| 123 | + |
| 124 | +gh release create --repo ${RELEASE_REPO} --prerelease --notes-file ${NOTES_FILE} --title "${SDKNAME}" "${SDKNAME}" ${ARTIFACTBUNDLE} |
| 125 | + |
0 commit comments