Skip to content

Commit

Permalink
Merge pull request #25 from aminya/vs2022 [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Feb 2, 2022
2 parents 61a3c6c + bb2e50e commit c56c0d9
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 57 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
fail-fast: false
matrix:
os:
- windows-2022
- windows-2019
- ubuntu-20.04
- macos-10.15
Expand Down
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/default_versions.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 3 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,15 @@ 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
}
case "gcc":
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
}
Expand All @@ -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
}
Expand Down
48 changes: 35 additions & 13 deletions src/msvc/__tests__/msvc.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
54 changes: 28 additions & 26 deletions src/msvc/msvc.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,63 @@
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
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
}

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"])
}
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", [])
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)/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)
Expand Down
8 changes: 6 additions & 2 deletions src/utils/setup/setupChocoPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 3 additions & 1 deletion src/utils/setup/setupPipPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit c56c0d9

Please sign in to comment.