Skip to content

Commit 062b5b1

Browse files
committed
setup-build: Support Swift toolchain installation
1 parent d4dd221 commit 062b5b1

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
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/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)