fix(update): detect active Linux libc
This commit is contained in:
@@ -765,14 +765,33 @@ async function pruneBunCacheAfterGlobalInstall(): Promise<BunInstallCachePruneRe
|
||||
/**
|
||||
* Detect a musl-libc Linux host (Alpine, Void-musl) so self-update replaces a
|
||||
* musl binary with the musl release asset instead of the glibc build, which
|
||||
* would fail to start on the next run. Mirrors the detection in
|
||||
* scripts/install.sh.
|
||||
* would fail to start on the next run. The loader file alone is not sufficient:
|
||||
* glibc hosts may have musl installed for cross-compilation.
|
||||
*/
|
||||
function isMuslLinux(): boolean {
|
||||
if (process.platform !== "linux") return false;
|
||||
if (fs.existsSync("/etc/alpine-release")) return true;
|
||||
const loaderArch = process.arch === "arm64" ? "aarch64" : "x86_64";
|
||||
return fs.existsSync(`/lib/ld-musl-${loaderArch}.so.1`);
|
||||
interface MuslDetectionOptions {
|
||||
platform?: NodeJS.Platform;
|
||||
alpineRelease?: boolean;
|
||||
lddOutput?: string;
|
||||
}
|
||||
|
||||
function detectLddOutput(): string | undefined {
|
||||
try {
|
||||
const result = Bun.spawnSync(["ldd", "--version"], { stdout: "pipe", stderr: "pipe" });
|
||||
return `${result.stdout.toString("utf-8")}\n${result.stderr.toString("utf-8")}`;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function isMuslLinux(options: MuslDetectionOptions = {}): boolean {
|
||||
if ((options.platform ?? process.platform) !== "linux") return false;
|
||||
if (options.alpineRelease ?? fs.existsSync("/etc/alpine-release")) return true;
|
||||
return /\bmusl\b/i.test(options.lddOutput ?? detectLddOutput() ?? "");
|
||||
}
|
||||
|
||||
/** Test seam for libc detection. */
|
||||
export function isMuslLinuxForTest(options: Required<MuslDetectionOptions>): boolean {
|
||||
return isMuslLinux(options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user