musl patches [v4] (#15066)

This commit is contained in:
Meghan Denny
2024-11-11 19:23:58 -08:00
committed by GitHub
parent 2b9abc20da
commit 797958082c
9 changed files with 73 additions and 12 deletions

View File

@@ -879,6 +879,7 @@ else()
set(LLD_NAME lld-${LLVM_VERSION_MAJOR})
endif()
if (NOT IS_MUSL)
if (IS_ARM64)
set(ARCH_WRAP_FLAGS
-Wl,--wrap=fcntl64
@@ -901,6 +902,10 @@ else()
-Wl,--wrap=statx
)
endif()
else()
set(ARCH_WRAP_FLAGS
)
endif()
if (NOT IS_MUSL)
set(ABI_WRAP_FLAGS

View File

@@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION 73b551e25d97e463e8e2c86cb819b8639fcbda06)
set(WEBKIT_VERSION 3bc4abf2d5875baf500b4687ef869987f6d19e00)
endif()
if(WEBKIT_LOCAL)

View File

@@ -2472,7 +2472,7 @@ pub const ModuleLoader = struct {
return jsSyntheticModule(.@"bun:sql", specifier);
},
.@"bun:sqlite" => return jsSyntheticModule(.@"bun:sqlite", specifier),
.@"detect-libc" => return jsSyntheticModule(if (Environment.isLinux) .@"detect-libc/linux" else .@"detect-libc", specifier),
.@"detect-libc" => return jsSyntheticModule(if (!Environment.isLinux) .@"detect-libc" else if (!Environment.isMusl) .@"detect-libc/linux" else .@"detect-libc/musl", specifier),
.@"node:assert" => return jsSyntheticModule(.@"node:assert", specifier),
.@"node:assert/strict" => return jsSyntheticModule(.@"node:assert/strict", specifier),
.@"node:async_hooks" => return jsSyntheticModule(.@"node:async_hooks", specifier),

View File

@@ -19,7 +19,7 @@ version: bun.Semver.Version = .{
.minor = @truncate(Environment.version.minor),
.patch = @truncate(Environment.version.patch),
},
libc: Libc = .default,
libc: Libc = if (!Environment.isMusl) .default else .musl,
const Libc = enum {
/// The default libc for the target

38
src/js/thirdparty/detect-libc.musl.js vendored Normal file
View File

@@ -0,0 +1,38 @@
// Hardcoded module "detect-libc" for linux
function family() {
return Promise.resolve(familySync());
}
function familySync() {
return MUSL;
}
const GLIBC = "glibc";
const MUSL = "musl";
function version() {
return Promise.resolve(versionSync());
}
function versionSync() {
return "1.2.5";
}
function isNonGlibcLinuxSync() {
return true;
}
function isNonGlibcLinux() {
return Promise.resolve(isNonGlibcLinuxSync());
}
export default {
GLIBC,
MUSL,
family,
familySync,
isNonGlibcLinux,
isNonGlibcLinuxSync,
version,
versionSync,
};

View File

@@ -5,6 +5,7 @@ import { readFile, readlink, writeFile } from "fs/promises";
import fs, { closeSync, openSync } from "node:fs";
import os from "node:os";
import { dirname, isAbsolute, join } from "path";
import detect_libc from "detect-libc";
type Awaitable<T> = T | Promise<T>;
@@ -18,6 +19,7 @@ export const isIntelMacOS = isMacOS && process.arch === "x64";
export const isDebug = Bun.version.includes("debug");
export const isCI = process.env.CI !== undefined;
export const isBuildKite = process.env.BUILDKITE === "true";
export const libc_family = detect_libc.familySync();
// Use these to mark a test as flaky or broken.
// This will help us keep track of these tests.
@@ -1365,3 +1367,19 @@ export function waitForFileToExist(path: string, interval: number) {
sleepSync(interval);
}
}
export function libcPathForDlopen() {
switch (process.platform) {
case "linux":
switch (libc_family) {
case "glibc":
return "libc.so.6";
case "musl":
return "/usr/lib/libc.so";
}
case "darwin":
return "libc.dylib";
default:
throw new Error("TODO");
}
}

View File

@@ -152,7 +152,7 @@ for (let [gcTick, label] of [
it("nothing to stdout and sleeping doesn't keep process open 4ever", async () => {
const proc = spawn({
cmd: [shellExe(), "-c", "sleep", "0.1"],
cmd: [shellExe(), "-c", "sleep 0.1"],
});
gcTick();
for await (const _ of proc.stdout) {
@@ -366,7 +366,7 @@ for (let [gcTick, label] of [
it("kill(SIGKILL) works", async () => {
const process = spawn({
cmd: [shellExe(), "-c", "sleep", "1000"],
cmd: [shellExe(), "-c", "sleep 1000"],
stdout: "pipe",
});
gcTick();
@@ -377,7 +377,7 @@ for (let [gcTick, label] of [
it("kill() works", async () => {
const process = spawn({
cmd: [shellExe(), "-c", "sleep", "1000"],
cmd: [shellExe(), "-c", "sleep 1000"],
stdout: "pipe",
});
gcTick();
@@ -551,7 +551,7 @@ if (!process.env.BUN_FEATURE_FLAG_FORCE_WAITER_THREAD && isPosix && !isMacOS) {
}
describe("spawn unref and kill should not hang", () => {
const cmd = [shellExe(), "-c", "sleep", "0.001"];
const cmd = [shellExe(), "-c", "sleep 0.001"];
it("kill and await exited", async () => {
const promises = new Array(10);
@@ -635,7 +635,7 @@ async function runTest(sleep: string, order = ["sleep", "kill", "unref", "exited
console.log("running", order.join(","), "x 100");
for (let i = 0; i < (isWindows ? 10 : 100); i++) {
const proc = spawn({
cmd: [shellExe(), "-c", "sleep", sleep],
cmd: [shellExe(), "-c", `sleep ${sleep}`],
stdout: "ignore",
stderr: "ignore",
stdin: "ignore",

View File

@@ -1,10 +1,10 @@
import { dlopen } from "bun:ffi";
import { libcPathForDlopen } from "harness";
var lazyRaise;
export function raise(signal) {
if (!lazyRaise) {
const suffix = process.platform === "darwin" ? "dylib" : "so.6";
lazyRaise = dlopen(`libc.${suffix}`, {
lazyRaise = dlopen(libcPathForDlopen(), {
raise: {
args: ["int"],
returns: "int",

View File

@@ -1,10 +1,10 @@
import { dlopen, ptr } from "bun:ffi";
import { libcPathForDlopen } from "harness";
var lazyMkfifo: any;
export function mkfifo(path: string, permissions: number = 0o666): void {
if (!lazyMkfifo) {
const suffix = process.platform === "darwin" ? "dylib" : "so.6";
lazyMkfifo = dlopen(`libc.${suffix}`, {
lazyMkfifo = dlopen(libcPathForDlopen(), {
mkfifo: {
args: ["ptr", "i32"],
returns: "i32",