Skip to content

Commit 9560b8d

Browse files
authored
Merge pull request #306 from aminya/versions [skip ci]
2 parents 8c22730 + 59c68f4 commit 9560b8d

13 files changed

+339
-144
lines changed

.terserrc.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { buildTerserOptions } from "terser-config-atomic/dist/builder.js"
22
const config = buildTerserOptions(process.env.NODE_ENV, undefined, true)
3-
config.compress.unsafe_math = false
3+
4+
if (
5+
typeof config.compress === "object"
6+
&& "unsafe_math" in config.compress
7+
) {
8+
config.compress.unsafe_math = false
9+
}
410

511
export default config

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/compilers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { endGroup, startGroup } from "@actions/core"
33
import { error, info } from "ci-log"
44
import semverValid from "semver/functions/valid"
55
import { getSuccessMessage } from "./cli-options.js"
6-
import { setupGcc, setupMingw } from "./gcc/gcc.js"
6+
import { setupGcc } from "./gcc/gcc.js"
7+
import { setupMingw } from "./gcc/mingw.js"
78
import { activateGcovGCC, activateGcovLLVM } from "./gcovr/gcovr.js"
89
import { setupAppleClang } from "./llvm/apple-clang.js"
910
import { setupLLVM } from "./llvm/llvm.js"

src/gcc/gcc.ts

+15-129
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,34 @@
1-
import path, { join } from "path"
1+
import path from "path"
22
import { fileURLToPath } from "url"
33
import { GITHUB_ACTIONS } from "ci-info"
44
import { error, info, warning } from "ci-log"
5-
import { addEnv, addPath } from "envosman"
5+
import { addEnv } from "envosman"
66
import { execa } from "execa"
77
import { readdir } from "fs/promises"
88
import { pathExists } from "path-exists"
9-
import { addExeExt } from "patha"
109
import semverCoerce from "semver/functions/coerce"
1110
import semverMajor from "semver/functions/major"
1211
import { addUpdateAlternativesToRc, installAptPack } from "setup-apt"
1312
import { installBrewPack } from "setup-brew"
1413
import { rcOptions } from "../cli-options.js"
1514
import { setupMacOSSDK } from "../macos-sdk/macos-sdk.js"
16-
import { loadAssetList, matchAsset } from "../utils/asset/load-assets.js"
1715
import { hasDnf } from "../utils/env/hasDnf.js"
1816
import { isArch } from "../utils/env/isArch.js"
1917
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"
2319
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
2420
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
2521
import { compareVersion } from "../utils/setup/version.js"
22+
import { addGccLoggingMatcher } from "./gccMatcher.js"
23+
import { setupMingw } from "./mingw.js"
2624

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))
6726

6827
export async function setupGcc(version: string, setupDir: string, arch: string, priority: number = 40) {
6928
let installationInfo: InstallationInfo | undefined
7029
switch (process.platform) {
7130
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)
8132
break
8233
}
8334
case "darwin": {
@@ -159,75 +110,18 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
159110
return undefined
160111
}
161112

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
217120
}
218-
return undefined
219-
}
220121

221-
/** Setup gcc as the compiler */
222-
async function activateGcc(givenVersion: string, binDir: string, priority: number = 40) {
223122
const promises: Promise<void>[] = []
224123

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+
{
231125
// if version is empty, get the version from the gcc command
232126
let version = givenVersion
233127
if (givenVersion === "") {
@@ -329,11 +223,3 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
329223
return givenVersion
330224
}
331225
}
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-
}

src/gcc/gccMatcher.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from "path"
2+
import { info, warning } from "ci-log"
3+
import { pathExists } from "path-exists"
4+
import { dirname } from "./gcc.ts"
5+
6+
export async function addGccLoggingMatcher() {
7+
const matcherPath = join(dirname, "gcc_matcher.json")
8+
if (!(await pathExists(matcherPath))) {
9+
return warning("the gcc_matcher.json file does not exist in the same folder as setup-cpp.js")
10+
}
11+
info(`::add-matcher::${matcherPath}`)
12+
}

0 commit comments

Comments
 (0)