Skip to content

Commit 2ed6d0d

Browse files
committed
Load correct linux binding
1 parent 530a5c0 commit 2ed6d0d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

scripts/init-rocksdb/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ try {
3535
}
3636

3737
const currentVersion = getCurrentVersion();
38-
const runtime = process.platform === 'linux' ? `-${process.env.ROCKSDB_LIBC || 'glibc'}` : undefined;
38+
const runtime = process.platform === 'linux'
39+
? `-${process.env.ROCKSDB_LIBC || 'glibc'}`
40+
: undefined;
3941
const pkgJson = JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
4042
const desiredVersion = process.env.ROCKSDB_VERSION || pkgJson.rocksdb?.version || undefined;
4143

src/load-binding.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { existsSync, readdirSync } from 'node:fs';
1+
import { execSync } from 'node:child_process';
2+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
23
import { createRequire } from 'node:module';
34
import { dirname, join, resolve } from 'node:path';
45
import { fileURLToPath } from 'node:url';
@@ -170,6 +171,29 @@ function locateBinding(): string {
170171
} catch {}
171172
}
172173

174+
// determine the Linux C runtime
175+
let runtime = '';
176+
if (process.platform === 'linux') {
177+
let isMusl = false;
178+
try {
179+
isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl');
180+
} catch {
181+
if (typeof process.report?.getReport === 'function') {
182+
process.report.excludeEnv = true;
183+
const report = process.report.getReport() as unknown as {
184+
header?: { glibcVersionRuntime?: string };
185+
sharedObjects?: string[];
186+
};
187+
isMusl = (!report?.header || !report.header.glibcVersionRuntime) &&
188+
Array.isArray(report?.sharedObjects) && report.sharedObjects.some(obj =>
189+
obj.includes('libc.musl-') || obj.includes('ld-musl-')
190+
);
191+
}
192+
isMusl = isMusl || execSync('ldd --version', { encoding: 'utf8' }).includes('musl');
193+
}
194+
runtime = isMusl ? '-musl' : '-glibc';
195+
}
196+
173197
// the following lines are non-trivial to test, so we'll ignore them
174198
/* v8 ignore next 10 -- @preserve */
175199

@@ -179,7 +203,7 @@ function locateBinding(): string {
179203
baseDir,
180204
'node_modules',
181205
'@harperfast',
182-
`rocksdb-js-${process.platform}-${process.arch}`,
206+
`rocksdb-js-${process.platform}-${process.arch}${runtime}`,
183207
'build',
184208
'Release',
185209
'rocksdb-js.node'

0 commit comments

Comments
 (0)