mirror of https://github.com/aminya/setup-cpp
Merge pull request #82 from aminya/mingw [skip ci]
This commit is contained in:
commit
f1ac436995
|
@ -41,6 +41,7 @@ words:
|
||||||
- libtinfo
|
- libtinfo
|
||||||
- msbuild
|
- msbuild
|
||||||
- msvc
|
- msvc
|
||||||
|
- msvcrt
|
||||||
- msys
|
- msys
|
||||||
- multilib
|
- multilib
|
||||||
- mxschmitt
|
- mxschmitt
|
||||||
|
@ -55,6 +56,7 @@ words:
|
||||||
- setx
|
- setx
|
||||||
- terserrc
|
- terserrc
|
||||||
- tsbuildinfo
|
- tsbuildinfo
|
||||||
|
- ucrt
|
||||||
- untildify
|
- untildify
|
||||||
- vcpkg
|
- vcpkg
|
||||||
- vcvarsall
|
- vcvarsall
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,7 @@ const DefaultVersions: Record<string, string> = {
|
||||||
kcov: "40", // https://github.com/SimonKagstrom/kcov/releases
|
kcov: "40", // https://github.com/SimonKagstrom/kcov/releases
|
||||||
task: "3.12.1", // https://github.com/go-task/task/releases
|
task: "3.12.1", // https://github.com/go-task/task/releases
|
||||||
doxygen: process.platform === "darwin" ? "1.9.3" : "1.9.4", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen
|
doxygen: process.platform === "darwin" ? "1.9.3" : "1.9.4", // https://www.doxygen.nl/download.html // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=doxygen
|
||||||
gcc: process.platform === "win32" ? "11.2.0.07112021" : "11", // https://community.chocolatey.org/packages/mingw#versionhistory and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
|
gcc: "11", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the default version if passed true or undefined, otherwise return the version itself */
|
/** Get the default version if passed true or undefined, otherwise return the version itself */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { testBin } from "../../utils/tests/test-helpers"
|
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
|
||||||
import { setupGcc } from "../gcc"
|
import { setupGcc } from "../gcc"
|
||||||
import { getVersion } from "../../default_versions"
|
import { getVersion } from "../../default_versions"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
@ -8,9 +8,14 @@ import { chmodSync } from "fs"
|
||||||
|
|
||||||
jest.setTimeout(3000000)
|
jest.setTimeout(3000000)
|
||||||
describe("setup-gcc", () => {
|
describe("setup-gcc", () => {
|
||||||
|
let directory: string
|
||||||
|
beforeAll(async () => {
|
||||||
|
directory = await setupTmpDir("doxygen")
|
||||||
|
})
|
||||||
|
|
||||||
it("should setup gcc", async () => {
|
it("should setup gcc", async () => {
|
||||||
const version = getVersion("gcc", undefined) || "11"
|
const version = getVersion("gcc", undefined)
|
||||||
const installInfo = await setupGcc(version, "", process.arch)
|
const installInfo = await setupGcc(version, directory, process.arch)
|
||||||
|
|
||||||
let gpp = "g++"
|
let gpp = "g++"
|
||||||
if (process.platform !== "win32") {
|
if (process.platform !== "win32") {
|
||||||
|
@ -30,4 +35,8 @@ describe("setup-gcc", () => {
|
||||||
}
|
}
|
||||||
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
|
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await cleanupTmpDir("doxygen")
|
||||||
|
}, 100000)
|
||||||
})
|
})
|
||||||
|
|
Binary file not shown.
|
@ -10,39 +10,80 @@ import path from "path"
|
||||||
import { warning, info } from "../utils/io/io"
|
import { warning, info } from "../utils/io/io"
|
||||||
import { isGitHubCI } from "../utils/env/isci"
|
import { isGitHubCI } from "../utils/env/isci"
|
||||||
import { addBinExtension } from "../utils/extension/extension"
|
import { addBinExtension } from "../utils/extension/extension"
|
||||||
|
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
|
||||||
|
import { extract7Zip } from "../utils/setup/extract"
|
||||||
|
|
||||||
|
interface MingwInfo {
|
||||||
|
releaseName: string
|
||||||
|
fileSuffix: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/brechtsanders/winlibs_mingw/releases
|
||||||
|
const GccToMingwInfo = {
|
||||||
|
"12": { releaseName: "12.1.0-10.0.0-msvcrt-r1", fileSuffix: "12.1.0-mingw-w64msvcrt-10.0.0-r1" },
|
||||||
|
"12.1.0-msvcrt": { releaseName: "12.1.0-10.0.0-msvcrt-r1", fileSuffix: "12.1.0-mingw-w64msvcrt-10.0.0-r1" },
|
||||||
|
"11": { releaseName: "11.3.0-14.0.3-10.0.0-ucrt-r3", fileSuffix: "11.3.0-mingw-w64ucrt-10.0.0-r3" },
|
||||||
|
"11.3.0-ucrt": { releaseName: "11.3.0-14.0.3-10.0.0-ucrt-r3", fileSuffix: "11.3.0-mingw-w64ucrt-10.0.0-r3" },
|
||||||
|
"11.3.0-msvcrt": { releaseName: "11.3.0-14.0.3-10.0.0-msvcrt-r3", fileSuffix: "11.3.0-mingw-w64msvcrt-10.0.0-r3" },
|
||||||
|
"11.2.0-ucrt": { releaseName: "11.2.0-9.0.0-ucrt-r5", fileSuffix: "11.2.0-mingw-w64ucrt-9.0.0-r5" },
|
||||||
|
"11.2.0-msvcrt": { releaseName: "11.2.0-9.0.0-msvcrt-r5", fileSuffix: "11.2.0-mingw-w64msvcrt-9.0.0-r5" },
|
||||||
|
"10": { releaseName: "10.3.0-12.0.0-9.0.0-r2", fileSuffix: "10.3.0-llvm-12.0.0-mingw-w64-9.0.0-r2" },
|
||||||
|
"10.3.0": { releaseName: "10.3.0-12.0.0-9.0.0-r2", fileSuffix: "10.3.0-llvm-12.0.0-mingw-w64-9.0.0-r2" },
|
||||||
|
"10.2.0": { releaseName: "10.2.0-7.0.0-r4", fileSuffix: "10.2.0-llvm-10.0.1-mingw-w64-7.0.0-r4" },
|
||||||
|
"9": { releaseName: "9.4.0-9.0.0-r1", fileSuffix: "9.4.0-mingw-w64-9.0.0-r1" },
|
||||||
|
"9.4.0": { releaseName: "9.4.0-9.0.0-r1", fileSuffix: "9.4.0-mingw-w64-9.0.0-r1" },
|
||||||
|
} as Record<string, MingwInfo | undefined>
|
||||||
|
|
||||||
|
function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
|
||||||
|
switch (platform) {
|
||||||
|
case "win32": {
|
||||||
|
const mingwInfo = GccToMingwInfo[version]
|
||||||
|
if (mingwInfo === undefined) {
|
||||||
|
throw new Error(`mingw version ${version} is not supported`)
|
||||||
|
}
|
||||||
|
const mingwArch = arch === "ia32" ? "i686" : "x86_64"
|
||||||
|
const exceptionModel: "seh" | "dwarf" = "seh" // SEH is native windows exception model https://github.com/brechtsanders/winlibs_mingw/issues/4#issuecomment-599296483
|
||||||
|
return {
|
||||||
|
binRelativeDir: "bin/",
|
||||||
|
binFileName: addBinExtension("g++"),
|
||||||
|
extractedFolderName: "mingw64",
|
||||||
|
extractFunction: extract7Zip,
|
||||||
|
url: `https://github.com/brechtsanders/winlibs_mingw/releases/download/${mingwInfo.releaseName}/winlibs-${mingwArch}-posix-${exceptionModel}-gcc-${mingwInfo.fileSuffix}.7z`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported platform '${platform}'`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export async function setupGcc(version: string, _setupDir: string, arch: string) {
|
export async function setupGcc(version: string, setupDir: string, arch: string) {
|
||||||
let binDir: string | undefined
|
let installationInfo: InstallationInfo | undefined
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "win32": {
|
case "win32": {
|
||||||
if (arch === "arm" || arch === "arm64") {
|
if (arch === "arm" || arch === "arm64") {
|
||||||
await setupChocoPack("gcc-arm-embedded", version)
|
await setupChocoPack("gcc-arm-embedded", version)
|
||||||
}
|
}
|
||||||
await setupChocoPack("mingw", version)
|
try {
|
||||||
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
|
installationInfo = await setupBin("g++", version, getGccPackageInfo, setupDir, arch)
|
||||||
binDir = "C:/tools/mingw64/bin"
|
} catch (err) {
|
||||||
await addPath(binDir)
|
info(`Failed to download g++ binary. ${err}. Falling back to chocolatey.`)
|
||||||
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
|
installationInfo = await setupChocoMingw(version, arch)
|
||||||
binDir = "C:/tools/mingw32/bin"
|
|
||||||
await addPath(binDir)
|
|
||||||
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
|
|
||||||
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case "darwin": {
|
case "darwin": {
|
||||||
binDir = setupBrewPack("gcc", version).binDir
|
installationInfo = setupBrewPack("gcc", version)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case "linux": {
|
case "linux": {
|
||||||
if (arch === "x64") {
|
if (arch === "x64") {
|
||||||
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
|
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
|
||||||
binDir = setupAptPack("g++", version, []).binDir
|
installationInfo = setupAptPack("g++", version, [])
|
||||||
} else {
|
} else {
|
||||||
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
info(`Install g++-multilib because gcc for ${arch} was requested`)
|
||||||
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
|
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
|
||||||
binDir = setupAptPack("g++-multilib", version, []).binDir
|
installationInfo = setupAptPack("g++-multilib", version, [])
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -61,8 +102,26 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
|
||||||
throw new Error(`Unsupported platform for ${arch}`)
|
throw new Error(`Unsupported platform for ${arch}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (installationInfo !== undefined) {
|
||||||
|
await activateGcc(version, installationInfo.binDir)
|
||||||
|
return installationInfo
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupChocoMingw(version: string, arch: string): Promise<InstallationInfo | undefined> {
|
||||||
|
await setupChocoPack("mingw", version)
|
||||||
|
let binDir: string | undefined
|
||||||
|
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
|
||||||
|
binDir = "C:/tools/mingw64/bin"
|
||||||
|
await addPath(binDir)
|
||||||
|
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
|
||||||
|
binDir = "C:/tools/mingw32/bin"
|
||||||
|
await addPath(binDir)
|
||||||
|
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
|
||||||
|
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
|
||||||
|
}
|
||||||
if (binDir !== undefined) {
|
if (binDir !== undefined) {
|
||||||
await activateGcc(version, binDir)
|
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
|
|
Loading…
Reference in New Issue