feat: support gcc/mingw

This commit is contained in:
Amin Yahyaabadi 2021-09-16 09:03:54 -05:00
parent cf3dbb2b16
commit 39993729df
6 changed files with 90 additions and 22 deletions

View File

@ -13,15 +13,16 @@ The package will be usable from any environment (locally, GitHub Actions, etc).
# Features (WIP)
- setup llvm
- setup gcc/mingw
- setup cmake
- setup ninja
- setup llvm
- setup conan
- setup meson
- setup gcovr
- setup conan
- setup ccache
- setup cppcheck
- setup doxygen
- setup ccache
- setup gcovr
- setup OpenCppCoverage
- setup python
- setup choco
@ -33,5 +34,4 @@ The package will be usable from any environment (locally, GitHub Actions, etc).
### TODO
- [ ] setup gcc/mingw
- [ ] setup vcpkg

View File

@ -12,6 +12,9 @@ inputs:
llvm:
description: "The llvm version to install"
required: false
gcc:
description: "The gcc version to install"
required: false
msvc:
description: "The msvc version to install"
required: false

View File

@ -0,0 +1,14 @@
import { spawnSync as spawn } from "child_process"
import { setupGcc } from "../gcc"
jest.setTimeout(200000)
describe("setup-gcc", () => {
it("should setup gcc", async () => {
await setupGcc("", "", "")
const { status } = spawn("gcc", {
encoding: "utf8",
})
expect(status).toBe(0)
})
})

36
src/gcc/gcc.ts Normal file
View File

@ -0,0 +1,36 @@
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupGcc(version: string, _setupCppDir: string, arch: string) {
switch (process.platform) {
case "win32": {
if (arch === "arm" || arch === "arm64") {
return setupChocoPack("gcc-arm-embedded", version)
}
return setupChocoPack("mingw", version)
}
case "darwin": {
return setupBrewPack("gcc", version)
}
case "linux": {
if (arch === "x64") {
return setupAptPack("g++", version, "ppa:ubuntu-toolchain-r/test")
}
return setupAptPack("g++-multilib", version, "ppa:ubuntu-toolchain-r/test")
}
// TODO support bare-metal
// TODO support abi
// case "none": {
// if (arch === "arm" || arch === "arm64") {
// return setupAptPack("gcc-arm-none-eabi", version, "ppa:ubuntu-toolchain-r/test")
// } else {
// throw new Error(`Unsupported platform for ${arch}`)
// }
// }
default: {
throw new Error(`Unsupported platform for ${arch}`)
}
}
}

View File

@ -233,10 +233,11 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupLLVM(
version: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_setupCppDir: string | undefined,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_arch: string
): Promise<InstallationInfo> {
let directory = _setupCppDir

View File

@ -17,6 +17,26 @@ import { setupPython } from "./python/python"
import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions"
import { InstallationInfo } from "./utils/setup/setupBin"
import { setupGcc } from "./gcc/gcc"
import { assert } from "console"
const tools = [
"cmake",
"ninja",
"python",
"conan",
"meson",
"gcovr",
"opencppcoverage",
"llvm",
"gcc",
"choco",
"brew",
"ccache",
"doxygen",
"cppcheck",
"msvc",
]
const setups = {
cmake: setupCmake,
@ -27,6 +47,7 @@ const setups = {
gcovr: setupGcovr,
opencppcoverage: setupOpencppcoverage,
llvm: setupLLVM,
gcc: setupGcc,
choco: setupChocolatey,
brew: setupBrew,
ccache: setupCcache,
@ -75,6 +96,13 @@ export async function main(): Promise<number> {
await setupLLVM(getVersion("llvm", version) as string, setupCppDir, arch)
break
}
case "gcc":
case "mingw":
case "cygwin":
case "msys": {
await setupGcc(getVersion("gcc", version) as string, setupCppDir, arch)
break
}
case "cl":
case "msvc":
case "msbuild":
@ -91,22 +119,8 @@ export async function main(): Promise<number> {
}
}
for (const tool of [
"cmake",
"ninja",
"python",
"conan",
"meson",
"gcovr",
"opencppcoverage",
"llvm",
"choco",
"brew",
"ccache",
"doxygen",
"cppcheck",
"msvc",
]) {
for (const tool of tools) {
assert(tool in setups)
const version = maybeGetInput(tool)
if (version !== undefined) {
const setupFunction = setups[tool]