Skip to content

Commit f1ac436

Browse files
authored
Merge pull request #82 from aminya/mingw [skip ci]
2 parents 1c4d0a4 + 97b65fa commit f1ac436

File tree

7 files changed

+91
-21
lines changed

7 files changed

+91
-21
lines changed

cspell.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ words:
4141
- libtinfo
4242
- msbuild
4343
- msvc
44+
- msvcrt
4445
- msys
4546
- multilib
4647
- mxschmitt
@@ -55,6 +56,7 @@ words:
5556
- setx
5657
- terserrc
5758
- tsbuildinfo
59+
- ucrt
5860
- untildify
5961
- vcpkg
6062
- vcvarsall

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const DefaultVersions: Record<string, string> = {
1313
kcov: "40", // https://github.com/SimonKagstrom/kcov/releases
1414
task: "3.12.1", // https://github.com/go-task/task/releases
1515
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
16-
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
16+
gcc: "11", // https://github.com/brechtsanders/winlibs_mingw/releases and // https://packages.ubuntu.com/search?suite=all&arch=any&searchon=names&keywords=gcc
1717
}
1818

1919
/** Get the default version if passed true or undefined, otherwise return the version itself */

src/gcc/__tests__/gcc.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testBin } from "../../utils/tests/test-helpers"
1+
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers"
22
import { setupGcc } from "../gcc"
33
import { getVersion } from "../../default_versions"
44
import path from "path"
@@ -8,9 +8,14 @@ import { chmodSync } from "fs"
88

99
jest.setTimeout(3000000)
1010
describe("setup-gcc", () => {
11+
let directory: string
12+
beforeAll(async () => {
13+
directory = await setupTmpDir("doxygen")
14+
})
15+
1116
it("should setup gcc", async () => {
12-
const version = getVersion("gcc", undefined) || "11"
13-
const installInfo = await setupGcc(version, "", process.arch)
17+
const version = getVersion("gcc", undefined)
18+
const installInfo = await setupGcc(version, directory, process.arch)
1419

1520
let gpp = "g++"
1621
if (process.platform !== "win32") {
@@ -30,4 +35,8 @@ describe("setup-gcc", () => {
3035
}
3136
execa.sync(main_exe, { cwd: __dirname, stdio: "inherit" })
3237
})
38+
39+
afterAll(async () => {
40+
await cleanupTmpDir("doxygen")
41+
}, 100000)
3342
})

src/gcc/__tests__/main.exe

111 KB
Binary file not shown.

src/gcc/gcc.ts

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,80 @@ import path from "path"
1010
import { warning, info } from "../utils/io/io"
1111
import { isGitHubCI } from "../utils/env/isci"
1212
import { addBinExtension } from "../utils/extension/extension"
13+
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
14+
import { extract7Zip } from "../utils/setup/extract"
15+
16+
interface MingwInfo {
17+
releaseName: string
18+
fileSuffix: string
19+
}
20+
21+
// https://github.com/brechtsanders/winlibs_mingw/releases
22+
const GccToMingwInfo = {
23+
"12": { releaseName: "12.1.0-10.0.0-msvcrt-r1", fileSuffix: "12.1.0-mingw-w64msvcrt-10.0.0-r1" },
24+
"12.1.0-msvcrt": { releaseName: "12.1.0-10.0.0-msvcrt-r1", fileSuffix: "12.1.0-mingw-w64msvcrt-10.0.0-r1" },
25+
"11": { releaseName: "11.3.0-14.0.3-10.0.0-ucrt-r3", fileSuffix: "11.3.0-mingw-w64ucrt-10.0.0-r3" },
26+
"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" },
27+
"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" },
28+
"11.2.0-ucrt": { releaseName: "11.2.0-9.0.0-ucrt-r5", fileSuffix: "11.2.0-mingw-w64ucrt-9.0.0-r5" },
29+
"11.2.0-msvcrt": { releaseName: "11.2.0-9.0.0-msvcrt-r5", fileSuffix: "11.2.0-mingw-w64msvcrt-9.0.0-r5" },
30+
"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" },
31+
"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" },
32+
"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" },
33+
"9": { releaseName: "9.4.0-9.0.0-r1", fileSuffix: "9.4.0-mingw-w64-9.0.0-r1" },
34+
"9.4.0": { releaseName: "9.4.0-9.0.0-r1", fileSuffix: "9.4.0-mingw-w64-9.0.0-r1" },
35+
} as Record<string, MingwInfo | undefined>
36+
37+
function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
38+
switch (platform) {
39+
case "win32": {
40+
const mingwInfo = GccToMingwInfo[version]
41+
if (mingwInfo === undefined) {
42+
throw new Error(`mingw version ${version} is not supported`)
43+
}
44+
const mingwArch = arch === "ia32" ? "i686" : "x86_64"
45+
const exceptionModel: "seh" | "dwarf" = "seh" // SEH is native windows exception model https://github.com/brechtsanders/winlibs_mingw/issues/4#issuecomment-599296483
46+
return {
47+
binRelativeDir: "bin/",
48+
binFileName: addBinExtension("g++"),
49+
extractedFolderName: "mingw64",
50+
extractFunction: extract7Zip,
51+
url: `https://github.com/brechtsanders/winlibs_mingw/releases/download/${mingwInfo.releaseName}/winlibs-${mingwArch}-posix-${exceptionModel}-gcc-${mingwInfo.fileSuffix}.7z`,
52+
}
53+
}
54+
default:
55+
throw new Error(`Unsupported platform '${platform}'`)
56+
}
57+
}
1358

1459
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15-
export async function setupGcc(version: string, _setupDir: string, arch: string) {
16-
let binDir: string | undefined
60+
export async function setupGcc(version: string, setupDir: string, arch: string) {
61+
let installationInfo: InstallationInfo | undefined
1762
switch (process.platform) {
1863
case "win32": {
1964
if (arch === "arm" || arch === "arm64") {
2065
await setupChocoPack("gcc-arm-embedded", version)
2166
}
22-
await setupChocoPack("mingw", version)
23-
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
24-
binDir = "C:/tools/mingw64/bin"
25-
await addPath(binDir)
26-
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
27-
binDir = "C:/tools/mingw32/bin"
28-
await addPath(binDir)
29-
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
30-
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
67+
try {
68+
installationInfo = await setupBin("g++", version, getGccPackageInfo, setupDir, arch)
69+
} catch (err) {
70+
info(`Failed to download g++ binary. ${err}. Falling back to chocolatey.`)
71+
installationInfo = await setupChocoMingw(version, arch)
3172
}
3273
break
3374
}
3475
case "darwin": {
35-
binDir = setupBrewPack("gcc", version).binDir
76+
installationInfo = setupBrewPack("gcc", version)
3677
break
3778
}
3879
case "linux": {
3980
if (arch === "x64") {
4081
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
41-
binDir = setupAptPack("g++", version, []).binDir
82+
installationInfo = setupAptPack("g++", version, [])
4283
} else {
4384
info(`Install g++-multilib because gcc for ${arch} was requested`)
4485
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
45-
binDir = setupAptPack("g++-multilib", version, []).binDir
86+
installationInfo = setupAptPack("g++-multilib", version, [])
4687
}
4788
break
4889
}
@@ -61,8 +102,26 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
61102
throw new Error(`Unsupported platform for ${arch}`)
62103
}
63104
}
105+
if (installationInfo !== undefined) {
106+
await activateGcc(version, installationInfo.binDir)
107+
return installationInfo
108+
}
109+
return undefined
110+
}
111+
112+
async function setupChocoMingw(version: string, arch: string): Promise<InstallationInfo | undefined> {
113+
await setupChocoPack("mingw", version)
114+
let binDir: string | undefined
115+
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
116+
binDir = "C:/tools/mingw64/bin"
117+
await addPath(binDir)
118+
} else if (arch === "ia32" && existsSync("C:/tools/mingw32/bin")) {
119+
binDir = "C:/tools/mingw32/bin"
120+
await addPath(binDir)
121+
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
122+
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
123+
}
64124
if (binDir !== undefined) {
65-
await activateGcc(version, binDir)
66125
return { binDir }
67126
}
68127
return undefined

0 commit comments

Comments
 (0)