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
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ jobs:
uses: `${repo}@${branch}`,
with: {
'swift-version': 'latest',
'check-latest': '${{ needs.ci.outputs.check_latest }}'
'check-latest': '${{ needs.ci.outputs.check_latest }}',
'visual-studio-components': 'Microsoft.VisualStudio.Component.Windows11SDK.22621'
}
}
]
Expand Down
29 changes: 24 additions & 5 deletions __tests__/installer/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ describe('windows toolchain installation verification', () => {
catalog: {productDisplayVersion: '17'},
properties: {
setupEngineFilePath: path.join('C:', 'Visual Studio', 'setup.exe')
}
},
components: [
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.Windows11SDK.22621'
]
})
const vsEnvs = [
`UniversalCRTSdkDir=${path.join('C:', 'Windows Kits')}`,
Expand All @@ -46,16 +50,19 @@ describe('windows toolchain installation verification', () => {
})

it('tests adding additional components', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.17063')
jest
.spyOn(core, 'getInput')
.mockReturnValue(
'Microsoft.VisualStudio.Component.VC.ATL;Microsoft.VisualStudio.Component.VC.CMake.Project;Microsoft.VisualStudio.Component.Windows10SDK'
)
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement'].components.slice(2)).toStrictEqual([
expect(installer['vsRequirement'].components).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.VC.ATL',
'Microsoft.VisualStudio.Component.VC.CMake.Project',
'Microsoft.VisualStudio.Component.Windows10SDK'
'Microsoft.VisualStudio.Component.Windows10SDK',
'Microsoft.VisualStudio.Component.Windows10SDK.17763'
])
})

Expand All @@ -77,6 +84,18 @@ describe('windows toolchain installation verification', () => {
])
})

it('tests setting up on Windows 11 with custom SDK', async () => {
jest.spyOn(os, 'release').mockReturnValue('10.0.26100')
jest
.spyOn(core, 'getInput')
.mockReturnValue('Microsoft.VisualStudio.Component.Windows11SDK.22621')
const installer = new WindowsToolchainInstaller(toolchain)
expect(installer['vsRequirement'].components).toStrictEqual([
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'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 Expand Up @@ -181,7 +200,7 @@ describe('windows toolchain installation verification', () => {
.mockResolvedValue()
await installer['add']('')
expect(setupSpy).toHaveBeenCalled()
expect(updateSpy).toHaveBeenCalledWith('root', true)
expect(updateSpy).toHaveBeenCalledWith('root')
})

it('tests unpack for failed path matching without additional module setup', async () => {
Expand Down Expand Up @@ -231,7 +250,7 @@ describe('windows toolchain installation verification', () => {
.mockResolvedValue()
await installer['add']('')
expect(setupSpy).toHaveBeenCalled()
expect(updateSpy).toHaveBeenCalledWith('root', false)
expect(updateSpy).toHaveBeenCalledWith('root')
})

it('tests add to PATH', async () => {
Expand Down
39 changes: 36 additions & 3 deletions __tests__/utils/visual_studio/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path'
import {promises as fs} from 'fs'
import os from 'os'
import * as exec from '@actions/exec'
import {VisualStudio} from '../../../src/utils/visual_studio'

Expand All @@ -11,7 +12,11 @@ describe('visual studio setup validation', () => {
catalog: {productDisplayVersion: '17'},
properties: {
setupEngineFilePath: path.join('C:', 'Visual Studio', 'setup.exe')
}
},
components: [
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
'Microsoft.VisualStudio.Component.Windows11SDK.22621'
]
})

beforeEach(() => {
Expand All @@ -33,7 +38,7 @@ describe('visual studio setup validation', () => {
stderr: ''
})
await expect(
VisualStudio.setup({version: '16', components: ['Component']})
VisualStudio.setup({version: '16', components: visualStudio.components})
).rejects.toMatchObject(
new Error(
`Unable to find any Visual Studio installation for version: 16.`
Expand All @@ -51,7 +56,35 @@ describe('visual studio setup validation', () => {
stderr: ''
})
await expect(
VisualStudio.setup({version: '16', components: ['Component']})
VisualStudio.setup({version: '16', components: visualStudio.components})
).resolves.toMatchObject(visualStudio)
})

it('tests visual studio environment setup', async () => {
jest.spyOn(os, 'arch').mockReturnValue('x64')
const execSpy = jest.spyOn(exec, 'getExecOutput').mockResolvedValue({
exitCode: 0,
stdout: '',
stderr: ''
})
await visualStudio.env()
const arg = execSpy.mock.calls.at(0)
expect(arg).toBeTruthy()
expect(arg?.[0]).toBe('cmd')
expect(arg?.[1]).toStrictEqual([
'/k',
path.join(
visualStudio.installationPath,
'Common7',
'Tools',
'VsDevCmd.bat'
),
'-arch=x64',
'-winsdk=10.0.22621.0',
'&&',
'set',
'&&',
'exit'
])
})
})
50 changes: 36 additions & 14 deletions dist/index.js

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

26 changes: 16 additions & 10 deletions src/installer/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as core from '@actions/core'
import * as semver from 'semver'
import {VerifyingToolchainInstaller} from '../verify'
import {WindowsToolchainSnapshot} from '../../snapshot'
import {VisualStudio} from '../../utils'
import {VisualStudio, VISUAL_STUDIO_WINSDK_COMPONENT_REGEX} from '../../utils'
import {Installation, CustomInstallation} from './installation'

export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<WindowsToolchainSnapshot> {
Expand All @@ -22,14 +22,23 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
private get vsRequirement() {
const componentsStr = core.getInput('visual-studio-components')
const providedComponents = componentsStr ? componentsStr.split(';') : []
const winsdkComponent = providedComponents.find(component => {
return (
(VISUAL_STUDIO_WINSDK_COMPONENT_REGEX.exec(component)?.length ?? 0) > 1
)
})

const vsComponents = [
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
...providedComponents
]
if (!winsdkComponent) {
vsComponents.push(this.winsdk)
}
return {
version: '16',
swift: this.version,
components: [
'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
this.winsdk,
...providedComponents
]
components: vsComponents
}
}

Expand Down Expand Up @@ -89,10 +98,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller<Windo
}

const visualStudio = await VisualStudio.setup(this.vsRequirement)
await visualStudio.update(
sdkroot,
!this.version || semver.lt(this.version, '6.0.0')
)
await visualStudio.update(sdkroot)
const swiftFlags = [
'-sdk',
sdkroot,
Expand Down
24 changes: 22 additions & 2 deletions src/utils/visual_studio/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import * as os from 'os'
import * as path from 'path'
import {getExecOutput} from '@actions/exec'

export const VISUAL_STUDIO_WINSDK_COMPONENT_REGEX =
/Microsoft\.VisualStudio\.Component\.Windows[0-9]+SDK\.([0-9]+)/

export class VisualStudio {
private constructor(
readonly installationPath: string,
readonly installationVersion: string,
readonly catalog: VisualStudioCatalog,
readonly properties: VisualStudioProperties
readonly properties: VisualStudioProperties,
readonly components: string[]
) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -16,7 +20,8 @@ export class VisualStudio {
json.installationPath,
json.installationVersion,
json.catalog,
json.properties
json.properties,
json.components
)
}

Expand All @@ -28,12 +33,27 @@ export class VisualStudio {
'Tools',
'VsDevCmd.bat'
)

const args = []
const sdkComponentMatch = this.components
.map(component => {
return VISUAL_STUDIO_WINSDK_COMPONENT_REGEX.exec(component)
})
.filter(match => {
return match && match.length > 1
})
.at(0)
if (sdkComponentMatch) {
args.push(`-winsdk=10.0.${sdkComponentMatch[1]}.0`)
}

const {stdout} = await getExecOutput(
'cmd',
[
'/k',
nativeToolsScriptx86,
`-arch=${os.arch()}`,
...args,
'&&',
'set',
'&&',
Expand Down
5 changes: 4 additions & 1 deletion src/utils/visual_studio/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ VisualStudio.setup = async function (requirement: VisualStudioRequirement) {
'-version',
requirement.version
])
const vs = VisualStudio.createFromJSON(JSON.parse(stdout)[0])
const vs = VisualStudio.createFromJSON({
...JSON.parse(stdout)[0],
components: requirement.components
})
if (!vs.installationPath) {
throw new Error(
`Unable to find any Visual Studio installation for version: ${requirement.version}.`
Expand Down
Loading
Loading