Merge pull request #25 from aminya/vs2022 [skip ci]

This commit is contained in:
Amin Yahyaabadi 2022-02-01 21:16:11 -08:00 committed by GitHub
commit c56c0d924a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 57 deletions

View File

@ -15,6 +15,7 @@ jobs:
fail-fast: false
matrix:
os:
- windows-2022
- windows-2019
- ubuntu-20.04
- macos-10.15

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> = {
msvc: "2019",
vcvarsall: "2019",
llvm: "13.0.0",
clangtidy: "13.0.0",
clangformat: "13.0.0",

View File

@ -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
}

View File

@ -1,45 +1,67 @@
import which from "which"
import { testBin } from "../../utils/tests/test-helpers"
import { setupMSVC } from "../msvc"
jest.setTimeout(300000)
describe("setup-msvc", () => {
it("should setup msvc 2019", async () => {
it("should setup the pre-installed msvc", () => {
try {
if (process.platform !== "win32") {
return
}
await setupMSVC("2019", "", process.arch)
await testBin("cl", [])
console.log(which("cl"))
setupMSVC("", "", process.arch)
console.log(which.sync("cl"))
} catch (e) {
// TODO
console.error(e)
}
})
it("should setup msvc 2017", async () => {
it("should setup msvc 2022", () => {
try {
if (process.platform !== "win32") {
return
}
await setupMSVC("2017", "", process.arch)
await testBin("cl", [])
console.log(which("cl"))
setupMSVC("2022", "", process.arch)
console.log(which.sync("cl"))
} catch (e) {
// TODO
console.error(e)
}
})
it("should setup msvc 2015", async () => {
it("should setup msvc 2019", () => {
try {
if (process.platform !== "win32") {
return
}
await setupMSVC("2015", "", process.arch)
await testBin("cl", [])
console.log(which("cl"))
setupMSVC("2019", "", process.arch)
console.log(which.sync("cl"))
} catch (e) {
// TODO
console.error(e)
}
})
it("should setup msvc 2017", () => {
try {
if (process.platform !== "win32") {
return
}
setupMSVC("2017", "", process.arch)
console.log(which.sync("cl"))
} catch (e) {
// TODO
console.error(e)
}
})
it("should setup msvc 2015", () => {
try {
if (process.platform !== "win32") {
return
}
setupMSVC("2015", "", process.arch)
console.log(which.sync("cl"))
} catch (e) {
// TODO
console.error(e)

View File

@ -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,30 +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 {
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)

View File

@ -23,9 +23,13 @@ export function setupChocoPack(name: string, version?: string, args: string[] =
env.PATH = PATH
if (version !== undefined && version !== "") {
execa.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], { env, extendEnv: false })
execa.sync("choco", ["install", "-y", name, `--version=${version}`, ...args], {
env,
extendEnv: false,
stdio: "inherit",
})
} else {
execa.sync("choco", ["install", "-y", name, ...args], { env, extendEnv: false })
execa.sync("choco", ["install", "-y", name, ...args], { env, extendEnv: false, stdio: "inherit" })
}
const binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`

View File

@ -26,7 +26,9 @@ export async function setupPipPack(name: string, version?: string) {
}
}
execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name])
execa.sync(pip, ["install", version !== undefined && version !== "" ? `${name}==${version}` : name], {
stdio: "inherit",
})
if (binDir === undefined) {
if (process.platform === "linux") {