fix: use the pre-installed msvc on any windows version

This commit is contained in:
Amin Yahyaabadi 2022-02-01 20:19:46 -08:00
parent 798452a83f
commit 39a166b787
6 changed files with 47 additions and 47 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,4 @@
const DefaultVersions: Record<string, string> = { const DefaultVersions: Record<string, string> = {
msvc: "2019",
vcvarsall: "2019",
llvm: "13.0.0", llvm: "13.0.0",
clangtidy: "13.0.0", clangtidy: "13.0.0",
clangformat: "13.0.0", clangformat: "13.0.0",

View File

@ -160,11 +160,7 @@ export async function main(args: string[]): Promise<number> {
case "llvm": case "llvm":
case "clang": case "clang":
case "clang++": { case "clang++": {
const installationInfo = await setupLLVM( const installationInfo = await setupLLVM(getVersion("llvm", version), join(setupCppDir, "llvm"), arch)
getVersion("llvm", version) as string,
join(setupCppDir, "llvm"),
arch
)
successMessages.push(getSuccessMessage("llvm", installationInfo)) successMessages.push(getSuccessMessage("llvm", installationInfo))
break break
} }
@ -172,7 +168,7 @@ export async function main(args: string[]): Promise<number> {
case "mingw": case "mingw":
case "cygwin": case "cygwin":
case "msys": { 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)) successMessages.push(getSuccessMessage("gcc", installationInfo))
break break
} }
@ -183,11 +179,7 @@ export async function main(args: string[]): Promise<number> {
case "visualstudio": case "visualstudio":
case "visualcpp": case "visualcpp":
case "visualc++": { case "visualc++": {
const installationInfo = await setupMSVC( const installationInfo = setupMSVC(getVersion("msvc", version), join(setupCppDir, "msvc"), arch)
getVersion("msvc", version) as string,
join(setupCppDir, "msvc"),
arch
)
successMessages.push(getSuccessMessage("msvc", installationInfo)) successMessages.push(getSuccessMessage("msvc", installationInfo))
break break
} }

View File

@ -4,6 +4,20 @@ import { setupMSVC } from "../msvc"
jest.setTimeout(300000) jest.setTimeout(300000)
describe("setup-msvc", () => { 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 () => { it("should setup msvc 2022", async () => {
try { try {
if (process.platform !== "win32") { if (process.platform !== "win32") {

View File

@ -1,5 +1,5 @@
import { setupChocoPack } from "../utils/setup/setupChocoPack" import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { error } from "@actions/core" import { error, info } from "@actions/core"
import { setupVCVarsall } from "../vcvarsall/vcvarsall" import { setupVCVarsall } from "../vcvarsall/vcvarsall"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @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 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, versionGiven: MSVCVersion,
_setupDir: string, _setupDir: string,
arch: string, arch: string,
sdk?: string, sdk?: string,
uwp?: boolean, uwp?: boolean,
spectre?: boolean spectre?: boolean
): Promise<void> { ) {
if (process.platform !== "win32") { if (process.platform !== "win32") {
return return
} }
const version = vsversion_to_versionnumber(versionGiven) as string const version = vsversion_to_versionnumber(versionGiven) as string
// check if the given version is already installed // check if the given version is already installed
info(`Checking if MSVC ${version} is already installed`)
let installed = false let installed = false
try { try {
findVcvarsall(version) const path = findVcvarsall(version) as string
installed = true installed = true
info(`Found the pre-installed version of MSVC at ${path}`)
} catch { } catch {
// not installed, try installing // not installed, try installing
} }
@ -32,30 +34,23 @@ export async function setupMSVC(
let toolset: string | undefined let toolset: string | undefined
let VCTargetsPath: string | undefined let VCTargetsPath: string | undefined
// https://github.com/aminya/setup-cpp/issues/1 // https://github.com/aminya/setup-cpp/issues/1
if (!installed) {
try { try {
if (version === "14.0") { if (version === "14.0") {
toolset = "14.0" toolset = "14.0"
if (!installed) { setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
await setupChocoPack("visualcpp-build-tools", "14.0.25420.1", ["--ignore-dependencies"])
}
VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140" VCTargetsPath = "C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/v140"
} else if (version === "15.0") { } else if (version === "15.0") {
toolset = "14.16" toolset = "14.16"
if (!installed) { setupChocoPack("visualstudio2017buildtools", "15.9.41.0", [])
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 VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16" // TODO verify path
} else if (version === "16.0") { } else if (version === "16.0") {
toolset = "14.29" toolset = "14.29"
if (!installed) { setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
await setupChocoPack("visualstudio2019buildtools", "16.11.7.0", [])
}
VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133" VCTargetsPath = "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133"
} else if (version === "17.0") { } else if (version === "17.0") {
toolset = undefined toolset = undefined
if (!installed) { setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
await setupChocoPack("visualstudio2022buildtools", "117.0.5.0", [])
}
VCTargetsPath = undefined VCTargetsPath = undefined
} else { } else {
error(`The given MSVC versions ${versionGiven} is not supported yet.`) error(`The given MSVC versions ${versionGiven} is not supported yet.`)
@ -63,6 +58,7 @@ export async function setupMSVC(
} catch (e) { } catch (e) {
error(e as string | Error) error(e as string | Error)
} }
}
// run vcvarsall.bat environment variables // run vcvarsall.bat environment variables
setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre) setupVCVarsall(version, VCTargetsPath, arch, toolset, sdk, uwp, spectre)
} }