Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ jobs:
with: {
'swift-version': 'latest',
'check-latest': '${{ needs.ci.outputs.check_latest }}',
'visual-studio-components': 'Microsoft.VisualStudio.Component.Windows11SDK.22000'
'visual-studio-components': '${{ matrix.os }}'.includes('arm') ? 'Microsoft.VisualStudio.Component.Windows11SDK.22000' : ''
}
}
]
Expand Down
57 changes: 50 additions & 7 deletions __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path'
import {promises as fs} from 'fs'
import {Dirent, promises as fs} from 'fs'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as cache from '@actions/cache'
Expand Down Expand Up @@ -57,7 +57,9 @@ describe('windows toolchain installation verification', () => {
'Microsoft.VisualStudio.Component.VC.ATL;Microsoft.VisualStudio.Component.VC.CMake.Project;Microsoft.VisualStudio.Component.Windows10SDK'
)
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('x86_64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('x86_64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.VC.ATL',
'Microsoft.VisualStudio.Component.VC.CMake.Project',
Expand All @@ -69,7 +71,9 @@ describe('windows toolchain installation verification', () => {
it('tests setting up on Windows 10', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.17063')
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('x86_64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('x86_64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.Windows10SDK.17763'
])
Expand All @@ -78,7 +82,9 @@ describe('windows toolchain installation verification', () => {
it('tests setting up on ARM64 Windows 10', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.17063')
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('arm64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('arm64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.ARM64',
'Microsoft.VisualStudio.Component.Windows10SDK.17763'
])
Expand All @@ -87,7 +93,9 @@ describe('windows toolchain installation verification', () => {
it('tests setting up on Windows 11', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.22621')
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('x86_64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('x86_64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.Windows11SDK.22621'
])
Expand All @@ -99,7 +107,9 @@ describe('windows toolchain installation verification', () => {
.spyOn(core, 'getInput')
.mockReturnValue('Microsoft.VisualStudio.Component.Windows11SDK.22621')
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('x86_64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('x86_64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.Windows11SDK.22621'
])
Expand All @@ -118,12 +128,45 @@ describe('windows toolchain installation verification', () => {
preventCaching: false
}
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement']('arm64').components).toStrictEqual([
expect(
(await installer['vsRequirement']('arm64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.ARM64',
'Microsoft.VisualStudio.Component.Windows11SDK.22000'
])
})

it('tests setting up on Windows 10 with Windows 11 SDK with unavailable recommended SDK', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.17063')
jest.spyOn(fs, 'readdir').mockResolvedValue([
{
name: 'wdf',
isDirectory: () => true
} as unknown as Dirent,
{
name: '10.0.22621.0',
isDirectory: () => true
} as unknown as Dirent
])
const toolchain = {
name: 'Windows 10 Swift Development Snapshot',
date: new Date('2025-04-03 10:10:00-06:00'),
download: 'swift-DEVELOPMENT-SNAPSHOT-2025-04-03-a-windows10.exe',
dir: 'swift-DEVELOPMENT-SNAPSHOT-2025-04-03-a',
platform: 'windows10',
branch: 'development',
windows: true,
preventCaching: false
}
const installer = new WindowsToolchainInstaller(toolchain)
expect(
(await installer['vsRequirement']('arm64')).components
).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.ARM64',
'Microsoft.VisualStudio.Component.Windows11SDK.22621'
])
})

it('tests download without caching', async () => {
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['version']).toStrictEqual(parseSemVer('5.8'))
Expand Down
104 changes: 91 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"ci"
],
"scripts": {
"prepare": "npm run build && node -e \"require('./.github/utils/update_metadata').fetch()\"",
"prepare": "node -e \"require('./.github/utils/update_metadata').fetch()\" && npm run build",
"build": "tsc",
"format": "prettier --write \"**/*.ts\"",
"lint": "depcheck --ignores ts-node,ts-jest,globals,@eslint/js,@eslint/eslintrc && eslint src/**/*.ts && prettier --check \"**/*.ts\"",
Expand Down
38 changes: 32 additions & 6 deletions src/installer/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,46 @@ import * as semver from 'semver'
import {VerifyingToolchainInstaller} from '../verify'
import {WindowsToolchainSnapshot} from '../../snapshot'
import {VisualStudio, VISUAL_STUDIO_WINSDK_COMPONENT_REGEX} from '../../utils'
import {program86} from '../../utils/windows'
import {Installation, CustomInstallation} from './installation'

export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<WindowsToolchainSnapshot> {
private get winsdk() {
private async winsdk() {
const win11Semver = '10.0.22000'
const recommended = semver.gte(this.version ?? '6.2.0', '6.2.0')
? win11Semver
: '10.0.17763'
const current = os.release()
const version = semver.gte(current, recommended) ? current : recommended
let version = semver.gte(current, recommended) ? current : recommended
const insatlled = await this.insatlledSdks()
if (insatlled.length && !insatlled.includes(version)) {
version = insatlled[0]
}

const major = semver.lt(version, win11Semver) ? semver.major(version) : 11
const minor = semver.patch(version)
return `Microsoft.VisualStudio.Component.Windows${major}SDK.${minor}`
}

private vsRequirement(arch: string) {
private async insatlledSdks() {
const sdksPath = path.join(program86(), 'Windows Kits', '10', 'Include')
try {
const dirs = await fs.readdir(sdksPath, {withFileTypes: true})
return dirs
.filter(dirent => dirent.isDirectory())
.map(dirent => {
const parts = dirent.name.split('.')
return parts.length >= 3 ? parts.slice(0, 3).join('.') : dirent.name
})
.filter(version => semver.valid(version))
.sort(semver.rcompare)
} catch (error) {
core.warning(`Unable to get installed SDKs due to: "${error}"`)
return []
}
}

private async vsRequirement(arch: string) {
const componentsStr = core.getInput('visual-studio-components')
const providedComponents = componentsStr ? componentsStr.split(';') : []
const winsdkComponent = providedComponents.find(component => {
Expand All @@ -47,7 +71,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
...providedComponents
]
if (!winsdkComponent) {
vsComponents.push(this.winsdk)
vsComponents.push(await this.winsdk())
}
return {
version: '16',
Expand All @@ -61,7 +85,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
`Using VS requirement ${JSON.stringify(this.vsRequirement(arch))}`
)
const [, toolchain] = await Promise.all([
VisualStudio.setup(this.vsRequirement(arch)),
VisualStudio.setup(await this.vsRequirement(arch)),
super.download(arch)
])
const exeFile = `${toolchain}.exe`
Expand Down Expand Up @@ -114,7 +138,9 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
return
}

const visualStudio = await VisualStudio.setup(this.vsRequirement(arch))
const visualStudio = await VisualStudio.setup(
await this.vsRequirement(arch)
)
await visualStudio.update(sdkroot)
const swiftFlags = [
'-sdk',
Expand Down
Loading
Loading