|
1 | | -import path, { join } from "path" |
| 1 | +import path from "path" |
2 | 2 | import { fileURLToPath } from "url" |
3 | 3 | import { GITHUB_ACTIONS } from "ci-info" |
4 | 4 | import { error, info, warning } from "ci-log" |
5 | | -import { addEnv, addPath } from "envosman" |
| 5 | +import { addEnv } from "envosman" |
6 | 6 | import { execa } from "execa" |
7 | 7 | import { readdir } from "fs/promises" |
8 | 8 | import { pathExists } from "path-exists" |
9 | | -import { addExeExt } from "patha" |
10 | 9 | import semverCoerce from "semver/functions/coerce" |
11 | 10 | import semverMajor from "semver/functions/major" |
12 | 11 | import { addUpdateAlternativesToRc, installAptPack } from "setup-apt" |
13 | 12 | import { installBrewPack } from "setup-brew" |
14 | 13 | import { rcOptions } from "../cli-options.js" |
15 | 14 | import { setupMacOSSDK } from "../macos-sdk/macos-sdk.js" |
16 | | -import { loadAssetList, matchAsset } from "../utils/asset/load-assets.js" |
17 | 15 | import { hasDnf } from "../utils/env/hasDnf.js" |
18 | 16 | import { isArch } from "../utils/env/isArch.js" |
19 | 17 | import { isUbuntu } from "../utils/env/isUbuntu.js" |
20 | | -import { extract7Zip } from "../utils/setup/extract.js" |
21 | | -import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setup/setupBin.js" |
22 | | -import { setupChocoPack } from "../utils/setup/setupChocoPack.js" |
| 18 | +import type { InstallationInfo } from "../utils/setup/setupBin.js" |
23 | 19 | import { setupDnfPack } from "../utils/setup/setupDnfPack.js" |
24 | 20 | import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js" |
25 | 21 | import { compareVersion } from "../utils/setup/version.js" |
| 22 | +import { addGccLoggingMatcher } from "./gccMatcher.js" |
| 23 | +import { setupMingw } from "./mingw.js" |
26 | 24 |
|
27 | | -const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url)) |
28 | | - |
29 | | -async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> { |
30 | | - switch (platform) { |
31 | | - case "win32": { |
32 | | - const mingwAssets = await loadAssetList( |
33 | | - join(dirname, "github_brechtsanders_winlibs_mingw.json"), |
34 | | - ) |
35 | | - |
36 | | - const mingwArchMap = { |
37 | | - x64: "x86_64", |
38 | | - ia32: "i386", |
39 | | - } as Record<string, string | undefined> |
40 | | - |
41 | | - const asset = matchAsset( |
42 | | - mingwAssets, |
43 | | - { |
44 | | - version, |
45 | | - keywords: [ |
46 | | - mingwArchMap[arch] ?? arch, |
47 | | - ], |
48 | | - }, |
49 | | - ) |
50 | | - |
51 | | - if (asset === undefined) { |
52 | | - throw new Error(`No asset found for version ${version} and arch ${arch}`) |
53 | | - } |
54 | | - |
55 | | - return { |
56 | | - binRelativeDir: "bin/", |
57 | | - binFileName: addExeExt("g++"), |
58 | | - extractedFolderName: "mingw64", |
59 | | - extractFunction: extract7Zip, |
60 | | - url: `https://github.com/brechtsanders/winlibs_mingw/releases/download/${asset.tag}/${asset.name}`, |
61 | | - } |
62 | | - } |
63 | | - default: |
64 | | - throw new Error(`Unsupported platform '${platform}'`) |
65 | | - } |
66 | | -} |
| 25 | +export const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url)) |
67 | 26 |
|
68 | 27 | export async function setupGcc(version: string, setupDir: string, arch: string, priority: number = 40) { |
69 | 28 | let installationInfo: InstallationInfo | undefined |
70 | 29 | switch (process.platform) { |
71 | 30 | case "win32": { |
72 | | - if (arch === "arm" || arch === "arm64") { |
73 | | - await setupChocoPack("gcc-arm-embedded", version) |
74 | | - } |
75 | | - try { |
76 | | - installationInfo = await setupBin("g++", version, getGccPackageInfo, setupDir, arch) |
77 | | - } catch (err) { |
78 | | - info(`Failed to download g++ binary. ${err}. Falling back to chocolatey.`) |
79 | | - installationInfo = await setupChocoMingw(version, arch) |
80 | | - } |
| 31 | + installationInfo = await setupMingw(version, setupDir, arch) |
81 | 32 | break |
82 | 33 | } |
83 | 34 | case "darwin": { |
@@ -159,75 +110,18 @@ export async function setupGcc(version: string, setupDir: string, arch: string, |
159 | 110 | return undefined |
160 | 111 | } |
161 | 112 |
|
162 | | -// eslint-disable-next-line @typescript-eslint/no-unused-vars |
163 | | -export async function setupMingw(version: string, setupDir: string, arch: string) { |
164 | | - let installationInfo: InstallationInfo | undefined |
165 | | - switch (process.platform) { |
166 | | - case "win32": |
167 | | - case "darwin": { |
168 | | - return setupGcc(version, setupDir, arch) |
169 | | - } |
170 | | - case "linux": { |
171 | | - if (isArch()) { |
172 | | - installationInfo = await setupPacmanPack("mingw-w64-gcc", version) |
173 | | - } else if (hasDnf()) { |
174 | | - installationInfo = await setupDnfPack([{ name: "mingw64-gcc", version }]) |
175 | | - } else if (isUbuntu()) { |
176 | | - installationInfo = await installAptPack([ |
177 | | - { |
178 | | - name: "mingw-w64", |
179 | | - version, |
180 | | - repository: "ppa:ubuntu-toolchain-r/test", |
181 | | - key: { key: "1E9377A2BA9EF27F", fileName: "ubuntu-toolchain-r-test.gpg" }, |
182 | | - }, |
183 | | - ]) |
184 | | - } |
185 | | - break |
186 | | - } |
187 | | - default: { |
188 | | - throw new Error(`Unsupported platform for ${arch}`) |
189 | | - } |
190 | | - } |
191 | | - if (installationInfo !== undefined) { |
192 | | - // TODO: setup alternatives and update CC/CXX env. ? |
193 | | - // Setting up g++-mingw-w64-i686-win32 (10.3.0-14ubuntu1+24.3) ... |
194 | | - // update-alternatives: using /usr/bin/i686-w64-mingw32-g++-win32 to provide /usr/bin/i686-w64-mingw32-g++ (i686-w64-mingw32-g++) in auto mode |
195 | | - // Setting up g++-mingw-w64-x86-64-win32 (10.3.0-14ubuntu1+24.3) ... |
196 | | - // update-alternatives: using /usr/bin/x86_64-w64-mingw32-g++-win32 to provide /usr/bin/x86_64-w64-mingw32-g++ (x86_64-w64-mingw32-g++) in auto mode |
197 | | - // await activateGcc(version, installationInfo.binDir) |
198 | | - return installationInfo |
199 | | - } |
200 | | - return undefined |
201 | | -} |
202 | | - |
203 | | -async function setupChocoMingw(version: string, arch: string): Promise<InstallationInfo | undefined> { |
204 | | - await setupChocoPack("mingw", version) |
205 | | - let binDir: string | undefined |
206 | | - if (arch === "x64" && (await pathExists("C:/tools/mingw64/bin"))) { |
207 | | - binDir = "C:/tools/mingw64/bin" |
208 | | - await addPath(binDir, rcOptions) |
209 | | - } else if (arch === "ia32" && (await pathExists("C:/tools/mingw32/bin"))) { |
210 | | - binDir = "C:/tools/mingw32/bin" |
211 | | - await addPath(binDir, rcOptions) |
212 | | - } else if (await pathExists(`${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin/g++.exe`)) { |
213 | | - binDir = `${process.env.ChocolateyInstall ?? "C:/ProgramData/chocolatey"}/bin` |
214 | | - } |
215 | | - if (binDir !== undefined) { |
216 | | - return { binDir } |
| 113 | +/** |
| 114 | + * Setup gcc as the compiler on Linux and macOS |
| 115 | + */ |
| 116 | +async function activateGcc(givenVersion: string, binDir: string, priority: number = 40) { |
| 117 | + if (process.platform === "win32") { |
| 118 | + // already done in setupMingw |
| 119 | + return |
217 | 120 | } |
218 | | - return undefined |
219 | | -} |
220 | 121 |
|
221 | | -/** Setup gcc as the compiler */ |
222 | | -async function activateGcc(givenVersion: string, binDir: string, priority: number = 40) { |
223 | 122 | const promises: Promise<void>[] = [] |
224 | 123 |
|
225 | | - if (process.platform === "win32") { |
226 | | - promises.push( |
227 | | - addEnv("CC", addExeExt(`${binDir}/gcc`), rcOptions), |
228 | | - addEnv("CXX", addExeExt(`${binDir}/g++`), rcOptions), |
229 | | - ) |
230 | | - } else { |
| 124 | + { |
231 | 125 | // if version is empty, get the version from the gcc command |
232 | 126 | let version = givenVersion |
233 | 127 | if (givenVersion === "") { |
@@ -329,11 +223,3 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) { |
329 | 223 | return givenVersion |
330 | 224 | } |
331 | 225 | } |
332 | | - |
333 | | -async function addGccLoggingMatcher() { |
334 | | - const matcherPath = join(dirname, "gcc_matcher.json") |
335 | | - if (!(await pathExists(matcherPath))) { |
336 | | - return warning("the gcc_matcher.json file does not exist in the same folder as setup-cpp.js") |
337 | | - } |
338 | | - info(`::add-matcher::${matcherPath}`) |
339 | | -} |
0 commit comments