Skip to content

Commit a47701e

Browse files
committed
fix: fixed latest toolchain(> 5.6) setup failure on Windows
1 parent 86e007c commit a47701e

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ jobs:
113113
cancel-in-progress: true
114114
strategy:
115115
matrix:
116-
os: [ubuntu-latest, macos-latest, macos-13]
116+
os: [ubuntu-latest, macos-latest, windows-latest]
117117
swift: ['latest']
118118
development: [false, true]
119119
include:
120120
- os: macos-latest
121121
swift: '5.0.0'
122122
development: false
123+
- os: macos-13
124+
swift: 'latest'
125+
development: false
123126
- os: ubuntu-latest
124127
swift: '5.3.0'
125128
development: false
126-
- os: windows-latest
127-
swift: '5.6'
128-
development: false
129129
- os: windows-latest
130130
swift: '5.3'
131131
development: false

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Setup Swift
22

3-
[![GitHub Action](https://img.shields.io/github/v/tag/SwiftyLab/setup-swift?logo=github&label=GitHub)](https://badge.fury.io/gh/SwiftyLab%2Fsetup-swift)
3+
[![GitHub Action](https://img.shields.io/github/v/tag/SwiftyLab/setup-swift?logo=github&label=GitHub)](https://github.com/marketplace/actions/setup-swift-environment-for-macos-linux-and-windows)
44
[![Supports macOS, Ubuntu & Windows](https://img.shields.io/badge/platform-macOS%20%7C%20Ubuntu%20%7C%20Windows-blue?label=platform)](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources)
55
[![Swift 5.9](https://img.shields.io/badge/Swift-5.9-orange?logo=swift&logoColor=white)](https://swift.org)
66
[![CI/CD](https://github.com/SwiftyLab/setup-swift/actions/workflows/main.yml/badge.svg)](https://github.com/SwiftyLab/setup-swift/actions/workflows/main.yml)
@@ -23,7 +23,8 @@ Or use the latest development snapshots by enabling the `development` flag:
2323

2424
```yml
2525
- uses: SwiftyLab/setup-swift@latest
26-
development: true
26+
with:
27+
development: true
2728
```
2829

2930
After the environment is configured you can run swift and xcode commands using the standard [`run`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun) step:

dist/index.js

Lines changed: 24 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/installer/windows.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
4545
protected async unpack(exe: string) {
4646
core.debug(`Installing toolchain from "${exe}"`)
4747
const code = await exec(`"${exe}"`, ['-q'])
48+
if (code !== 0) {
49+
throw new Error(`Swift installer failed with exit code: "${code}"`)
50+
}
4851
const installation = path.join(process.env.SystemDrive ?? 'C:', 'Library')
4952
const toolchain = path.join(
5053
installation,
@@ -61,11 +64,20 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
6164
'SDKs',
6265
'Windows.sdk'
6366
)
64-
if (code !== 0) {
65-
throw new Error(`Swift installer failed with exit code: "${code}"`)
66-
}
67+
const runtime = path.join(
68+
process.env.SystemDrive ?? 'C:',
69+
'Program Files',
70+
'swift'
71+
)
6772
core.debug(`Toolchain installed at "${toolchain}"`)
6873
core.debug(`SDK installed at "${sdkroot}"`)
74+
try {
75+
await fs.access(runtime)
76+
await fs.cp(runtime, path.join(installation, 'swift'), {recursive: true})
77+
core.debug(`Runtime installed at "${runtime}"`)
78+
} catch (error) {
79+
core.debug('No Swift runtime installed')
80+
}
6981
return installation
7082
}
7183

@@ -90,7 +102,23 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
90102
core.exportVariable('SDKROOT', sdkroot)
91103
const swiftDev = path.join(installation, 'Swift-development', 'bin')
92104
const icu67 = path.join(installation, 'icu-67', 'usr', 'bin')
93-
for (const envPath of [swiftPath, swiftDev, icu67]) {
105+
const runtime = path.join(
106+
installation,
107+
'swift',
108+
'runtime-development',
109+
'usr',
110+
'bin'
111+
)
112+
const requirePaths = [swiftPath, swiftDev, icu67]
113+
try {
114+
await fs.access(runtime)
115+
requirePaths.push(runtime)
116+
} catch (error) {
117+
core.debug('No Swift runtime found, skipping runtime path')
118+
}
119+
120+
for (const envPath of requirePaths) {
121+
core.debug(`Adding "${envPath}" to PATH`)
94122
core.addPath(envPath)
95123
}
96124
core.debug(`Swift installed at "${swiftPath}"`)

0 commit comments

Comments
 (0)