mirror of https://github.com/aminya/setup-cpp
feat: add msvc installation
This commit is contained in:
parent
00e68ef657
commit
b302dc3e25
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"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/"]
|
||||
}
|
||||
|
|
|
@ -2,3 +2,7 @@
|
|||
path = src/python/setup-python
|
||||
url = https://github.com/actions/setup-python
|
||||
branch = main
|
||||
[submodule "src/msvc/msvc-dev-cmd"]
|
||||
path = src/msvc/msvc-dev-cmd
|
||||
url = https://github.com/aminya/msvc-dev-cmd
|
||||
branch = lib
|
||||
|
|
|
@ -4,4 +4,5 @@ package-lock.json
|
|||
CHANGELOG.md
|
||||
dist
|
||||
stats.html
|
||||
src/python/setup-python/
|
||||
src/python/setup-python/
|
||||
src/msvc/msvc-dev-cmd/
|
||||
|
|
|
@ -20,7 +20,7 @@ The package will be usable from any environment (locally, GitHub Actions, etc).
|
|||
- [x] setup meson
|
||||
- [x] setup gcovr
|
||||
- [x] setup python
|
||||
- [ ] setup msvc
|
||||
- [x] setup msvc
|
||||
- [ ] setup gcc/mingw
|
||||
- [ ] setup OpenCppCoverage
|
||||
- [ ] setup cppcheck
|
||||
|
|
|
@ -9,6 +9,9 @@ inputs:
|
|||
llvm:
|
||||
description: "The llvm version to install"
|
||||
required: false
|
||||
msvc:
|
||||
description: "The msvc version to install"
|
||||
required: false
|
||||
cmake:
|
||||
description: "The cmake version to install."
|
||||
default: "3.20.2"
|
||||
|
|
|
@ -5,6 +5,7 @@ import { setupConan } from "./conan/conan"
|
|||
import { setupGcovr } from "./gcovr/gcovr"
|
||||
import { setupLLVM } from "./llvm/llvm"
|
||||
import { setupMeson } from "./meson/meson"
|
||||
import { setupMSVC } from "./msvc/msvc"
|
||||
import { setupNinja } from "./ninja/ninja"
|
||||
import { setupPython } from "./python/python"
|
||||
|
||||
|
@ -67,6 +68,12 @@ export async function main(): Promise<number> {
|
|||
if (chocoVersion !== undefined) {
|
||||
await setupChocolatey()
|
||||
}
|
||||
|
||||
// setup msvc
|
||||
const msvcVersion = maybeGetInput("msvc")
|
||||
if (msvcVersion !== undefined) {
|
||||
await setupMSVC(msvcVersion)
|
||||
}
|
||||
} catch (err) {
|
||||
core.error(err as string | Error)
|
||||
core.setFailed("install-cpp failed")
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 082928e04f67114ec851d165f1ab48fce0b5d752
|
|
@ -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)
|
||||
}
|
|
@ -6,7 +6,7 @@ import { setupChocolatey } from "../../chocolatey/chocolatey"
|
|||
let hasChoco = false
|
||||
|
||||
/** 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) {
|
||||
await setupChocolatey()
|
||||
hasChoco = true
|
||||
|
@ -14,9 +14,9 @@ export async function setupChocoPack(name: string, version?: string) {
|
|||
|
||||
let exit
|
||||
if (version === undefined) {
|
||||
exit = await exec("choco", ["install", name])
|
||||
exit = await exec("choco", ["install", name, ...args])
|
||||
} else {
|
||||
exit = await exec("choco", ["install", name, `--version=${version}`])
|
||||
exit = await exec("choco", ["install", name, `--version=${version}`, ...args])
|
||||
}
|
||||
|
||||
if (exit !== 0) {
|
||||
|
|
|
@ -28,5 +28,5 @@
|
|||
},
|
||||
"compileOnSave": false,
|
||||
"include": ["./src"],
|
||||
"exclude": ["./src/python/setup-python"]
|
||||
"exclude": ["./src/python/setup-python", "src/msvc/msvc-dev-cmd/"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue