Skip to content

Commit

Permalink
musl patches [v4] (#15066)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored Nov 12, 2024
1 parent 2b9abc2 commit 7979580
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 12 deletions.
5 changes: 5 additions & 0 deletions cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -901,6 +902,10 @@ else()
-Wl,--wrap=statx
)
endif()
else()
set(ARCH_WRAP_FLAGS
)
endif()

if (NOT IS_MUSL)
set(ABI_WRAP_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/compile_target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/js/thirdparty/detect-libc.musl.js
Original file line number Diff line number Diff line change
@@ -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,
};
18 changes: 18 additions & 0 deletions test/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand All @@ -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.
Expand Down Expand Up @@ -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");
}
}
10 changes: 5 additions & 5 deletions test/js/bun/spawn/spawn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/js/node/process/call-raise.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/mkfifo.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 7979580

Please sign in to comment.