setup-cpp/src/gcc/gcc.ts

86 lines
3.1 KiB
TypeScript
Raw Normal View History

2021-09-18 10:17:21 +08:00
import { exportVariable, info } from "@actions/core"
import { addPath } from "../utils/path/addPath"
2021-09-17 04:13:55 +08:00
import { existsSync } from "fs"
2021-09-16 22:03:54 +08:00
import { setupAptPack } from "../utils/setup/setupAptPack"
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import semverMajor from "semver/functions/major"
import semverCoerce from "semver/functions/coerce"
2021-11-22 01:06:16 +08:00
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
2021-09-16 22:03:54 +08:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function setupGcc(version: string, _setupCppDir: string, arch: string) {
let binDir: string | undefined
2021-09-16 22:03:54 +08:00
switch (process.platform) {
case "win32": {
if (arch === "arm" || arch === "arm64") {
await setupChocoPack("gcc-arm-embedded", version)
2021-09-16 22:03:54 +08:00
}
await setupChocoPack("mingw", version)
2021-09-17 07:26:57 +08:00
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
binDir = "C:/tools/mingw64/bin"
2021-09-19 16:49:42 +08:00
addPath(binDir)
2021-09-17 07:26:57 +08:00
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
binDir = "C:/tools/mingw32/bin"
2021-09-19 16:49:42 +08:00
addPath(binDir)
2021-09-17 17:55:20 +08:00
} else if (existsSync("C:/ProgramData/Chocolatey/bin/g++.exe")) {
2021-09-17 18:21:43 +08:00
binDir = "C:/ProgramData/Chocolatey/bin/"
}
break
2021-09-16 22:03:54 +08:00
}
case "darwin": {
binDir = setupBrewPack("gcc", version).binDir
break
2021-09-16 22:03:54 +08:00
}
case "linux": {
if (arch === "x64") {
binDir = (await setupAptPack("g++", version, "ppa:ubuntu-toolchain-r/test")).binDir
2021-09-17 06:00:14 +08:00
} else {
2021-09-17 06:17:32 +08:00
info(`Install g++-multilib because gcc for ${arch} was requested`)
2021-09-17 06:00:14 +08:00
binDir = (await setupAptPack("g++-multilib", version, "ppa:ubuntu-toolchain-r/test")).binDir
2021-09-16 22:03:54 +08:00
}
break
2021-09-16 22:03:54 +08:00
}
// 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}`)
}
}
if (binDir !== undefined) {
2021-11-22 01:06:16 +08:00
await activateGcc(version, binDir)
return { binDir }
}
return undefined
2021-09-16 22:03:54 +08:00
}
2021-09-20 20:25:41 +08:00
2021-11-22 01:06:16 +08:00
async function activateGcc(version: string, binDir: string) {
2021-09-20 20:25:41 +08:00
const majorVersion = semverMajor(semverCoerce(version) ?? version)
// TODO
// const ld = process.env.LD_LIBRARY_PATH ?? ""
// const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
// // Setup gcc as the compiler
// exportVariable("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
// exportVariable("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
// exportVariable("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
// exportVariable("LDFLAGS", `-L${installDir}/lib`)
// exportVariable("CPPFLAGS", `-I${installDir}/include`)
if (process.platform === "win32") {
exportVariable("CC", `${binDir}/gcc`)
exportVariable("CXX", `${binDir}/g++`)
} else {
exportVariable("CC", `${binDir}/gcc-${majorVersion}`)
exportVariable("CXX", `${binDir}/g++-${majorVersion}`)
}
2021-11-22 01:06:16 +08:00
await setupMacOSSDK()
2021-09-20 20:25:41 +08:00
}