Skip to content

Commit 6ce60bb

Browse files
authored
setup-build: Support Swift toolchain installation (#979)
* Add support for both upstream and BCNY Swift toolchain installation as part of the `setup-build` action. * Update users of the `gha-setup-swift` action.
1 parent d4dd221 commit 6ce60bb

File tree

3 files changed

+116
-52
lines changed

3 files changed

+116
-52
lines changed

.github/actions/setup-build/action.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ inputs:
2222
This is the target architecture for the Visual Studio Developer Environment.
2323
required: false
2424
type: string
25+
swift-version:
26+
description: The Swift version to use, e.g. "6.0.1" for the upstream Apple Swift repository.
27+
Or "6.0.0-20261216.0" for a specific snapshot from another repository.
28+
If unspecified, the Swift toolchain is not set up.
29+
required: false
30+
type: string
31+
swift-repo:
32+
description: |
33+
The Swift repository to use, e.g. "thebrowsercompany/swift-build". If unspecified, and
34+
`swift-version` is specified, the upstream Apple Swift repository is used.
35+
required: false
36+
type: string
2537

2638
outputs:
2739
windows-build-tools-version:
@@ -96,14 +108,39 @@ runs:
96108
$HostArch = $BuildArch
97109
}
98110
111+
${SwiftVersion} = "${{ inputs.swift-version }}"
112+
${SwiftRepo} = "${{ inputs.swift-repo }}"
113+
if ($SwiftRepo -ne "" -and $SwiftVersion -eq "") {
114+
Write-Output "::error::The `swift-repo` input was specified, but the `swift-version` input was not. Please specify a Swift toolchain version to use."
115+
exit 1
116+
}
117+
99118
Write-Output "ℹ️ Build OS: $BuildOS"
100119
Write-Output "ℹ️ Build architecture: $BuildArch"
101120
Write-Output "ℹ️ Host architecture: $HostArch"
102121
122+
# Derive the Swift version and repository from the inputs.
123+
if ($SwiftVersion -ne "") {
124+
if ($SwiftRepo -eq "") {
125+
$SwiftBranch = "swift-${SwiftVersion}-release"
126+
$SwiftTag = "${SwiftVersion}-RELEASE"
127+
Write-Output "ℹ️ Using upstream Swift toolchain: $SwiftVersion (branch: $SwiftBranch, tag: $SwiftTag)"
128+
} else {
129+
# Note: This only supports Windows for now.
130+
$SwiftReleaseAssetName = "installer-${BuildArch}.exe"
131+
$SwiftReleaseTagName = "swift-${SwiftVersion}"
132+
Write-Output "ℹ️ Using custom Swift toolchain: $SwiftVersion (repository: $SwiftRepo, tag: $SwiftReleaseTagName, asset: $SwiftReleaseAssetName)"
133+
}
134+
}
135+
103136
@"
104137
build-os=$BuildOS
105138
build-arch=$BuildArch
106139
host-arch=$HostArch
140+
swift-branch=$SwiftBranch
141+
swift-tag=$SwiftTag
142+
swift-release-asset=$SwiftReleaseAssetName
143+
swift-release-tag=$SwiftReleaseTagName
107144
"@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
108145
109146
- name: Install Windows SDK version ${{ inputs.windows-sdk-version }}
@@ -257,3 +294,19 @@ runs:
257294
arch: ${{ steps.sanitize-input.outputs.host-arch }}
258295
winsdk: ${{ inputs.windows-sdk-version }}
259296
toolset_version: ${{ inputs.msvc-version }}
297+
298+
- name: Setup Swift toolchain (Upstream)
299+
if: inputs.swift-version != '' && inputs.swift-repo == ''
300+
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
301+
with:
302+
branch: ${{ steps.sanitize-input.outputs.swift-branch }}
303+
tag: ${{ steps.sanitize-input.outputs.swift-tag }}
304+
305+
- name: Setup Swift toolchain (Custom)
306+
if: inputs.swift-version != '' && inputs.swift-repo != ''
307+
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
308+
with:
309+
github-repo: ${{ inputs.swift-repo }}
310+
github-token: ${{ github.token }}
311+
release-asset-name: ${{ steps.sanitize-input.outputs.swift-release-asset }}
312+
release-tag-name: ${{ steps.sanitize-input.outputs.swift-release-tag }}

.github/workflows/swift-toolchain.yml

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,12 @@ on:
277277
required: true
278278

279279
env:
280-
# Workaround for needing llvm-17 on macOS preventing us from using the 5.10 toolchain release.
281-
WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_BRANCH: swift-6.0.1-release
282-
WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_TAG: 6.0.1-RELEASE
280+
PINNED_BOOTSTRAP_TOOLCHAIN_VERSION: 6.0.1
283281

284282
# Workaround for the upstream builds are still built with VS versions (17.9.x and 17.10.x)
285283
# with the ARM64 miscompile bug.
286284
WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO: thebrowsercompany/swift-build
287-
WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_RELEASE: swift-6.0.0-20241216.0
285+
WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_VERSION: 6.0.0-20241216.0
288286

289287
# Workaround for issues with building with SDK version 26100.
290288
# See https://github.com/compnerd/swift-build/issues/909 for details.
@@ -795,6 +793,8 @@ jobs:
795793
msvc-version: ${{ env.WORKAROUND_BOOTSTRAP_WINDOWS_MSVC_VERSION }}
796794
windows-sdk-version: ${{ env.WORKAROUND_BOOTSTRAP_WINDOWS_SDK_VERSION }}
797795
host-arch: ${{ matrix.arch }}
796+
swift-version: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_VERSION || env.PINNED_BOOTSTRAP_TOOLCHAIN_VERSION }}
797+
swift-repo: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO || '' }}
798798

799799
- uses: actions/[email protected]
800800
with:
@@ -827,22 +827,6 @@ jobs:
827827
path: ${{ github.workspace }}/SourceCache/swift-driver
828828
show-progress: false
829829

830-
- name: Install Swift Toolchain (macOS)
831-
if: matrix.os == 'Darwin'
832-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
833-
with:
834-
branch: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_BRANCH }}
835-
tag: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_TAG }}
836-
837-
- name: Install Swift Toolchain (Windows)
838-
if: matrix.os == 'Windows'
839-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
840-
with:
841-
github-repo: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO }}
842-
github-token: ${{ secrets.GITHUB_TOKEN }}
843-
release-asset-name: installer-${{ inputs.build_arch }}.exe
844-
release-tag-name: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_RELEASE }}
845-
846830
- name: Build early swift-driver
847831
run: |
848832
$env:SWIFTCI_USE_LOCAL_DEPS=1
@@ -930,6 +914,9 @@ jobs:
930914
windows-sdk-version: ${{ env.WORKAROUND_BOOTSTRAP_WINDOWS_SDK_VERSION }}
931915
setup-vs-dev-env: true
932916
host-arch: ${{ matrix.arch }}
917+
swift-version: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_VERSION || env.PINNED_BOOTSTRAP_TOOLCHAIN_VERSION }}
918+
swift-repo: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO || '' }}
919+
933920
- uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # master
934921
if: inputs.build_os == 'Darwin'
935922

@@ -1034,22 +1021,6 @@ jobs:
10341021
echo "PYTHON_LOCATION_amd64=$env:pythonLocation" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
10351022
echo "PYTHON_LOCATION_arm64=${{ github.workspace }}\pythonarm64.${{ env.PYTHON_VERSION_WINDOWS }}\tools" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
10361023
1037-
- name: Install Swift Toolchain
1038-
if: inputs.build_os == 'Windows'
1039-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
1040-
with:
1041-
github-repo: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO }}
1042-
github-token: ${{ secrets.GITHUB_TOKEN }}
1043-
release-asset-name: installer-${{ inputs.build_arch }}.exe
1044-
release-tag-name: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_RELEASE }}
1045-
1046-
- name: Install Swift Toolchain
1047-
if: inputs.build_os == 'Darwin'
1048-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
1049-
with:
1050-
branch: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_BRANCH }}
1051-
tag: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_TAG }}
1052-
10531024
- uses: nttld/setup-ndk@v1
10541025
if: matrix.os == 'Android'
10551026
id: setup-ndk
@@ -1085,7 +1056,7 @@ jobs:
10851056
Remove-Item env:\SDKROOT
10861057
} elseif ( "${{ matrix.os }}" -eq "Darwin" ) {
10871058
# Default swiftc comes from /usr/bin and is not compatible with the toolchain.
1088-
$CLANG_LOCATION = "${env:HOME}/Library/Developer/Toolchains/swift-${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_TAG }}.xctoolchain/usr/bin"
1059+
$CLANG_LOCATION = "${env:HOME}/Library/Developer/Toolchains/swift-${{ env.PINNED_BOOTSTRAP_TOOLCHAIN_VERSION }}-RELEASE.xctoolchain/usr/bin"
10891060
$SWIFTC = Join-Path $CLANG_LOCATION "swiftc"
10901061
10911062
# We need to use llvm-17 to build the compiler on macOS. We get it from the Swift toolchain.
@@ -1679,6 +1650,8 @@ jobs:
16791650
windows-sdk-version: ${{ env.WORKAROUND_BOOTSTRAP_WINDOWS_SDK_VERSION }}
16801651
setup-vs-dev-env: ${{ matrix.os == 'Windows' }}
16811652
host-arch: ${{ matrix.arch }}
1653+
swift-version: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_VERSION || env.PINNED_BOOTSTRAP_TOOLCHAIN_VERSION }}
1654+
swift-repo: ${{ inputs.build_os == 'Windows' && env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO || '' }}
16821655
- uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # master
16831656
if: inputs.build_os == 'Darwin'
16841657

@@ -1717,21 +1690,6 @@ jobs:
17171690
path: ${{ github.workspace }}/SourceCache/swift-experimental-string-processing
17181691
show-progress: false
17191692

1720-
- name: Install Swift Toolchain
1721-
if: inputs.build_os == 'Windows' && (matrix.os != 'Android' || inputs.build_android)
1722-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
1723-
with:
1724-
github-repo: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_REPO }}
1725-
github-token: ${{ secrets.GITHUB_TOKEN }}
1726-
release-asset-name: installer-${{ inputs.build_arch }}.exe
1727-
release-tag-name: ${{ env.WORKAROUND_WINDOWS_PINNED_BOOTSTRAP_TOOLCHAIN_RELEASE }}
1728-
- name: Install Swift Toolchain
1729-
if: inputs.build_os == 'Darwin'
1730-
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
1731-
with:
1732-
branch: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_BRANCH }}
1733-
tag: ${{ env.WORKAROUND_MACOS_PINNED_BOOTSTRAP_TOOLCHAIN_TAG }}
1734-
17351693
- uses: nttld/setup-ndk@v1
17361694
if: matrix.os == 'Android' && inputs.build_android
17371695
id: setup-ndk

.github/workflows/test-setup-build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ env:
2323
TEST_WIN_SDK_VERSION: "10.0.22000.0"
2424
TEST_MSVC_VERSION: "14.40"
2525
TEST_BUILD_TOOLS_EXPECTED_VERSION: "14.40.33807"
26+
TEST_UPSTREAM_SWIFT_VERSION: "5.10"
27+
TEST_BCNY_SWIFT_VERSION: "6.0.0-20241216.0"
28+
TEST_BCNY_SWIFT_REPO: "thebrowsercompany/swift-build"
2629

2730
jobs:
2831
test-setup-build-windows-vs-dev-env:
@@ -289,3 +292,53 @@ jobs:
289292
Write-Output "✅ Log file found. File contents:"
290293
Get-Content -Path "$LogFile"
291294
}
295+
296+
test-upstream-swift-install:
297+
name: Upstream Swift Installation
298+
runs-on: ${{ inputs.windows-runner || 'windows-latest' }}
299+
steps:
300+
- name: Checkout
301+
uses: actions/[email protected]
302+
303+
- name: Set up build with upstream Swift
304+
id: setup-build
305+
uses: ./.github/actions/setup-build
306+
with:
307+
swift-version: ${{ env.TEST_UPSTREAM_SWIFT_VERSION }}
308+
309+
- name: Check Swift installation
310+
run: |
311+
$SwiftVersion = & swift --version
312+
if ($SwiftVersion -match "Swift version ${env:TEST_UPSTREAM_SWIFT_VERSION}") {
313+
Write-Output "✅ Upstream Swift version `"$env:TEST_UPSTREAM_SWIFT_VERSION`" is installed."
314+
} else {
315+
Write-Output "::error::Expected to find Swift version `"$env:TEST_UPSTREAM_SWIFT_VERSION`" in output:"
316+
Write-Output "$SwiftVersion"
317+
exit 1
318+
}
319+
320+
test-bcny-swift-install:
321+
name: BCNY Swift Installation
322+
runs-on: ${{ inputs.windows-runner || 'windows-latest' }}
323+
steps:
324+
- name: Checkout
325+
uses: actions/[email protected]
326+
- name: Set up build with BCNY Swift
327+
id: setup-build
328+
uses: ./.github/actions/setup-build
329+
with:
330+
swift-version: ${{ env.TEST_BCNY_SWIFT_VERSION }}
331+
swift-repo: ${{ env.TEST_BCNY_SWIFT_REPO }}
332+
333+
- name: Check Swift installation
334+
run: |
335+
# Get the expected Swift version from the environment variable (i.e. "6.0" for "6.0.0-20241216.0")
336+
$ExpectedSwiftVersion = ${env:TEST_BCNY_SWIFT_VERSION} -replace '-.*$', '' | ForEach-Object { ($_ -split '\.')[0..1] -join '.' }
337+
$SwiftVersionOutput = & swift --version
338+
if (${SwiftVersionOutput} -match "Swift version ${ExpectedSwiftVersion}") {
339+
Write-Output "✅ BCNY Swift version `"${env:TEST_BCNY_SWIFT_VERSION}`" is installed."
340+
} else {
341+
Write-Output "::error::Expected to find Swift version `"${ExpectedSwiftVersion}`" in output:"
342+
Write-Output "${SwiftVersionOutput}"
343+
exit 1
344+
}

0 commit comments

Comments
 (0)