|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +snapshot="swift-6.4.x-DEVELOPMENT-SNAPSHOT-2026-07-23-a" |
| 5 | +expected_commit="ef761e567dc94ee" |
| 6 | +toolchain_identifier="org.swift.64202607231a" |
| 7 | +download_root="https://download.swift.org/swift-6.4.x-branch" |
| 8 | +temporary_parent="${RUNNER_TEMP:-${TMPDIR:-/tmp}}" |
| 9 | +temporary_directory="$(mktemp -d "$temporary_parent/swift-toolchain.XXXXXX")" |
| 10 | + |
| 11 | +cleanup() { |
| 12 | + rm -rf "$temporary_directory" |
| 13 | +} |
| 14 | +trap cleanup EXIT |
| 15 | + |
| 16 | +verify_compiler() { |
| 17 | + local swift_binary="$1" |
| 18 | + local version |
| 19 | + version="$("$swift_binary" --version)" |
| 20 | + if [[ "$version" != *"Swift $expected_commit"* ]]; then |
| 21 | + echo "Unexpected Swift compiler. Required commit: $expected_commit" >&2 |
| 22 | + echo "$version" >&2 |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + echo "$version" |
| 26 | +} |
| 27 | + |
| 28 | +append_github_path() { |
| 29 | + local directory="$1" |
| 30 | + if [[ -n "${GITHUB_PATH:-}" ]]; then |
| 31 | + printf '%s\n' "$directory" >> "$GITHUB_PATH" |
| 32 | + fi |
| 33 | +} |
| 34 | + |
| 35 | +install_macos_toolchain() { |
| 36 | + local toolchain_root="$HOME/Library/Developer/Toolchains/$snapshot.xctoolchain" |
| 37 | + if [[ ! -x "$toolchain_root/usr/bin/swift" ]]; then |
| 38 | + local package_path="$temporary_directory/$snapshot-osx.pkg" |
| 39 | + local package_url="$download_root/xcode/$snapshot/$snapshot-osx.pkg" |
| 40 | + curl --fail --location --show-error "$package_url" --output "$package_path" |
| 41 | + |
| 42 | + local signature |
| 43 | + signature="$(pkgutil --check-signature "$package_path")" |
| 44 | + if [[ "$signature" != *"Developer ID Installer: Swift Open Source (V9AUD2URP3)"* ]]; then |
| 45 | + echo "Swift toolchain package signature verification failed." >&2 |
| 46 | + echo "$signature" >&2 |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + |
| 50 | + installer -pkg "$package_path" -target CurrentUserHomeDirectory |
| 51 | + fi |
| 52 | + |
| 53 | + local toolchain_linker="$toolchain_root/usr/bin/ld" |
| 54 | + if [[ ! -x "$toolchain_linker" ]]; then |
| 55 | + local xcode_linker |
| 56 | + xcode_linker="$(xcrun --toolchain XcodeDefault --find ld)" |
| 57 | + if [[ ! -x "$xcode_linker" ]]; then |
| 58 | + echo "The active Xcode toolchain does not provide an executable linker: $xcode_linker" >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + if [[ -L "$toolchain_linker" ]]; then |
| 62 | + unlink "$toolchain_linker" |
| 63 | + elif [[ -e "$toolchain_linker" ]]; then |
| 64 | + echo "The Swift toolchain linker path exists but is not executable: $toolchain_linker" >&2 |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + ln -s "$xcode_linker" "$toolchain_linker" |
| 68 | + fi |
| 69 | + |
| 70 | + local swift_binary |
| 71 | + swift_binary="$(xcrun --toolchain "$toolchain_identifier" --find swift)" |
| 72 | + verify_compiler "$swift_binary" |
| 73 | + append_github_path "${swift_binary%/swift}" |
| 74 | + if [[ -n "${GITHUB_ENV:-}" ]]; then |
| 75 | + printf 'TOOLCHAINS=%s\n' "$toolchain_identifier" >> "$GITHUB_ENV" |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +case "$(uname -s)" in |
| 80 | + Darwin) |
| 81 | + install_macos_toolchain |
| 82 | + ;; |
| 83 | + *) |
| 84 | + echo "Unsupported operating system: $(uname -s)" >&2 |
| 85 | + exit 1 |
| 86 | + ;; |
| 87 | +esac |
0 commit comments