Skip to content

Commit 05d55cb

Browse files
committed
fix: select the default llvm version based on ubuntu version
1 parent bd5d402 commit 05d55cb

File tree

7 files changed

+100
-2
lines changed

7 files changed

+100
-2
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.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
"@actions/io": "^1.1.2",
3939
"@actions/tool-cache": "^1.7.2",
4040
"execa": "^5.1.1",
41+
"make-synchronous": "^1.0.0",
4142
"mri": "^1.2.0",
4243
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#9f672c1",
4344
"numerous": "1.0.3",
4445
"semver": "7.3.7",
4546
"setup-python": "github:actions/setup-python#v3.1.2",
4647
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
48+
"ubuntu-version": "^2.0.0",
4749
"untildify": "^4.0.0",
4850
"which": "^2.0.2"
4951
},

pnpm-lock.yaml

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { warning } from "./utils/io/io"
2+
import { ubuntuVersion } from "./utils/env/ubuntu_version"
3+
14
const DefaultVersions: Record<string, string> = {
25
llvm: "13.0.0", // https://github.com/llvm/llvm-project/releases
36
clangtidy: "13.0.0",
@@ -14,6 +17,8 @@ const DefaultVersions: Record<string, string> = {
1417
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
1518
}
1619

20+
let ubuntuVersionCached: number[] | null = null
21+
1722
/** Get the default version if passed true or undefined, otherwise return the version itself */
1823
export function getVersion(name: string, version: string | undefined) {
1924
if (version === "true" || (version === undefined && name in DefaultVersions)) {
@@ -22,3 +27,24 @@ export function getVersion(name: string, version: string | undefined) {
2227
return version ?? ""
2328
}
2429
}
30+
31+
export function defaultLLVMVersion(name: string) {
32+
if (["llvm", "clangtidy", "clangformat"].includes(name)) {
33+
if (process.platform === "linux") {
34+
try {
35+
// get the version if not already done
36+
ubuntuVersionCached = ubuntuVersionCached ?? ubuntuVersion()
37+
} catch (err) {
38+
warning((err as Error).toString())
39+
return DefaultVersions[name]
40+
}
41+
// choose the default version for llvm based on ubuntu
42+
if (ubuntuVersionCached !== null) {
43+
if ([20, 18, 16].includes(ubuntuVersionCached[0]) && ubuntuVersionCached[1] === 4) {
44+
return `-13.0.0-x86_64-linux-gnu-ubuntu-${ubuntuVersionCached[0]}.0${ubuntuVersionCached[1]}`
45+
}
46+
}
47+
}
48+
}
49+
return DefaultVersions[name]
50+
}

src/llvm/llvm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ const UBUNTU_RC: Map<string, string> = new Map()
124124
*
125125
* https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.1 or https://releases.llvm.org/14.0.1
126126
*/
127+
// TODO change based on ubuntu version
127128
const UBUNTU_SUFFIX_MAP: { [key: string]: string } = {
128129
"3.5.0": "-ubuntu-14.04",
129130
"3.5.1": "",

src/utils/env/ubuntu_version.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getUbuntuVersion } from "ubuntu-version"
2+
import makeSynchronous from "make-synchronous"
3+
4+
export function ubuntuVersion(): number[] | null {
5+
if (process.platform === "linux") {
6+
const versionSplitted = makeSynchronous(getUbuntuVersion)()
7+
8+
if (versionSplitted.length === 0) {
9+
throw new Error("Failed to get the ubuntu major version.")
10+
}
11+
12+
return versionSplitted
13+
} else {
14+
return null
15+
}
16+
}

0 commit comments

Comments
 (0)