Skip to content

Commit d24850c

Browse files
committed
feat: directly download mingw binaries on Windows
1 parent bdff7f7 commit d24850c

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

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/gcc.ts

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,79 @@ import semverMajor from "semver/functions/major"
77
import semverCoerce from "semver/functions/coerce"
88
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
99
import path from "path"
10-
import { warning, info } from "../utils/io/io"
10+
import { warning, info, notice } 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+
mingwVersion: string
18+
llvmVersion?: string
19+
number: string
20+
runtime: "ucrt" | "msvcrt" // ucrt is the modern runtime and should be preferred
21+
}
22+
23+
const GccToMingwInfo = {
24+
"12": { mingwVersion: "10.0.0", number: "r1", runtime: "msvcrt" },
25+
"12.1.0-msvcrt": { mingwVersion: "10.0.0", number: "r1", runtime: "msvcrt" },
26+
"11": { mingwVersion: "10.0.0", llvmVersion: "14.0.3", number: "r3", runtime: "ucrt" },
27+
"11.3.0-ucrt": { mingwVersion: "10.0.0", llvmVersion: "14.0.3", number: "r3", runtime: "ucrt" },
28+
"11.3.0-msvcrt": { mingwVersion: "10.0.0", llvmVersion: "14.0.3", number: "r3", runtime: "msvcrt" },
29+
"11.2.0-ucrt": { mingwVersion: "9.0.0", number: "r5", runtime: "ucrt" },
30+
"11.2.0-msvcrt": { mingwVersion: "9.0.0", number: "r6", runtime: "msvcrt" }, // TODO -w64-
31+
} as Record<string, MingwInfo | undefined>
32+
33+
function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): PackageInfo {
34+
switch (platform) {
35+
case "win32": {
36+
const mingwInfo = GccToMingwInfo[version]
37+
if (mingwInfo === undefined) {
38+
throw new Error(`mingw version ${version} is not supported`)
39+
}
40+
const mingwArch = arch === "ia32" ? "i686" : "x86_64"
41+
const llvmVersionString = mingwInfo.llvmVersion !== undefined ? `${mingwInfo.llvmVersion}-` : ""
42+
return {
43+
binRelativeDir: "./bin",
44+
binFileName: addBinExtension("g++"),
45+
extractedFolderName: "mingw64",
46+
extractFunction: extract7Zip,
47+
url: `https://github.com/brechtsanders/winlibs_mingw/releases/download/${version}-${llvmVersionString}${mingwInfo.mingwVersion}-${mingwInfo.runtime}-${mingwInfo.number}/winlibs-${mingwArch}-posix-seh-gcc-${version}-mingw-w64${mingwInfo.runtime}-${mingwInfo.mingwVersion}-${mingwInfo.number}.7z`,
48+
}
49+
}
50+
default:
51+
throw new Error(`Unsupported platform '${platform}'`)
52+
}
53+
}
1354

1455
// 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
56+
export async function setupGcc(version: string, setupDir: string, arch: string) {
57+
let installationInfo: InstallationInfo | undefined
1758
switch (process.platform) {
1859
case "win32": {
1960
if (arch === "arm" || arch === "arm64") {
2061
await setupChocoPack("gcc-arm-embedded", version)
2162
}
22-
binDir = await setupChocoMingw(version, arch)
63+
try {
64+
installationInfo = await setupBin("g++", version, getGccPackageInfo, setupDir, arch)
65+
} catch (err) {
66+
notice(`Failed to download g++ binary. ${err}. Falling back to chocolatey.`)
67+
installationInfo = await setupChocoMingw(version, arch)
68+
}
2369
break
2470
}
2571
case "darwin": {
26-
binDir = setupBrewPack("gcc", version).binDir
72+
installationInfo = setupBrewPack("gcc", version)
2773
break
2874
}
2975
case "linux": {
3076
if (arch === "x64") {
3177
setupAptPack("gcc", version, ["ppa:ubuntu-toolchain-r/test"])
32-
binDir = setupAptPack("g++", version, []).binDir
78+
installationInfo = setupAptPack("g++", version, [])
3379
} else {
3480
info(`Install g++-multilib because gcc for ${arch} was requested`)
3581
setupAptPack("gcc-multilib", version, ["ppa:ubuntu-toolchain-r/test"])
36-
binDir = setupAptPack("g++-multilib", version, []).binDir
82+
installationInfo = setupAptPack("g++-multilib", version, [])
3783
}
3884
break
3985
}
@@ -52,14 +98,14 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
5298
throw new Error(`Unsupported platform for ${arch}`)
5399
}
54100
}
55-
if (binDir !== undefined) {
56-
await activateGcc(version, binDir)
57-
return { binDir }
101+
if (installationInfo !== undefined) {
102+
await activateGcc(version, installationInfo.binDir)
103+
return installationInfo
58104
}
59105
return undefined
60106
}
61107

62-
async function setupChocoMingw(version: string, arch: string) {
108+
async function setupChocoMingw(version: string, arch: string): Promise<InstallationInfo | undefined> {
63109
await setupChocoPack("mingw", version)
64110
let binDir: string | undefined
65111
if (arch === "x64" && existsSync("C:/tools/mingw64/bin")) {
@@ -71,7 +117,10 @@ async function setupChocoMingw(version: string, arch: string) {
71117
} else if (existsSync(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) {
72118
binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin`
73119
}
74-
return binDir
120+
if (binDir !== undefined) {
121+
return { binDir }
122+
}
123+
return undefined
75124
}
76125

77126
async function activateGcc(version: string, binDir: string) {

0 commit comments

Comments
 (0)