fix(llvm): set LLVM_CPPFLAGS/LDFLAGS instead of CPPFLAGS/LDFLAGS

This commit is contained in:
Amin Yahyaabadi 2024-09-17 12:00:18 -07:00
parent 691fa792a8
commit 22ad634883
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
22 changed files with 670 additions and 665 deletions

View File

@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.1/schema.json",
"files": {
"ignore": [
"**/node_modules/**",
@ -33,8 +33,18 @@
"suspicious": {
"noConfusingVoidType": "off"
},
"nursery": {
"useImportExtensions": "warn"
"correctness": {
"useImportExtensions": {
"level": "error",
"options": {
"suggestedExtensions": {
"ts": {
"component": "js",
"module": "js"
}
}
}
}
}
}
},

File diff suppressed because one or more lines are too long

2
dist/legacy/assets/hdi-HMjVj8JE.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/modern/assets/hdi-DCb6yS8z.mjs vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -61,7 +61,7 @@
"@actions/tool-cache": "^2.0.1",
"@aminya/minijson": "1.0.3",
"@babel/core": "^7.25.2",
"@biomejs/biome": "^1.8.3",
"@biomejs/biome": "^1.9.1",
"@iarna/toml": "^2.2.5",
"@liuli-util/vite-plugin-node": "^0.9.0",
"@octokit/core": "^6.1.2",
@ -77,7 +77,7 @@
"@types/escape-quotes": "~1.0.0",
"@types/eslint": "^8.56.12",
"@types/iarna__toml": "~2.0.5",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.13",
"@types/memoizee": "^0.4.11",
"@types/node": "^12.20.55",
"@types/semver": "^7.5.8",
@ -89,14 +89,14 @@
"ci-log": "workspace:*",
"cross-env": "7.0.3",
"cross-spawn": "^7.0.3",
"cspell": "^8.14.2",
"cspell": "^8.14.3",
"diagnostics_channel": "^1.1.0",
"dprint": "^0.47.2",
"envosman": "workspace:*",
"escape-path-with-spaces": "^1.0.2",
"escape-quotes": "^1.0.2",
"escape-string-regexp": "^5.0.0",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-config-atomic": "^1.22.1",
"exec-powershell": "workspace:*",
"execa": "^7.2.0",
@ -110,7 +110,7 @@
"msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd",
"node-downloader-helper": "2.1.9",
"npm-check-updates": "^17.1.1",
"npm-run-all2": "^6.2.2",
"npm-run-all2": "^6.2.3",
"numerous": "1.0.3",
"p-timeout": "^6.1.2",
"path-exists": "^5.0.0",
@ -119,7 +119,7 @@
"prettier-config-atomic": "^4.0.0",
"readme-md-generator": "^1.0.0",
"retry-as-promised": "^7.0.4",
"rollup": "^4.21.2",
"rollup": "^4.21.3",
"safe-stable-stringify": "^2.5.0",
"semver": "7.6.3",
"setup-apt": "workspace:*",
@ -127,17 +127,17 @@
"setup-python": "github:aminya/setup-python#a783db655c6e40317e2c0c96f9d162d9c9f4a751",
"shx": "0.3.4",
"simple-update-notifier": "^2.0.0",
"terser": "^5.31.6",
"terser": "^5.33.0",
"terser-config-atomic": "^1.0.0",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
"ts-node": "^10.9.2",
"ts-readme": "^1.1.3",
"turbo": "2.1.1",
"typescript": "^5.5.4",
"typescript": "^5.6.2",
"ubuntu-version": "^2.0.0",
"untildify-user": "workspace:*",
"util.types": "^0.0.2",
"vite": "^5.4.3",
"vite": "^5.4.6",
"vite-plugin-babel": "^1.2.0",
"web-streams-polyfill": "^4.0.0",
"which": "^4.0.0"

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,6 @@ export async function installCompiler(
setupCppDir: string,
arch: string,
successMessages: string[],
hasLLVM: boolean,
errorMessages: string[],
) {
try {
@ -67,11 +66,6 @@ export async function installCompiler(
? await setupMingw(gccVersion, join(setupCppDir, "gcc"), arch)
: await setupGcc(gccVersion, join(setupCppDir, "gcc"), arch)
if (hasLLVM) {
// remove back the added CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "", rcOptions)
}
await activateGcovGCC(gccVersion)
successMessages.push(getSuccessMessage("gcc", installationInfo))
@ -90,11 +84,6 @@ export async function installCompiler(
arch,
)
if (hasLLVM) {
// remove the CPPFLAGS of LLVM that include the LLVM headers
await addEnv("CPPFLAGS", "", rcOptions)
}
successMessages.push(getSuccessMessage("msvc", installationInfo))
break
}

View File

@ -22,9 +22,8 @@ export async function installTool(
timeout: number = DEFAULT_TIMEOUT,
) {
startGroup(`Installing ${tool} ${version}`)
let hasLLVM = false
try {
hasLLVM = await pTimeout(installToolImpl(tool, version, osVersion, arch, setupCppDir, successMessages), {
await pTimeout(installToolImpl(tool, version, osVersion, arch, setupCppDir, successMessages), {
milliseconds: timeout,
message: `Timeout while installing ${tool} ${version}. You can increase the timeout from options`,
})
@ -37,7 +36,6 @@ export async function installTool(
errorMessages.push(`${tool} failed to install`)
}
endGroup()
return hasLLVM
}
async function installToolImpl(
@ -48,7 +46,6 @@ async function installToolImpl(
setupCppDir: string,
successMessages: string[],
) {
// eslint-disable-next-line no-param-reassign
const hasLLVM = ["llvm", "clangformat", "clangtidy"].includes(tool)
let installationInfo: InstallationInfo | undefined | void
@ -72,5 +69,4 @@ async function installToolImpl(
}
// preparing a report string
successMessages.push(getSuccessMessage(tool, installationInfo))
return hasLLVM
}

View File

@ -18,6 +18,7 @@ import { type InstallationInfo, setupBin } from "../utils/setup/setupBin.js"
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
import { semverCoerceIfInvalid } from "../utils/setup/version.js"
import { quoteIfHasSpace } from "../utils/std/index.js"
import { getVersion } from "../versions/versions.js"
import { LLVMPackages, setupLLVMApt } from "./llvm_installer.js"
import { getLLVMPackageInfo } from "./llvm_url.js"
@ -26,11 +27,11 @@ const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURL
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installationInfo = await setupLLVMWithoutActivation(version, setupDir, arch)
await activateLLVM(installationInfo.installDir ?? setupDir)
await activateLLVM(installationInfo.installDir ?? setupDir, version)
return installationInfo
}
async function setupLLVMWithoutActivation_raw(version: string, setupDir: string, arch: string) {
async function setupLLVMWithoutActivation_(version: string, setupDir: string, arch: string) {
// install LLVM
const [installationInfo, _1] = await Promise.all([
setupLLVMOnly(version, setupDir, arch),
@ -42,7 +43,7 @@ async function setupLLVMWithoutActivation_raw(version: string, setupDir: string,
return installationInfo
}
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_raw, { promise: true })
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_, { promise: true })
/**
* Setup clang-format
@ -64,8 +65,7 @@ async function setupLLVMOnly(
arch: string,
packages: LLVMPackages = LLVMPackages.All,
) {
const coeredVersion = semverCoerceIfInvalid(version)
const majorVersion = Number.parseInt(coeredVersion.split(".")[0], 10)
const majorVersion = majorLLVMVersion(version)
try {
if (isUbuntu()) {
return await setupLLVMApt(majorVersion, packages)
@ -79,7 +79,12 @@ async function setupLLVMOnly(
return installationInfo
}
async function llvmBinaryDeps_raw(majorVersion: number) {
function majorLLVMVersion(version: string) {
const coeredVersion = semverCoerceIfInvalid(version)
return Number.parseInt(coeredVersion.split(".")[0], 10)
}
async function llvmBinaryDeps_(majorVersion: number) {
if (isUbuntu()) {
if (majorVersion <= 10) {
await installAptPack([{ name: "libtinfo5" }])
@ -96,36 +101,45 @@ async function llvmBinaryDeps_raw(majorVersion: number) {
])
}
}
const llvmBinaryDeps = memoize(llvmBinaryDeps_raw, { promise: true })
const llvmBinaryDeps = memoize(llvmBinaryDeps_, { promise: true })
async function setupLLVMDeps_raw(arch: string) {
async function setupLLVMDeps_(arch: string) {
if (process.platform === "linux") {
// using llvm requires ld, an up to date libstdc++, etc. So, install gcc first,
// but with a lower priority than the one used by activateLLVM()
await setupGcc(getVersion("gcc", undefined, await ubuntuVersion()), "", arch, 40)
}
}
const setupLLVMDeps = memoize(setupLLVMDeps_raw, { promise: true })
const setupLLVMDeps = memoize(setupLLVMDeps_, { promise: true })
export async function activateLLVM(directory: string) {
export async function activateLLVM(directory: string, version: string) {
const ld = process.env.LD_LIBRARY_PATH ?? ""
const dyld = process.env.DYLD_LIBRARY_PATH ?? ""
const llvmMajor = majorLLVMVersion(version)
const actPromises: Promise<void>[] = [
// compiler paths
addEnv("CC", addExeExt(`${directory}/bin/clang`), rcOptions),
addEnv("CXX", addExeExt(`${directory}/bin/clang++`), rcOptions),
// the output of this action
addEnv("LLVM_PATH", directory, rcOptions),
// Setup LLVM as the compiler
addEnv("LD_LIBRARY_PATH", `${directory}/lib${delimiter}${ld}`, rcOptions),
addEnv("DYLD_LIBRARY_PATH", `${directory}/lib${delimiter}${dyld}`, rcOptions),
addEnv("LD_LIBRARY_PATH", `${ld}${delimiter}${directory}/lib`, rcOptions),
addEnv("DYLD_LIBRARY_PATH", `${dyld}${delimiter}${directory}/lib`, rcOptions),
// compiler flags
addEnv("LDFLAGS", `-L"${directory}/lib"`, rcOptions),
addEnv("CPPFLAGS", `-I"${directory}/include"`, rcOptions),
addEnv("LLVM_LDFLAGS", `-L${quoteIfHasSpace(`${directory}/lib`)}`, rcOptions),
addEnv("LLVM_CPPFLAGS", `-I${quoteIfHasSpace(`${directory}/include`)}`, rcOptions),
// compiler paths
addEnv("CC", addExeExt(`${directory}/bin/clang`), rcOptions),
addEnv("CXX", addExeExt(`${directory}/bin/clang++`), rcOptions),
// CPATH
await pathExists(`${directory}/lib/clang/${version}/include`)
? addEnv("LLVM_CPATH", `${directory}/lib/clang/${version}/include`, rcOptions)
: await pathExists(`${directory}/lib/clang/${llvmMajor}/include`)
? addEnv("LLVM_CPATH", `${directory}/lib/clang/${llvmMajor}/include`, rcOptions)
: Promise.resolve(),
addEnv("LIBRARY_PATH", `${directory}/lib`, rcOptions),
@ -133,16 +147,6 @@ export async function activateLLVM(directory: string) {
setupMacOSSDK(),
]
// TODO Causes issues with clangd
// TODO Windows builds fail with llvm's CPATH
// if (process.platform !== "win32") {
// if (await pathExists(`${directory}/lib/clang/${version}/include`)) {
// promises.push(addEnv("CPATH", `${directory}/lib/clang/${version}/include`, rcOptions))
// } else if (await pathExists(`${directory}/lib/clang/${llvmMajor}/include`)) {
// promises.push(addEnv("CPATH", `${directory}/lib/clang/${llvmMajor}/include`, rcOptions))
// }
// }
if (isUbuntu()) {
const priority = 60
actPromises.push(

View File

@ -293,7 +293,7 @@ async function ensurePipUpgrade(foundPython: string) {
return false
}
async function addPythonBaseExecPrefix_raw(python: string) {
async function addPythonBaseExecPrefix_(python: string) {
const dirs: string[] = []
// detection based on the platform
@ -317,4 +317,4 @@ async function addPythonBaseExecPrefix_raw(python: string) {
*
* The answer is cached for subsequent calls
*/
export const addPythonBaseExecPrefix = memoize(addPythonBaseExecPrefix_raw, { promise: true })
export const addPythonBaseExecPrefix = memoize(addPythonBaseExecPrefix_, { promise: true })

View File

@ -66,9 +66,6 @@ async function main(args: string[]): Promise<number> {
await setupPacmanPack("python-pygments")
}
/** Used to unset CPPFLAGS of LLVM when other compilers are used as the main compiler */
let hasLLVM = false
// loop over the tools and run their setup function
let failedFast = false
@ -89,7 +86,7 @@ async function main(args: string[]): Promise<number> {
// running the setup function for this tool
time1 = Date.now()
// eslint-disable-next-line no-await-in-loop
hasLLVM = await installTool(
await installTool(
tool,
version,
osVersion,
@ -109,7 +106,7 @@ async function main(args: string[]): Promise<number> {
const maybeCompiler = opts.compiler
if (maybeCompiler !== undefined) {
const time1Compiler = Date.now()
await installCompiler(maybeCompiler, osVersion, setupCppDir, arch, successMessages, hasLLVM, errorMessages)
await installCompiler(maybeCompiler, osVersion, setupCppDir, arch, successMessages, errorMessages)
const time2Compiler = Date.now()
info(`took ${timeFormatter.format(time1Compiler, time2Compiler) || "0 seconds"}`)
}

View File

@ -6,7 +6,7 @@ import memoize from "memoizee"
*
* @returns {number[]} - The macOS version as an array of numbers
*/
function macosVersion_raw() {
function macosVersion_() {
if (process.platform !== "darwin") {
return []
}
@ -14,4 +14,4 @@ function macosVersion_raw() {
const { version } = macosRelease()
return version.split(".").map((v) => Number.parseInt(v, 10))
}
export const macosVersion = memoize(macosVersion_raw)
export const macosVersion = memoize(macosVersion_)

View File

@ -6,7 +6,7 @@ import { getUbuntuVersion } from "ubuntu-version"
import which from "which"
import { isUbuntu } from "./isUbuntu.js"
async function ubuntuVersion_raw(): Promise<number[] | null> {
async function ubuntuVersion_(): Promise<number[] | null> {
try {
if (isUbuntu()) {
try {
@ -34,7 +34,7 @@ async function ubuntuVersion_raw(): Promise<number[] | null> {
}
/** Detect Ubuntu version */
export const ubuntuVersion = memoize(ubuntuVersion_raw, { promise: true })
export const ubuntuVersion = memoize(ubuntuVersion_, { promise: true })
/** Detect Ubuntu version using os.version() for Ubuntu based distros */
function detectUsingOsVersion() {

View File

@ -97,7 +97,7 @@ export async function hasPipx(givenPython: string) {
return (await execa(givenPython, ["-m", "pipx", "--help"], { stdio: "ignore", reject: false })).exitCode === 0
}
async function getPipxHome_raw() {
async function getPipxHome_() {
let pipxHome = process.env.PIPX_HOME
if (pipxHome !== undefined) {
return pipxHome
@ -130,9 +130,9 @@ async function getPipxHome_raw() {
await mkdirp(join(pipxHome, "venv"))
return pipxHome
}
const getPipxHome = memoize(getPipxHome_raw, { promise: true })
const getPipxHome = memoize(getPipxHome_, { promise: true })
async function getPipxBinDir_raw() {
async function getPipxBinDir_() {
if (process.env.PIPX_BIN_DIR !== undefined) {
return process.env.PIPX_BIN_DIR
}
@ -142,16 +142,16 @@ async function getPipxBinDir_raw() {
await mkdirp(pipxBinDir)
return pipxBinDir
}
const getPipxBinDir = memoize(getPipxBinDir_raw, { promise: true })
const getPipxBinDir = memoize(getPipxBinDir_, { promise: true })
async function getPython_raw(): Promise<string> {
async function getPython_(): Promise<string> {
const pythonBin = (await setupPython(getVersion("python", undefined, await ubuntuVersion()), "", process.arch)).bin
if (pythonBin === undefined) {
throw new Error("Python binary was not found")
}
return pythonBin
}
const getPython = memoize(getPython_raw, { promise: true })
const getPython = memoize(getPython_, { promise: true })
async function pipHasPackage(python: string, name: string) {
const result = await execa(python, ["-m", "pip", "-qq", "index", "versions", name], {

View File

@ -1,3 +1,7 @@
export function unique(dirs: string[]) {
return [...new Set(dirs)]
}
export function quoteIfHasSpace(str: string, quoteChar = "\"") {
return str.includes(" ") ? `${quoteChar}${str}${quoteChar}` : str
}