mirror of https://github.com/aminya/setup-cpp
fix: use the pre-installed msvc on any windows version
This commit is contained in:
parent
798452a83f
commit
39a166b787
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,4 @@
|
|||
const DefaultVersions: Record<string, string> = {
|
||||
msvc: "2019",
|
||||
vcvarsall: "2019",
|
||||
llvm: "13.0.0",
|
||||
clangtidy: "13.0.0",
|
||||
clangformat: "13.0.0",
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -160,11 +160,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "llvm":
|
||||
case "clang":
|
||||
case "clang++": {
|
||||
const installationInfo = await setupLLVM(
|
||||
getVersion("llvm", version) as string,
|
||||
join(setupCppDir, "llvm"),
|
||||
arch
|
||||
)
|
||||
const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
|
||||
successMessages.push(getSuccessMessage("llvm", installationInfo))
|
||||
break
|
||||
}
|
||||
|
@ -172,7 +168,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "mingw":
|
||||
case "cygwin":
|
||||
case "msys": {
|
||||
const installationInfo = await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
|
||||
const installationInfo = await setupGcc(getVersion("gcc", version), join(setupCppDir, "gcc"), arch)
|
||||
successMessages.push(getSuccessMessage("gcc", installationInfo))
|
||||
break
|
||||
}
|
||||
|
@ -183,11 +179,7 @@ export async function main(args: string[]): Promise<number> {
|
|||
case "visualstudio":
|
||||
case "visualcpp":
|
||||
case "visualc++": {
|
||||
const installationInfo = await setupMSVC(
|
||||
getVersion("msvc", version) as string,
|
||||
join(setupCppDir, "msvc"),
|
||||
arch
|
||||
)
|
||||
const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
|
||||
successMessages.push(getSuccessMessage("msvc", installationInfo))
|
||||
break
|
||||
}
|
||||
|
|
|
@ -4,6 +4,20 @@ import { setupMSVC } from "../msvc"
|
|||
|
||||
jest.setTimeout(300000)
|
||||
describe("setup-msvc", () => {
|
||||
it("should setup the pre-installed msvc", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
await setupMSVC("", "", process.arch)
|
||||
await testBin("cl", [])
|
||||
console.log(which("cl"))
|
||||
} catch (e) {
|
||||
// TODO
|
||||
console.error(e)
|
||||
}
|
||||
})
|
||||
|
||||
it("should setup msvc 2022", async () => {
|
||||
try {
|
||||
if (process.platform !== "win32") {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
||||
import { error } from "@actions/core"
|
||||
import { error, info } from "@actions/core"
|
||||
import { setupVCVarsall } from "../vcvarsall/vcvarsall"
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
|
@ -7,24 +7,26 @@ import { vsversion_to_versionnumber, findVcvarsall } from "msvc-dev-cmd/lib.js"
|
|||
|
||||
type MSVCVersion = "2022" | "17.0" | "2019" | "16.0" | "2017" | "15.0" | "2015" | "14.0" | "2013" | "12.0" | string
|
||||
|
||||
export async function setupMSVC(
|
||||
export function setupMSVC(
|
||||
versionGiven: MSVCVersion,
|
||||
_setupDir: string,
|
||||
arch: string,
|
||||
sdk?: string,
|
||||
uwp?: boolean,
|
||||
spectre?: boolean
|
||||
): Promise<void> {
|
||||
) {
|
||||
if (process.platform !== "win32") {
|
||||
return
|
||||
}
|
||||
const version = vsversion_to_versionnumber(versionGiven) as string
|
||||
|
||||
// check if the given version is already installed
|
||||
info(`Checking if MSVC ${version} is already installed`)
|
||||
let installed = false
|
||||
try {
|
||||
findVcvarsall(version)
|
||||
const path = findVcvarsall(version) as string
|
||||
installed = true
|
||||
info(`Found the pre-installed version of MSVC at ${path}`)
|
||||
} catch {
|
||||
// not installed, try installing
|
||||
}
|
||||
|
@ -32,36 +34,30 @@ export async function setupMSVC(
|
|||
let toolset: string | undefined
|
||||
let VCTargetsPath: string | undefined
|
||||
// https://github.com/aminya/setup-cpp/issues/1
|
||||
try {
|
||||
if (version === "14.0") {
|
||||
toolset = "14.0"
|
||||
if (!installed) {
|
||||
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
|
||||
if (!installed) {
|
||||
try {
|
||||
if (version === "14.0") {
|
||||
toolset = "14.0"
|
||||
setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
|
||||
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
|
||||
} else if (version === "15.0") {
|
||||
toolset = "14.16"
|
||||
setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
|
||||
} else if (version === "16.0") {
|
||||
toolset = "14.29"
|
||||
setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
|
||||
} else if (version === "17.0") {
|
||||
toolset = undefined
|
||||
setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
|
||||
VCTargetsPath = undefined
|
||||
} else {
|
||||
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
|
||||
}
|
||||
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
|
||||
} else if (version === "15.0") {
|
||||
toolset = "14.16"
|
||||
if (!installed) {
|
||||
await setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
|
||||
}
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
|
||||
} else if (version === "16.0") {
|
||||
toolset = "14.29"
|
||||
if (!installed) {
|
||||
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
|
||||
}
|
||||
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
|
||||
} else if (version === "17.0") {
|
||||
toolset = undefined
|
||||
if (!installed) {
|
||||
await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
|
||||
}
|
||||
VCTargetsPath = undefined
|
||||
} else {
|
||||
error(`The given MSVC versions ${versionGiven} is not supported yet.`)
|
||||
} catch (e) {
|
||||
error(e as string | Error)
|
||||
}
|
||||
} catch (e) {
|
||||
error(e as string | Error)
|
||||
}
|
||||
// run vcvarsall.bat environment variables
|
||||
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
|
||||
|
|
Loading…
Reference in New Issue