Skip to content

Commit 3b5817d

Browse files
committed
feat: support setting up a specific msvc version
1 parent 487a882 commit 3b5817d

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"execa": "^5.1.1",
3737
"hasha": "^5.2.2",
3838
"mri": "^1.2.0",
39-
"msvc-dev-cmd": " https://github.com/ilammy/msvc-dev-cmd",
39+
"msvc-dev-cmd": " https://github.com/aminya/msvc-dev-cmd",
4040
"semver": "^7.3.5",
4141
"setup-python": "https://github.com/actions/setup-python",
4242
"untildify": "^4.0.0",

pnpm-lock.yaml

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

src/default_versions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const DefaultVersions: Record<string, string> = {
22
msvc: "2019",
3+
vcvarsall: "2019",
34
llvm: "13.0.0",
45
ninja: "1.10.2",
56
cmake: "3.22.0",

src/main.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,16 @@ export async function main(args: string[]): Promise<number> {
114114

115115
// skip if undefined
116116
if (value !== undefined) {
117-
// get the setup function
118-
const setupFunction = setups[tool]
119-
120117
// running the setup function for this tool
121118
try {
122119
let installationInfo: InstallationInfo | undefined | void
123120
if (tool === "vcvarsall") {
124-
// TODO expose the options
125121
// eslint-disable-next-line no-await-in-loop
126-
;(setupFunction as typeof setupVCVarsall)(undefined, arch, undefined, undefined, false, false)
122+
setupVCVarsall(getVersion(tool, value), undefined, arch, undefined, undefined, false, false)
127123
} else {
124+
// get the setup function
125+
const setupFunction = setups[tool]
126+
128127
// eslint-disable-next-line no-await-in-loop
129128
installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch)
130129
}

src/msvc/msvc.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { setupChocoPack } from "../utils/setup/setupChocoPack"
22
import { error } from "@actions/core"
33
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
4+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5+
// @ts-ignore
6+
import { vsversion_to_versionnumber } from "msvc-dev-cmd/lib.js"
47

5-
type MSVCVersion = "2015" | "2017" | "2019" | string
8+
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
69

710
export async function setupMSVC(
8-
version: MSVCVersion,
11+
versionGiven: MSVCVersion,
912
_setupDir: string,
1013
arch: string,
1114
sdk?: string,
@@ -15,23 +18,27 @@ export async function setupMSVC(
1518
if (process.platform !== "win32") {
1619
return
1720
}
21+
const version = vsversion_to_versionnumber(versionGiven) as string
22+
1823
let toolset: string | undefined
1924
let VCTargetsPath: string | undefined
2025
// TODO enable this code path once its bugs are fixed
2126
// https://github.com/aminya/setup-cpp/issues/1
2227
try {
23-
if (version === "2015") {
28+
if (version === "14.0") {
2429
toolset = "14.0"
2530
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
2631
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
27-
} else if (version === "2017") {
32+
} else if (version === "15.0") {
2833
toolset = "14.16"
2934
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
3035
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
31-
} else if (version === "2019") {
36+
} else if (version === "16.0") {
3237
toolset = "14.29"
3338
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
3439
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
40+
} else {
41+
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
3542
}
3643
} catch (e) {
3744
if (
@@ -43,5 +50,5 @@ export async function setupMSVC(
4350
}
4451
}
4552
// run vcvarsall.bat environment variables
46-
setupVCVarsall(VCTargetsPath, arch, toolset, sdk, uwp, spectre)
53+
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
4754
}

src/vcvarsall/vcvarsall.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { exportVariable, info } from "@actions/core"
22
import { existsSync } from "fs"
3+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4+
// @ts-ignore
5+
import { setupMSVCDevCmd } from "msvc-dev-cmd/lib.js"
36

47
function getArch(arch: string): string {
58
switch (arch) {
@@ -18,6 +21,7 @@ function getArch(arch: string): string {
1821
}
1922

2023
export function setupVCVarsall(
24+
vsversion: string,
2125
VCTargetsPath: string | undefined,
2226
arch: string,
2327
toolset: string | undefined,
@@ -30,8 +34,5 @@ export function setupVCVarsall(
3034
exportVariable("VCTargetsPath", VCTargetsPath)
3135
}
3236

33-
// lazy load the action so it is not executed
34-
// eslint-disable-next-line @typescript-eslint/no-var-requires
35-
const { setupMSVCDevCmd } = require("msvc-dev-cmd/index")
36-
setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre)
37+
setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre, vsversion)
3738
}

0 commit comments

Comments
 (0)