1- import { existsSync , readdirSync } from 'node:fs' ;
1+ import { execSync } from 'node:child_process' ;
2+ import { existsSync , readdirSync , readFileSync } from 'node:fs' ;
23import { createRequire } from 'node:module' ;
34import { dirname , join , resolve } from 'node:path' ;
45import { 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