Skip to content

Commit 39aef3e

Browse files
author
Opencoder
committed
feat: implement musl libc detection for native module
1 parent 2bd91b6 commit 39aef3e

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ test-*.cjs
5252
test-*.mjs
5353

5454
# Benchmark results
55-
benchmark-results/
55+
benchmark-results/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"aarch64-apple-darwin",
6060
"x86_64-unknown-linux-gnu",
6161
"aarch64-unknown-linux-gnu",
62+
"x86_64-unknown-linux-musl",
63+
"aarch64-unknown-linux-musl",
6264
"x86_64-pc-windows-msvc"
6365
]
6466
},
@@ -99,5 +101,4 @@
99101
"optional": true
100102
}
101103
}
102-
103-
}
104+
}

src/native/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,36 @@ function getNativeBinding() {
66
const platform = os.platform();
77
const arch = os.arch();
88

9+
// Detect musl vs glibc on Linux
10+
const isMusl = () => {
11+
try {
12+
const lddVersion = require("child_process").execSync("ldd --version", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] });
13+
return lddVersion.includes("musl") || lddVersion.includes("MUSL");
14+
} catch {
15+
// Fallback: check if /etc/alpine-release exists (Alpine = musl)
16+
try {
17+
require("fs").accessSync("/etc/alpine-release");
18+
return true;
19+
} catch {
20+
return false;
21+
}
22+
}
23+
};
24+
25+
// Cache the result
26+
const musl = isMusl();
27+
const libc = musl ? "musl" : "gnu";
28+
929
let bindingName: string;
1030

1131
if (platform === "darwin" && arch === "arm64") {
1232
bindingName = "codebase-index-native.darwin-arm64.node";
1333
} else if (platform === "darwin" && arch === "x64") {
1434
bindingName = "codebase-index-native.darwin-x64.node";
1535
} else if (platform === "linux" && arch === "x64") {
16-
bindingName = "codebase-index-native.linux-x64-gnu.node";
36+
bindingName = `codebase-index-native.linux-x64-${libc}.node`;
1737
} else if (platform === "linux" && arch === "arm64") {
18-
bindingName = "codebase-index-native.linux-arm64-gnu.node";
38+
bindingName = `codebase-index-native.linux-arm64-${libc}.node`;
1939
} else if (platform === "win32" && arch === "x64") {
2040
bindingName = "codebase-index-native.win32-x64-msvc.node";
2141
} else {

src/tools/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export const index_codebase: ToolDefinition = tool({
6565
async execute(args, context) {
6666
const indexer = getIndexer();
6767

68+
// Guard: use noop if context is not provided
69+
const safeContext = context || { metadata: () => {} };
70+
6871
if (args.estimateOnly) {
6972
const estimate = await indexer.estimateCost();
7073
return formatCostEstimate(estimate);
@@ -75,7 +78,7 @@ export const index_codebase: ToolDefinition = tool({
7578
}
7679

7780
const stats = await indexer.index((progress) => {
78-
context.metadata({
81+
safeContext.metadata({
7982
title: formatProgressTitle(progress),
8083
metadata: {
8184
phase: progress.phase,

0 commit comments

Comments
 (0)