Skip to content

Commit 1f6f832

Browse files
authored
Merge pull request #296 from aminya/llvm-urls [skip ci]
fix: avoid old LLVM release HTTP redirects + fix libtinfo5 installation on Ubuntu 24
2 parents fb2a9a2 + 2a2a8eb commit 1f6f832

File tree

8 files changed

+50
-7
lines changed

8 files changed

+50
-7
lines changed

dist/legacy/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/legacy/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.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.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/llvm/__tests__/llvm.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ describe("setup-llvm", () => {
8282
execaSync(main_exe, { cwd: dirname, stdio: "inherit" })
8383
})
8484

85+
it("should setup LLVM 5 from llvm.org", async () => {
86+
const { binDir } = await setupLLVM("5", directory, process.arch)
87+
await testBin("clang++", ["--version"], binDir)
88+
89+
expect(process.env.CC?.includes("clang")).toBeTruthy()
90+
expect(process.env.CXX?.includes("clang++")).toBeTruthy()
91+
92+
// test compilation
93+
const file = join(dirname, "main.cpp")
94+
const main_exe = join(dirname, addExeExt("main"))
95+
execaSync("clang++", ["-std=c++17", file, "-o", main_exe], { cwd: dirname })
96+
if (process.platform !== "win32") {
97+
await chmod(main_exe, "755")
98+
}
99+
execaSync(main_exe, { cwd: dirname, stdio: "inherit" })
100+
})
101+
85102
it("should setup clang-format", async () => {
86103
const osVersion = await ubuntuVersion()
87104
const { binDir } = await setupClangFormat(getVersion("llvm", "true", osVersion), directory, process.arch)

src/llvm/assets-list.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ async function main() {
2121
for (let major = 1; major <= 9; major++) {
2222
for (let minor = 0; minor <= 9; minor++) {
2323
for (let patch = 0; patch <= 9; patch++) {
24-
const version = `${major}.${minor}.${patch}`
24+
const version = (major >= 3 && minor >= 4 && patch >= 1)
25+
? `${major}.${minor}`
26+
: `${major}.${minor}.${patch}`
2527
yield [version, `https://releases.llvm.org/${version}`] as [string, string]
2628
}
2729
}

src/llvm/llvm.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import { tmpdir } from "os"
12
import path, { delimiter, join } from "path"
23
import { fileURLToPath } from "url"
4+
import { execRootSync } from "admina"
35
import { GITHUB_ACTIONS } from "ci-info"
46
import { info, warning } from "ci-log"
57
import { addEnv } from "envosman"
68
import memoize from "memoizee"
9+
import { DownloaderHelper } from "node-downloader-helper"
710
import { pathExists } from "path-exists"
811
import { addExeExt } from "patha"
912
import { addUpdateAlternativesToRc, installAptPack } from "setup-apt"
1013
import { rcOptions } from "../cli-options.js"
1114
import { setupGcc } from "../gcc/gcc.js"
1215
import { setupMacOSSDK } from "../macos-sdk/macos-sdk.js"
16+
import { arm64, x86_64 } from "../utils/env/arch.js"
1317
import { hasDnf } from "../utils/env/hasDnf.js"
1418
import { isArch } from "../utils/env/isArch.js"
1519
import { isUbuntu } from "../utils/env/isUbuntu.js"
@@ -87,7 +91,27 @@ function majorLLVMVersion(version: string) {
8791
async function llvmBinaryDeps_(majorVersion: number) {
8892
if (isUbuntu()) {
8993
if (majorVersion <= 10) {
90-
await installAptPack([{ name: "libtinfo5" }])
94+
try {
95+
await installAptPack([{ name: "libtinfo5" }])
96+
} catch (err) {
97+
// Manually install libtinfo5 if the package is not available
98+
info(`Failed to install libtinfo5 ${err}\nManually installing the package`)
99+
const arch = x86_64.includes(process.arch)
100+
? "amd64"
101+
: arm64.includes(process.arch)
102+
? "arm64"
103+
: process.arch
104+
105+
const fileName = `libtinfo5_6.3-2ubuntu0.1_${arch}.deb`
106+
const url = `http://launchpadlibrarian.net/666971015/${fileName}`
107+
const dl = new DownloaderHelper(url, tmpdir(), { fileName })
108+
dl.on("error", (dlErr) => {
109+
throw new Error(`Failed to download ${url}: ${dlErr}`)
110+
})
111+
await dl.start()
112+
// Install the downloaded package via dpkg
113+
execRootSync("dpkg", ["-i", join(tmpdir(), fileName)])
114+
}
91115
} else {
92116
await installAptPack([{ name: "libtinfo-dev" }])
93117
}

src/llvm/llvm_url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function getLLVMAssetURL(platform: string, arch: string, version: s
7171
)
7272

7373
if (websiteAsset !== undefined) {
74-
return `https://llvm.org/releases/${websiteAsset.tag}/${websiteAsset.name}`
74+
return `https://releases.llvm.org/${websiteAsset.tag}/${websiteAsset.name}`
7575
}
7676

7777
throw new Error(`No asset found for version ${version} matching ${keywords} and ${optionalKeywords}`)

0 commit comments

Comments
 (0)