2022-03-12 09:32:28 +08:00
|
|
|
import { addPath, addEnv } from "../utils/env/addEnv"
|
2021-09-17 04:13:55 +08:00
|
|
|
import { existsSync } from "fs"
|
2022-04-19 14:34:18 +08:00
|
|
|
import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack"
|
2021-09-16 22:03:54 +08:00
|
|
|
import { setupBrewPack } from "../utils/setup/setupBrewPack"
|
|
|
|
import { setupChocoPack } from "../utils/setup/setupChocoPack"
|
2021-09-17 05:47:49 +08:00
|
|
|
import semverMajor from "semver/functions/major"
|
2021-09-17 07:02:18 +08:00
|
|
|
import semverCoerce from "semver/functions/coerce"
|
2021-11-22 01:06:16 +08:00
|
|
|
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
|
2022-02-12 08:58:50 +08:00
|
|
|
import path from "path"
|
|
|
|
import { warning } from "../utils/io/io"
|
|
|
|
import { isGitHubCI } from "../utils/env/isci"
|
|
|
|
import { info } from "@actions/core"
|
2021-09-16 22:03:54 +08:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-11-22 02:46:34 +08:00
|
|
|
export async function setupGcc(version: string, _setupDir: string, arch: string) {
|
2021-09-17 05:47:49 +08:00
|
|
|
let binDir: string | undefined
|
2021-09-16 22:03:54 +08:00
|
|
|
switch (process.platform) {
|
|
|
|
case "win32": {
|
|
|
|
if (arch === "arm" || arch === "arm64") {
|
2021-09-16 22:19:56 +08:00
|
|
|
await setupChocoPack("gcc-arm-embedded", version)
|
2021-09-16 22:03:54 +08:00
|
|
|
}
|
2021-09-16 22:19:56 +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)
|
2022-01-31 09:49:30 +08:00
|
|
|
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
|
|
|
|
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
|
2021-09-16 22:19:56 +08:00
|
|
|
}
|
2021-09-17 05:47:49 +08:00
|
|
|
break
|
2021-09-16 22:03:54 +08:00
|
|
|
}
|
|
|
|
case "darwin": {
|
2021-09-17 05:47:49 +08:00
|
|
|
binDir = setupBrewPack("gcc", version).binDir
|
|
|
|
break
|
2021-09-16 22:03:54 +08:00
|
|
|
}
|
|
|
|
case "linux": {
|
|
|
|
if (arch === "x64") {
|
2022-04-27 15:02:35 +08:00
|
|
|
setupAptPack("gcc", version, [
|
2021-12-08 04:16:22 +08:00
|
|
|
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
|
2021-12-08 03:37:01 +08:00
|
|
|
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
|
2021-12-07 20:16:31 +08:00
|
|
|
"ppa:ubuntu-toolchain-r/test",
|
|
|
|
])
|
2022-04-27 15:02:35 +08:00
|
|
|
binDir = setupAptPack("g++", version, []).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`)
|
2022-04-27 15:02:35 +08:00
|
|
|
setupAptPack("gcc-multilib", version, [
|
2021-12-08 04:16:22 +08:00
|
|
|
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
|
2021-12-08 03:37:01 +08:00
|
|
|
"deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
|
2021-12-07 20:16:31 +08:00
|
|
|
"ppa:ubuntu-toolchain-r/test",
|
|
|
|
])
|
2022-04-27 15:02:35 +08:00
|
|
|
binDir = setupAptPack("g++-multilib", version, []).binDir
|
2021-09-16 22:03:54 +08:00
|
|
|
}
|
2021-09-17 05:47:49 +08:00
|
|
|
break
|
2021-09-16 22:03:54 +08:00
|
|
|
}
|
2021-12-07 16:53:22 +08:00
|
|
|
// TODO support bare-metal (need to support passing it as the input)
|
2021-09-16 22:03:54 +08:00
|
|
|
// TODO support abi
|
|
|
|
// case "none": {
|
|
|
|
// if (arch === "arm" || arch === "arm64") {
|
2021-12-07 16:53:22 +08:00
|
|
|
// return setupAptPack("gcc-arm-none-eabi", version, [
|
2021-12-08 04:16:22 +08:00
|
|
|
// "deb http://dk.archive.ubuntu.com/ubuntu/ xenial main",
|
2021-12-08 03:37:01 +08:00
|
|
|
// "deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe",
|
2021-12-07 20:16:31 +08:00
|
|
|
// "ppa:ubuntu-toolchain-r/test",
|
2021-12-07 16:53:22 +08:00
|
|
|
// ])
|
2021-09-16 22:03:54 +08:00
|
|
|
// } else {
|
|
|
|
// throw new Error(`Unsupported platform for ${arch}`)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
default: {
|
|
|
|
throw new Error(`Unsupported platform for ${arch}`)
|
|
|
|
}
|
|
|
|
}
|
2021-09-17 05:47:49 +08:00
|
|
|
if (binDir !== undefined) {
|
2021-11-22 01:06:16 +08:00
|
|
|
await activateGcc(version, binDir)
|
2021-09-17 05:47:49 +08:00
|
|
|
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
|
|
|
// TODO
|
|
|
|
// const ld = process.env.LD_LIBRARY_PATH ?? ""
|
|
|
|
// const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
|
|
|
|
// // Setup gcc as the compiler
|
2022-01-18 10:30:02 +08:00
|
|
|
// addEnv("LD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${ld}`)
|
|
|
|
// addEnv("DYLD_LIBRARY_PATH", `${installDir}/lib${path.delimiter}${dyld}`)
|
|
|
|
// addEnv("CPATH", `${installDir}/lib/gcc/${majorVersion}/include`)
|
|
|
|
// addEnv("LDFLAGS", `-L${installDir}/lib`)
|
|
|
|
// addEnv("CPPFLAGS", `-I${installDir}/include`)
|
2021-09-20 20:25:41 +08:00
|
|
|
if (process.platform === "win32") {
|
2022-01-18 10:30:02 +08:00
|
|
|
addEnv("CC", `${binDir}/gcc`)
|
|
|
|
addEnv("CXX", `${binDir}/g++`)
|
2021-09-20 20:25:41 +08:00
|
|
|
} else {
|
2021-12-07 20:16:31 +08:00
|
|
|
const majorVersion = semverMajor(semverCoerce(version) ?? version)
|
|
|
|
if (majorVersion >= 5) {
|
2022-01-18 10:30:02 +08:00
|
|
|
addEnv("CC", `${binDir}/gcc-${majorVersion}`)
|
|
|
|
addEnv("CXX", `${binDir}/g++-${majorVersion}`)
|
2022-04-19 14:34:18 +08:00
|
|
|
|
|
|
|
if (process.platform === "linux") {
|
|
|
|
await updateAptAlternatives("cc", `${binDir}/gcc-${majorVersion}`)
|
|
|
|
await updateAptAlternatives("cxx", `${binDir}/g++-${majorVersion}`)
|
2022-04-25 09:11:19 +08:00
|
|
|
await updateAptAlternatives("gcc", `${binDir}/gcc-${majorVersion}`)
|
|
|
|
await updateAptAlternatives("g++", `${binDir}/g++-${majorVersion}`)
|
2022-04-19 14:34:18 +08:00
|
|
|
}
|
2021-12-07 20:16:31 +08:00
|
|
|
} else {
|
2022-01-18 10:30:02 +08:00
|
|
|
addEnv("CC", `${binDir}/gcc-${version}`)
|
|
|
|
addEnv("CXX", `${binDir}/g++-${version}`)
|
2022-04-19 14:34:18 +08:00
|
|
|
|
|
|
|
if (process.platform === "linux") {
|
|
|
|
await updateAptAlternatives("cc", `${binDir}/gcc-${version}`)
|
|
|
|
await updateAptAlternatives("cxx", `${binDir}/g++-${version}`)
|
2022-04-25 09:11:19 +08:00
|
|
|
await updateAptAlternatives("gcc", `${binDir}/gcc-${version}`)
|
|
|
|
await updateAptAlternatives("g++", `${binDir}/g++-${version}`)
|
2022-04-19 14:34:18 +08:00
|
|
|
}
|
2021-12-07 20:16:31 +08:00
|
|
|
}
|
2021-09-20 20:25:41 +08:00
|
|
|
}
|
2021-11-22 01:06:16 +08:00
|
|
|
|
|
|
|
await setupMacOSSDK()
|
2022-02-12 08:58:50 +08:00
|
|
|
|
|
|
|
if (isGitHubCI()) {
|
|
|
|
addGccLoggingMatcher()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addGccLoggingMatcher() {
|
|
|
|
const matcherPath = path.join(__dirname, "gcc_matcher.json")
|
|
|
|
if (!existsSync(matcherPath)) {
|
|
|
|
return warning("the gcc_matcher.json file does not exist in the same folder as setup_cpp.js")
|
|
|
|
}
|
|
|
|
info(`::add-matcher::${matcherPath}`)
|
2021-09-20 20:25:41 +08:00
|
|
|
}
|