Skip to content

Commit 4f45ecc

Browse files
committed
setup-build: Support Swift toolchain installation
1 parent d4dd221 commit 4f45ecc

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

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

Lines changed: 57 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,6 +108,13 @@ 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"
@@ -106,6 +125,28 @@ runs:
106125
host-arch=$HostArch
107126
"@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
108127
128+
# Derive the Swift version and repository from the inputs.
129+
if ($SwiftVersion -ne "") {
130+
if ($SwiftRepo -eq "") {
131+
$SwiftBranch = "swift-${SwiftVersion}-release"
132+
$SwiftTag = "${SwiftVersion}-RELEASE"
133+
Write-Output "ℹ️ Using upstream Swift toolchain: $SwiftVersion (branch: $SwiftBranch, tag: $SwiftTag)"
134+
@"
135+
swift-branch=$SwiftBranch
136+
swift-tag=$SwiftTag
137+
"@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
138+
} else {
139+
# Note: This only supports Windows for now.
140+
$SwiftReleaseAssetName = "installer-${BuildArch}.exe"
141+
$SwiftReleaseTagName = "swift-${SwiftVersion}"
142+
Write-Output "ℹ️ Using custom Swift toolchain: $SwiftVersion (repository: $SwiftRepo, tag: $SwiftReleaseTagName, asset: $SwiftReleaseAssetName)"
143+
@"
144+
swift-release-tag=$SwiftReleaseTagName
145+
swift-release-asset=$SwiftReleaseAssetName
146+
"@ | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
147+
}
148+
}
149+
109150
- name: Install Windows SDK version ${{ inputs.windows-sdk-version }}
110151
if: steps.sanitize-input.outputs.build-os == 'windows' && inputs.windows-sdk-version != ''
111152
id: setup-windows-sdk
@@ -257,3 +298,19 @@ runs:
257298
arch: ${{ steps.sanitize-input.outputs.host-arch }}
258299
winsdk: ${{ inputs.windows-sdk-version }}
259300
toolset_version: ${{ inputs.msvc-version }}
301+
302+
- name: Setup Swift toolchain (Upstream)
303+
if: inputs.swift-version != '' && inputs.swift-repo == ''
304+
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
305+
with:
306+
branch: ${{ steps.sanitize-input.outputs.swift-branch }}
307+
tag: ${{ steps.sanitize-input.outputs.swift-tag }}
308+
309+
- name: Setup Swift toolchain (Custom)
310+
if: inputs.swift-version != '' && inputs.swift-repo != ''
311+
uses: compnerd/gha-setup-swift@6c9f2db7c3155c57fe35f160bcd5cf5859b9c1ba # main
312+
with:
313+
github-repo: ${{ inputs.swift-repo }}
314+
github-token: ${{ secrets.GITHUB_TOKEN }}
315+
release-asset-name: ${{ steps.sanitize-input.outputs.swift-release-asset }}
316+
release-tag-name: ${{ steps.sanitize-input.outputs.swift-release-tag }}

.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)