diff --git a/README.md b/README.md index 503345fb..1f21a351 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 5e0e2f37..ec248730 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/src/gcc/__tests__/gcc.test.ts b/src/gcc/__tests__/gcc.test.ts new file mode 100644 index 00000000..4da3e32c --- /dev/null +++ b/src/gcc/__tests__/gcc.test.ts @@ -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) + }) +}) diff --git a/src/gcc/gcc.ts b/src/gcc/gcc.ts new file mode 100644 index 00000000..afcf5f7d --- /dev/null +++ b/src/gcc/gcc.ts @@ -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}`) + } + } +} diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index 57cac8ff..9cd07b27 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -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 { let directory = _setupCppDir diff --git a/src/main.ts b/src/main.ts index b9a82f66..e13c7b8b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { 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 { } } - 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]