Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit ca2bb78

Browse files
Joona Heinikoskijoonamo
authored andcommitted
Allow setting libc to glibc on non-glibc platform
1 parent 4a1ed43 commit ca2bb78

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ prebuild-install [options]
7272
--version (print prebuild-install version and exit)
7373
```
7474

75-
When `prebuild-install` is run via an `npm` script, options `--build-from-source`, `--debug`, `--download`, `--target`, `--runtime`, `--arch` and `--platform` may be passed through via arguments given to the `npm` command.
75+
When `prebuild-install` is run via an `npm` script, options `--build-from-source`, `--debug`, `--download`, `--target`, `--runtime`, `--arch` `--platform` and `--libc` may be passed through via arguments given to the `npm` command.
7676

77-
Alternatively you can set environment variables `npm_config_build_from_source=true`, `npm_config_platform`, `npm_config_arch`, `npm_config_target` and `npm_config_runtime`.
77+
Alternatively you can set environment variables `npm_config_build_from_source=true`, `npm_config_platform`, `npm_config_arch`, `npm_config_target` `npm_config_runtime` and `npm_config_libc`.
78+
79+
### Libc
80+
81+
On non-glibc Linux platforms, the Libc name is appended to platform name. For example, musl-based environments are called `linuxmusl`. If `--libc=glibc` is passed as option, glibc is discarded and platform is called as just `linux`. This can be used for example to build cross-platform packages on Alpine Linux.
7882

7983
### Private Repositories
8084

rc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const detectLibc = require('detect-libc')
55
const napi = require('napi-build-utils')
66

77
const env = process.env
8-
const libc = env.LIBC || (detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || ''
8+
9+
const libc = env.LIBC || process.env.npm_config_libc ||
10+
(detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || ''
911

1012
// Get the configuration
1113
module.exports = function (pkg) {
@@ -51,6 +53,8 @@ module.exports = function (pkg) {
5153

5254
rc.abi = napi.isNapiRuntime(rc.runtime) ? rc.target : getAbi(rc.target, rc.runtime)
5355

56+
rc.libc = rc.libc === detectLibc.GLIBC ? '' : rc.libc
57+
5458
return rc
5559
}
5660

test/rc-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ test('npm_config_* are passed on from environment into rc', function (t) {
7171
npm_config_target: '1.4.0',
7272
npm_config_runtime: 'electron',
7373
npm_config_platform: 'PLATFORM',
74-
npm_config_build_from_source: 'true'
74+
npm_config_build_from_source: 'true',
75+
npm_config_libc: 'testlibc'
7576
}
7677
runRc(t, '', env, function (rc) {
7778
t.equal(rc.proxy, 'http://localhost/', 'proxy is set')
@@ -81,6 +82,7 @@ test('npm_config_* are passed on from environment into rc', function (t) {
8182
t.equal(rc.runtime, 'electron', 'runtime is set')
8283
t.equal(rc.platform, 'PLATFORM', 'platform is set')
8384
t.equal(rc.buildFromSource, true, 'build-from-source is set')
85+
t.equal(rc.libc, 'testlibc', 'libc is set')
8486
t.end()
8587
})
8688
})
@@ -115,6 +117,16 @@ test('using --tag-prefix will set the tag prefix', function (t) {
115117
})
116118
})
117119

120+
test('libc glibc is passed as empty', function (t) {
121+
const args = [
122+
'--libc glibc'
123+
]
124+
runRc(t, args.join(' '), {}, function (rc, tmp) {
125+
t.equal(rc.libc, '', 'libc family')
126+
t.end()
127+
})
128+
})
129+
118130
function runRc (t, args, env, cb) {
119131
const pkg = {
120132
name: 'test',

util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function getDownloadUrl (opts) {
2020
runtime: opts.runtime || 'node',
2121
platform: opts.platform,
2222
arch: opts.arch,
23-
libc: opts.libc || process.env.LIBC || '',
23+
libc: opts.libc || '',
2424
configuration: (opts.debug ? 'Debug' : 'Release'),
2525
module_name: opts.pkg.binary && opts.pkg.binary.module_name,
2626
tag_prefix: opts['tag-prefix']

0 commit comments

Comments
 (0)