feat: add msvc installation

This commit is contained in:
Amin Yahyaabadi 2021-09-15 05:25:02 -05:00
parent 00e68ef657
commit b302dc3e25
11 changed files with 92 additions and 7 deletions

View File

@ -1,4 +1,4 @@
{ {
"extends": "eslint-config-atomic", "extends": "eslint-config-atomic",
"ignorePatterns": ["dist/", "node_modules/", "src/python/setup-python/"] "ignorePatterns": ["dist/", "node_modules/", "src/python/setup-python/", "src/msvc/msvc-dev-cmd/"]
} }

4
.gitmodules vendored
View File

@ -2,3 +2,7 @@
path = src/python/setup-python path = src/python/setup-python
url = https://github.com/actions/setup-python url = https://github.com/actions/setup-python
branch = main branch = main
[submodule "src/msvc/msvc-dev-cmd"]
path = src/msvc/msvc-dev-cmd
url = https://github.com/aminya/msvc-dev-cmd
branch = lib

View File

@ -5,3 +5,4 @@ CHANGELOG.md
dist dist
stats.html stats.html
src/python/setup-python/ src/python/setup-python/
src/msvc/msvc-dev-cmd/

View File

@ -20,7 +20,7 @@ The package will be usable from any environment (locally, GitHub Actions, etc).
- [x] setup meson - [x] setup meson
- [x] setup gcovr - [x] setup gcovr
- [x] setup python - [x] setup python
- [ ] setup msvc - [x] setup msvc
- [ ] setup gcc/mingw - [ ] setup gcc/mingw
- [ ] setup OpenCppCoverage - [ ] setup OpenCppCoverage
- [ ] setup cppcheck - [ ] setup cppcheck

View File

@ -9,6 +9,9 @@ inputs:
llvm: llvm:
description: "The llvm version to install" description: "The llvm version to install"
required: false required: false
msvc:
description: "The msvc version to install"
required: false
cmake: cmake:
description: "The cmake version to install." description: "The cmake version to install."
default: "3.20.2" default: "3.20.2"

View File

@ -5,6 +5,7 @@ import { setupConan } from "./conan/conan"
import { setupGcovr } from "./gcovr/gcovr" import { setupGcovr } from "./gcovr/gcovr"
import { setupLLVM } from "./llvm/llvm" import { setupLLVM } from "./llvm/llvm"
import { setupMeson } from "./meson/meson" import { setupMeson } from "./meson/meson"
import { setupMSVC } from "./msvc/msvc"
import { setupNinja } from "./ninja/ninja" import { setupNinja } from "./ninja/ninja"
import { setupPython } from "./python/python" import { setupPython } from "./python/python"
@ -67,6 +68,12 @@ export async function main(): Promise<number> {
if (chocoVersion !== undefined) { if (chocoVersion !== undefined) {
await setupChocolatey() await setupChocolatey()
} }
// setup msvc
const msvcVersion = maybeGetInput("msvc")
if (msvcVersion !== undefined) {
await setupMSVC(msvcVersion)
}
} catch (err) { } catch (err) {
core.error(err as string | Error) core.error(err as string | Error)
core.setFailed("install-cpp failed") core.setFailed("install-cpp failed")

View File

@ -0,0 +1,17 @@
import { setupMSVC } from "../msvc"
import { spawnSync as spawn } from "child_process"
jest.setTimeout(200000)
describe("setup-msvc", () => {
it("should setup msvc", async () => {
if (process.platform !== "win32") {
return
}
await setupMSVC("2017")
const { status } = spawn("cl", {
encoding: "utf8",
})
expect(status).toBe(0)
})
})

1
src/msvc/msvc-dev-cmd Submodule

@ -0,0 +1 @@
Subproject commit 082928e04f67114ec851d165f1ab48fce0b5d752

52
src/msvc/msvc.ts Normal file
View File

@ -0,0 +1,52 @@
import { setupMSVCDevCmd } from "./msvc-dev-cmd/index"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { exportVariable } from "@actions/core"
import { existsSync } from "fs"
import { arch as osArch } from "os"
type MSVCVersion = "2015" | "2017" | "2019" | string
function getArch(arch: string): string {
switch (arch) {
case "x32":
case "32":
case "ia32": {
return "x86"
}
case "64": {
return "x64"
}
default: {
return arch
}
}
}
export async function setupMSVC(
version: MSVCVersion,
sdk?: string,
uwp?: boolean,
spectre?: boolean,
arch = osArch()
): Promise<void> {
let toolset: string | undefined
if (version === "2015") {
toolset = "14.0.25420.1"
await setupChocoPack("visualcpp-build-tools", toolset, ["--ignore-dependencies", "--params", "'/IncludeRequired'"])
const VCTargetsPath = "C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\v140"
if (existsSync(VCTargetsPath)) {
exportVariable("VCTargetsPath", VCTargetsPath)
}
} else if (version === "2017") {
toolset = "15.0.26228.20170424"
await setupChocoPack("visualcpp-build-tools", toolset, ["--ignore-dependencies", "--params", "'/IncludeRequired'"])
} else if (version === "2019") {
toolset = "16.11.2.0"
await setupChocoPack("visualstudio2019buildtools", toolset, [
"--package-parameters",
"add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --passive",
])
}
setupMSVCDevCmd(getArch(arch), sdk, toolset, uwp, spectre)
}

View File

@ -6,7 +6,7 @@ import { setupChocolatey } from "../../chocolatey/chocolatey"
let hasChoco = false let hasChoco = false
/** A function that installs a package using choco */ /** A function that installs a package using choco */
export async function setupChocoPack(name: string, version?: string) { export async function setupChocoPack(name: string, version?: string, args: string[] = []) {
if (!hasChoco || which.sync("choco", { nothrow: true }) === null) { if (!hasChoco || which.sync("choco", { nothrow: true }) === null) {
await setupChocolatey() await setupChocolatey()
hasChoco = true hasChoco = true
@ -14,9 +14,9 @@ export async function setupChocoPack(name: string, version?: string) {
let exit let exit
if (version === undefined) { if (version === undefined) {
exit = await exec("choco", ["install", name]) exit = await exec("choco", ["install", name, ...args])
} else { } else {
exit = await exec("choco", ["install", name, `--version=${version}`]) exit = await exec("choco", ["install", name, `--version=${version}`, ...args])
} }
if (exit !== 0) { if (exit !== 0) {

View File

@ -28,5 +28,5 @@
}, },
"compileOnSave": false, "compileOnSave": false,
"include": ["./src"], "include": ["./src"],
"exclude": ["./src/python/setup-python"] "exclude": ["./src/python/setup-python", "src/msvc/msvc-dev-cmd/"]
} }