From ffd9b03110e1cbb6db4dd7fd314b485aa977f4b8 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Tue, 26 Sep 2023 09:56:05 +0800 Subject: [PATCH 01/10] feat: support Windows 11 SDK --- src/installer/windows/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index c14eb39..dc47da8 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -11,17 +11,18 @@ import {Installation} from './installation' export class WindowsToolchainInstaller extends VerifyingToolchainInstaller { private get vsRequirement() { - const reccommended = '10.0.17763' + const recommended = '10.0.17763' const current = os.release() - const version = semver.gte(current, reccommended) ? current : reccommended - const winsdk = semver.patch(version) + const version = semver.gte(current, recommended) ? current : recommended + const winsdkMajor = semver.gte(version, '10.0.22000') ? semver.major(version) : 11 + const winsdkMinor = semver.patch(version) const componentsStr = core.getInput('visual-studio-components') const providedComponents = componentsStr ? componentsStr.split(';') : [] return { version: '16', components: [ 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', - `Microsoft.VisualStudio.Component.Windows10SDK.${winsdk}`, + `Microsoft.VisualStudio.Component.Windows${winsdkMajor}SDK.${winsdkMinor}`, ...providedComponents ] } From 5565d3f3fc79082f2b169cdecce27f1ba92dcf61 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Tue, 26 Sep 2023 09:57:37 +0800 Subject: [PATCH 02/10] feat: update Visual Studio and Windows SDK --- src/installer/windows/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index dc47da8..765ccc9 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -11,7 +11,7 @@ import {Installation} from './installation' export class WindowsToolchainInstaller extends VerifyingToolchainInstaller { private get vsRequirement() { - const recommended = '10.0.17763' + const recommended = '10.0.19041' const current = os.release() const version = semver.gte(current, recommended) ? current : recommended const winsdkMajor = semver.gte(version, '10.0.22000') ? semver.major(version) : 11 @@ -19,7 +19,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller Date: Tue, 26 Sep 2023 10:05:00 +0800 Subject: [PATCH 03/10] fix: fixme for support file setup --- src/installer/windows/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index 765ccc9..fc1c052 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -72,6 +72,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller Date: Tue, 26 Sep 2023 14:31:34 +0800 Subject: [PATCH 04/10] fix: run linter --- src/installer/windows/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index fc1c052..b0b234f 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -14,7 +14,9 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller Date: Tue, 26 Sep 2023 14:34:02 +0800 Subject: [PATCH 05/10] fix: update test to use Visual Studio 2022 --- __tests__/installer/windows.test.ts | 6 +++--- __tests__/utils/visual_studio/setup.test.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/__tests__/installer/windows.test.ts b/__tests__/installer/windows.test.ts index b944eb3..5e21c27 100644 --- a/__tests__/installer/windows.test.ts +++ b/__tests__/installer/windows.test.ts @@ -23,15 +23,15 @@ describe('windows toolchain installation verification', () => { } const visualStudio = VisualStudio.createFromJSON({ installationPath: path.join('C:', 'Visual Studio'), - installationVersion: '16', - catalog: {productDisplayVersion: '16'}, + installationVersion: '17', + catalog: {productDisplayVersion: '17'}, properties: { setupEngineFilePath: path.join('C:', 'Visual Studio', 'setup.exe') } }) const vsEnvs = [ `UniversalCRTSdkDir=${path.join('C:', 'Windows Kits')}`, - `UCRTVersion=10.0.17063`, + `UCRTVersion=10.0.19041`, `VCToolsInstallDir=${path.join('C:', 'Visual Studio', 'Tools')}` ] diff --git a/__tests__/utils/visual_studio/setup.test.ts b/__tests__/utils/visual_studio/setup.test.ts index 2ed7f32..26e37f1 100644 --- a/__tests__/utils/visual_studio/setup.test.ts +++ b/__tests__/utils/visual_studio/setup.test.ts @@ -7,8 +7,8 @@ describe('visual studio setup validation', () => { const env = process.env const visualStudio = VisualStudio.createFromJSON({ installationPath: path.join('C:', 'Visual Studio'), - installationVersion: '16', - catalog: {productDisplayVersion: '16'}, + installationVersion: '17', + catalog: {productDisplayVersion: '17'}, properties: { setupEngineFilePath: path.join('C:', 'Visual Studio', 'setup.exe') } @@ -33,10 +33,10 @@ describe('visual studio setup validation', () => { stderr: '' }) await expect( - VisualStudio.setup({version: '16', components: ['Component']}) + VisualStudio.setup({version: '17', components: ['Component']}) ).rejects.toMatchObject( new Error( - `Unable to find any Visual Studio installation for version: 16.` + `Unable to find any Visual Studio installation for version: 17.` ) ) }) @@ -51,7 +51,7 @@ describe('visual studio setup validation', () => { stderr: '' }) await expect( - VisualStudio.setup({version: '16', components: ['Component']}) + VisualStudio.setup({version: '17', components: ['Component']}) ).resolves.toMatchObject(visualStudio) }) }) From 1d3c38fc24dc9356d8d38085cae838ba16aa70ec Mon Sep 17 00:00:00 2001 From: YR Chen Date: Tue, 26 Sep 2023 20:20:45 +0800 Subject: [PATCH 06/10] fix: Windows version judgement was accidentally inverted --- src/installer/windows/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index b0b234f..6b3ed1a 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -14,7 +14,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller Date: Wed, 27 Sep 2023 00:13:03 +0800 Subject: [PATCH 07/10] fix: revert some Visual Studio requirement changes --- __tests__/installer/windows.test.ts | 2 +- __tests__/utils/visual_studio/setup.test.ts | 6 +++--- src/installer/windows/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/installer/windows.test.ts b/__tests__/installer/windows.test.ts index 5e21c27..a731a65 100644 --- a/__tests__/installer/windows.test.ts +++ b/__tests__/installer/windows.test.ts @@ -31,7 +31,7 @@ describe('windows toolchain installation verification', () => { }) const vsEnvs = [ `UniversalCRTSdkDir=${path.join('C:', 'Windows Kits')}`, - `UCRTVersion=10.0.19041`, + `UCRTVersion=10.0.22000`, `VCToolsInstallDir=${path.join('C:', 'Visual Studio', 'Tools')}` ] diff --git a/__tests__/utils/visual_studio/setup.test.ts b/__tests__/utils/visual_studio/setup.test.ts index 26e37f1..555fbdd 100644 --- a/__tests__/utils/visual_studio/setup.test.ts +++ b/__tests__/utils/visual_studio/setup.test.ts @@ -33,10 +33,10 @@ describe('visual studio setup validation', () => { stderr: '' }) await expect( - VisualStudio.setup({version: '17', components: ['Component']}) + VisualStudio.setup({version: '16', components: ['Component']}) ).rejects.toMatchObject( new Error( - `Unable to find any Visual Studio installation for version: 17.` + `Unable to find any Visual Studio installation for version: 16.` ) ) }) @@ -51,7 +51,7 @@ describe('visual studio setup validation', () => { stderr: '' }) await expect( - VisualStudio.setup({version: '17', components: ['Component']}) + VisualStudio.setup({version: '16', components: ['Component']}) ).resolves.toMatchObject(visualStudio) }) }) diff --git a/src/installer/windows/index.ts b/src/installer/windows/index.ts index 6b3ed1a..609ccdd 100644 --- a/src/installer/windows/index.ts +++ b/src/installer/windows/index.ts @@ -21,7 +21,7 @@ export class WindowsToolchainInstaller extends VerifyingToolchainInstaller Date: Wed, 27 Sep 2023 00:13:47 +0800 Subject: [PATCH 08/10] build: update `dist/index.js` --- dist/index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index a4e5a2e..71aa44e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -467,17 +467,20 @@ const utils_1 = __nccwpck_require__(1606); const installation_1 = __nccwpck_require__(539); class WindowsToolchainInstaller extends verify_1.VerifyingToolchainInstaller { get vsRequirement() { - const reccommended = '10.0.17763'; + const recommended = '10.0.19041'; const current = os.release(); - const version = semver.gte(current, reccommended) ? current : reccommended; - const winsdk = semver.patch(version); + const version = semver.gte(current, recommended) ? current : recommended; + const winsdkMajor = semver.lt(version, '10.0.22000') + ? semver.major(version) + : 11; + const winsdkMinor = semver.patch(version); const componentsStr = core.getInput('visual-studio-components'); const providedComponents = componentsStr ? componentsStr.split(';') : []; return { version: '16', components: [ 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', - `Microsoft.VisualStudio.Component.Windows10SDK.${winsdk}`, + `Microsoft.VisualStudio.Component.Windows${winsdkMajor}SDK.${winsdkMinor}`, ...providedComponents ] }; @@ -521,11 +524,18 @@ class WindowsToolchainInstaller extends verify_1.VerifyingToolchainInstaller { const runtimePath = path.join(installation.runtime, 'usr', 'bin'); const requirePaths = [swiftPath, swiftDev, icu67, tools, runtimePath]; for (const envPath of requirePaths) { - core.debug(`Adding "${envPath}" to PATH`); - core.addPath(envPath); + try { + yield fs_1.promises.access(envPath); + core.debug(`Adding "${envPath}" to PATH`); + core.addPath(envPath); + } + catch (_a) { + core.debug(`"${envPath}" doesn't exist. Skip adding to PATH`); + } } core.debug(`Swift installed at "${swiftPath}"`); const visualStudio = yield utils_1.VisualStudio.setup(this.vsRequirement); + // FIXME(stevapple): This is no longer required for Swift 5.9+ yield visualStudio.update(installation.sdkroot); const swiftFlags = `-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows`; core.exportVariable('SWIFTFLAGS', swiftFlags); @@ -1580,7 +1590,7 @@ class Swiftorg { try { yield fs_1.promises.access(swiftorg); core.debug(`Removing existing "${swiftorg}" directory`); - yield fs_1.promises.rmdir(swiftorg, { recursive: true }); + yield fs_1.promises.rm(swiftorg, { recursive: true }); } catch (error) { core.debug(`Failed removing "${swiftorg}" with "${error}"`); @@ -1615,7 +1625,7 @@ class Swiftorg { gitArgs.push('--recursive', '--remote'); } core.debug(`Initializing submodules in "${const_1.MODULE_DIR}"`); - yield (0, exec_1.exec)('git', ['init'], { cwd: const_1.MODULE_DIR }); + yield (0, exec_1.exec)('git', ['init', '-b', 'main'], { cwd: const_1.MODULE_DIR }); core.debug(`Updating submodules in "${const_1.MODULE_DIR}" with args "${gitArgs}"`); yield (0, exec_1.exec)('git', gitArgs, { cwd: const_1.MODULE_DIR }); const swiftorg = path.join(const_1.MODULE_DIR, 'swiftorg'); From 4ea245afe6593034f437bba85e6cea924a47d163 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Wed, 27 Sep 2023 02:28:18 +0800 Subject: [PATCH 09/10] test: mock Windows 10 and 11 for SDK resolution --- __tests__/installer/windows.test.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/__tests__/installer/windows.test.ts b/__tests__/installer/windows.test.ts index a731a65..1c0123f 100644 --- a/__tests__/installer/windows.test.ts +++ b/__tests__/installer/windows.test.ts @@ -1,10 +1,10 @@ -import * as os from 'os' import * as path from 'path' import {promises as fs} from 'fs' import * as core from '@actions/core' import * as exec from '@actions/exec' import * as cache from '@actions/cache' import * as toolCache from '@actions/tool-cache' +import os from 'os' import {coerce as parseSemVer} from 'semver' import {WindowsToolchainInstaller} from '../../src/installer/windows' import {VisualStudio} from '../../src/utils/visual_studio' @@ -58,6 +58,24 @@ 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'].components).toStrictEqual([ + 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', + 'Microsoft.VisualStudio.Component.Windows10SDK.19041' + ]) + }) + + it('tests setting up on Windows 11', async () => { + jest.spyOn(os, 'release').mockReturnValue('10.0.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')) From 1ceff75b97fd56a31eaf460eca49e7c6ad8c7bc3 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Wed, 27 Sep 2023 02:32:04 +0800 Subject: [PATCH 10/10] chore: integration test for Windows Server 2019 --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1db6dae..7c2f048 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -249,6 +249,9 @@ jobs: - os: windows-latest swift: '5.3' development: false + - os: windows-2019 + swift: '5.3' + development: false steps: - name: Checkout repository