Skip to content

Commit 39a166b

Browse files
committed
fix: use the pre-installed msvc on any windows version
1 parent 798452a commit 39a166b

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
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.

src/default_versions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const DefaultVersions: Record<string, string> = {
2-
msvc: "2019",
3-
vcvarsall: "2019",
42
llvm: "13.0.0",
53
clangtidy: "13.0.0",
64
clangformat: "13.0.0",

src/main.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,15 @@ export async function main(args: string[]): Promise<number> {
160160
case "llvm":
161161
case "clang":
162162
case "clang++": {
163-
const installationInfo = await setupLLVM(
164-
getVersion("llvm", version) as string,
165-
join(setupCppDir, "llvm"),
166-
arch
167-
)
163+
const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
168164
successMessages.push(getSuccessMessage("llvm", installationInfo))
169165
break
170166
}
171167
case "gcc":
172168
case "mingw":
173169
case "cygwin":
174170
case "msys": {
175-
const installationInfo = await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
171+
const installationInfo = await setupGcc(getVersion("gcc", version), join(setupCppDir, "gcc"), arch)
176172
successMessages.push(getSuccessMessage("gcc", installationInfo))
177173
break
178174
}
@@ -183,11 +179,7 @@ export async function main(args: string[]): Promise<number> {
183179
case "visualstudio":
184180
case "visualcpp":
185181
case "visualc++": {
186-
const installationInfo = await setupMSVC(
187-
getVersion("msvc", version) as string,
188-
join(setupCppDir, "msvc"),
189-
arch
190-
)
182+
const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
191183
successMessages.push(getSuccessMessage("msvc", installationInfo))
192184
break
193185
}

src/msvc/__tests__/msvc.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import { setupMSVC } from "../msvc"
44

55
jest.setTimeout(300000)
66
describe("setup-msvc", () => {
7+
it("should setup the pre-installed msvc", async () => {
8+
try {
9+
if (process.platform !== "win32") {
10+
return
11+
}
12+
await setupMSVC("", "", process.arch)
13+
await testBin("cl", [])
14+
console.log(which("cl"))
15+
} catch (e) {
16+
// TODO
17+
console.error(e)
18+
}
19+
})
20+
721
it("should setup msvc 2022", async () => {
822
try {
923
if (process.platform !== "win32") {

src/msvc/msvc.ts

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,63 @@
11
import { setupChocoPack } from "../utils/setup/setupChocoPack"
2-
import { error } from "@actions/core"
2+
import { error, info } from "@actions/core"
33
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
44
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
// @ts-ignore
66
import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js"
77

88
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
99

10-
export async function setupMSVC(
10+
export function setupMSVC(
1111
versionGiven: MSVCVersion,
1212
_setupDir: string,
1313
arch: string,
1414
sdk?: string,
1515
uwp?: boolean,
1616
spectre?: boolean
17-
): Promise<void> {
17+
) {
1818
if (process.platform !== "win32") {
1919
return
2020
}
2121
const version = vsversion_to_versionnumber(versionGiven) as string
2222

2323
// check if the given version is already installed
24+
info(`Checking if MSVC ${version} is already installed`)
2425
let installed = false
2526
try {
26-
findVcvarsall(version)
27+
const path = findVcvarsall(version) as string
2728
installed = true
29+
info(`Found the pre-installed version of MSVC at ${path}`)
2830
} catch {
2931
// not installed, try installing
3032
}
3133

3234
let toolset: string | undefined
3335
let VCTargetsPath: string | undefined
3436
// https://github.com/aminya/setup-cpp/issues/1
35-
try {
36-
if (version === "14.0") {
37-
toolset = "14.0"
38-
if (!installed) {
39-
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
40-
}
41-
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
42-
} else if (version === "15.0") {
43-
toolset = "14.16"
44-
if (!installed) {
45-
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
46-
}
47-
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
48-
} else if (version === "16.0") {
49-
toolset = "14.29"
50-
if (!installed) {
51-
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
52-
}
53-
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
54-
} else if (version === "17.0") {
55-
toolset = undefined
56-
if (!installed) {
57-
await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
37+
if (!installed) {
38+
try {
39+
if (version === "14.0") {
40+
toolset = "14.0"
41+
setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
42+
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
43+
} else if (version === "15.0") {
44+
toolset = "14.16"
45+
setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
46+
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
47+
} else if (version === "16.0") {
48+
toolset = "14.29"
49+
setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
50+
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
51+
} else if (version === "17.0") {
52+
toolset = undefined
53+
setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
54+
VCTargetsPath = undefined
55+
} else {
56+
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
5857
}
59-
VCTargetsPath = undefined
60-
} else {
61-
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
58+
} catch (e) {
59+
error(e as string | Error)
6260
}
63-
} catch (e) {
64-
error(e as string | Error)
6561
}
6662
// run vcvarsall.bat environment variables
6763
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)

0 commit comments

Comments
 (0)