Skip to content

Commit

Permalink
feat: use GitHub API to find a matching MinGW releases
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 3, 2024
1 parent 81c10d4 commit 11fad2b
Show file tree
Hide file tree
Showing 19 changed files with 423 additions and 107 deletions.
3 changes: 2 additions & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"**/.venv/",
"**/.*cache/",
"coverage/",
"**/coverage/"
"**/coverage/",
"**/github_brechtsanders_winlibs_mingw.json"
],
"ignoreUnknown": true
},
Expand Down
1 change: 1 addition & 0 deletions dist/actions/github_brechtsanders_winlibs_mingw.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/actions/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/legacy/github_brechtsanders_winlibs_mingw.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/github_brechtsanders_winlibs_mingw.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/modern/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"./.cache/",
"**/build",
"**/dist",
"**/github_brechtsanders_winlibs_mingw.json",
"dev/cpp_vcpkg_project"
],
"plugins": [
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
"build.modern": "shx cp -r ./dist/actions/* ./dist/modern",
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync && pnpm run clean",
"clean": "shx rm -rf ./dist ./packages/*/dist ./exe ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/actions ./dist/modern ",
"copy.matchers": "run-p copy.matchers.legacy copy.matchers.actions",
"copy.matchers.legacy": "shx cp ./src/gcc/gcc_matcher.json ./dist/legacy/ && shx cp ./src/msvc/msvc_matcher.json ./dist/legacy/ && shx cp ./src/python/python_matcher.json ./dist/legacy/ && shx cp ./src/llvm/llvm_matcher.json ./dist/legacy/",
"copy.matchers.actions": "shx cp ./src/gcc/gcc_matcher.json ./dist/actions/ && shx cp ./src/msvc/msvc_matcher.json ./dist/actions/ && shx cp ./src/python/python_matcher.json ./dist/actions/ && shx cp ./src/llvm/llvm_matcher.json ./dist/actions/",
"copy.matchers": "shx cp ./src/*/*.json ./dist/legacy/ && shx cp ./dist/legacy/*.json ./dist/actions",
"dev.parcel": "cross-env NODE_ENV=development parcel watch",
"dev.packages": "turbo dev",
"dev": "run-p dev.packages dev.parcel",
Expand Down Expand Up @@ -67,6 +65,12 @@
"@babel/plugin-transform-private-methods": "^7.25.4",
"@biomejs/biome": "^1.8.3",
"@iarna/toml": "^2.2.5",
"@octokit/core": "^6.1.2",
"@octokit/openapi-types": "^22.2.0",
"@octokit/plugin-paginate-rest": "^11.3.3",
"@octokit/plugin-rest-endpoint-methods": "^13.2.4",
"@octokit/rest": "^21.0.2",
"@octokit/types": "^13.5.0",
"@shockpkg/archive-files": "github:aminya/archive-files#54ec59fad46aca736ac6feb6c7bb526528141b9d",
"@swc/jest": "^0.2.36",
"@types/cross-spawn": "^6.0.6",
Expand Down Expand Up @@ -115,6 +119,7 @@
"prettier-config-atomic": "^4.0.0",
"readme-md-generator": "^1.0.0",
"retry-as-promised": "^7.0.4",
"safe-stable-stringify": "^2.5.0",
"semver": "7.6.3",
"setup-apt": "workspace:*",
"setup-brew": "workspace:*",
Expand Down
150 changes: 150 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/gcc/assets-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { saveGitHubAssetList } from "../utils/github/fetch-assets.ts"

/**
* Generate the list of all releases of a GitHub repository and save it to a json file
*/
async function main() {
// https://github.com/brechtsanders/winlibs_mingw/releases
await saveGitHubAssetList("brechtsanders", "winlibs_mingw", "./src/gcc/github_brechtsanders_winlibs_mingw.json")
}

main().catch((err) => {
console.error(err)
process.exit(1)
})
64 changes: 17 additions & 47 deletions src/gcc/gcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,34 @@ import { setupMacOSSDK } from "../macos-sdk/macos-sdk.js"
import { hasDnf } from "../utils/env/hasDnf.js"
import { isArch } from "../utils/env/isArch.js"
import { isUbuntu } from "../utils/env/isUbuntu.js"
import { loadGitHubAssetList, matchAsset } from "../utils/github/load-assets.js"
import { extract7Zip } from "../utils/setup/extract.js"
import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setup/setupBin.js"
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"

interface MingwInfo {
releaseName: string
fileSuffix: string
}

// https://github.com/brechtsanders/winlibs_mingw/releases
const GccToMingwInfo = {
"13": { releaseName: "13.2.0-16.0.6-11.0.0-ucrt-r1", fileSuffix: "13.2.0-mingw-w64ucrt-11.0.0-r1" },
"13.2-ucrt": { releaseName: "13.2.0-16.0.6-11.0.0-ucrt-r1", fileSuffix: "13.2.0-mingw-w64ucrt-11.0.0-r1" },
"13.2-ucrt-mcf": { releaseName: "13.2.0mcf-16.0.6-11.0.1-ucrt-r2", fileSuffix: "13.2.0-mingw-w64ucrt-11.0.1-r2" },
"13.2-msvcrt": { releaseName: "13.2.0-16.0.6-11.0.1-msvcrt-r1", fileSuffix: "13.2.0-mingw-w64msvcrt-11.0.1-r1" },
"13.1-ucrt": { releaseName: "13.1.0posix-16.0.3-11.0.0-ucrt-r1", fileSuffix: "13.1.0-mingw-w64ucrt-11.0.0-r1" },
"13.1-msvcrt": { releaseName: "13.1.0posix-16.0.3-11.0.0-msvcrt-r1", fileSuffix: "13.1.0-mingw-w64msvcrt-11.0.0-r1" },
"12": { releaseName: "12.3.0-16.0.4-11.0.0-ucrt-r1", fileSuffix: "12.3.0-mingw-w64ucrt-11.0.0-r1" },
"12.3.0-ucrt": { releaseName: "12.3.0-16.0.4-11.0.0-ucrt-r1", fileSuffix: "12.3.0-mingw-w64ucrt-11.0.0-r1" },
"12.3.0-msvcrt": { releaseName: "12.3.0-16.0.4-11.0.0-msvcrt-r1", fileSuffix: "12.3.0-mingw-w64msvcrt-11.0.0-r1" },
"12.2.0-ucrt": { releaseName: "12.2.0-14.0.6-10.0.0-ucrt-r2", fileSuffix: "12.2.0-mingw-w64ucrt-10.0.0-r2" },
"12.2.0-msvcrt": { releaseName: "12.2.0-14.0.6-10.0.0-msvcrt-r2", fileSuffix: "12.2.0-mingw-w64msvcrt-10.0.0-r2" },
"12.1.0-ucrt": { releaseName: "12.1.0-14.0.4-10.0.0-ucrt-r2", fileSuffix: "12.1.0-mingw-w64ucrt-10.0.0-r2" },
"12.1.0-msvcrt": {
releaseName: "12.1.0-14.0.6-10.0.0-msvcrt-r3",
fileSuffix: "12.1.0-llvm-14.0.6-mingw-w64msvcrt-10.0.0-r3",
},
"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.5.0-11.0.1-msvcrt-r1", fileSuffix: "10.5.0-mingw-w64msvcrt-11.0.1-r1" },
"10.5.0-msvcrt": { releaseName: "10.5.0-11.0.1-msvcrt-r1", fileSuffix: "10.5.0-mingw-w64msvcrt-11.0.1-r1" },
"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 {
async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<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
const mingwAssets = await loadGitHubAssetList(
join(__dirname, "github_brechtsanders_winlibs_mingw.json"),
)
const asset = matchAsset(
mingwAssets,
{
version,
arch,
filterName: (name) => name.endsWith(".7z"),
},
)

return {
binRelativeDir: "bin/",
binFileName: addExeExt("g++"),
extractedFolderName: "mingw64",
extractFunction: extract7Zip,
url:
`https://github.com/brechtsanders/winlibs_mingw/releases/download/${mingwInfo.releaseName}/winlibs-${mingwArch}-posix-${exceptionModel}-gcc-${mingwInfo.fileSuffix}.7z`,
url: `https://github.com/brechtsanders/winlibs_mingw/releases/download/${asset.tag}/${asset.name}`,
}
}
default:
Expand Down Expand Up @@ -110,7 +80,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
{ name: "libstdc++-devel" },
])
} else if (isUbuntu()) {
if (version === undefined) {
if (version === "") {
// the default version
installationInfo = await installAptPack([{ name: "gcc" }, { name: "g++" }])
} else {
Expand All @@ -136,7 +106,7 @@ export async function setupGcc(version: string, setupDir: string, arch: string,
if (isArch()) {
await setupPacmanPack("gcc-multilib", version)
} else if (isUbuntu()) {
if (version === undefined) {
if (version === "") {
// the default version
await installAptPack([{ name: "gcc-multilib" }])
} else {
Expand Down
1 change: 1 addition & 0 deletions src/gcc/github_brechtsanders_winlibs_mingw.json

Large diffs are not rendered by default.

Loading

0 comments on commit 11fad2b

Please sign in to comment.