Skip to content

Commit

Permalink
Allow setting libc to glibc on non-glibc platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Joona Heinikoski authored and joonamo committed Mar 19, 2022
1 parent 4a1ed43 commit 61b48e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ prebuild-install [options]
--version (print prebuild-install version and exit)
```

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.
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.

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`.
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 `LIBC`.

### Libc

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.

### Private Repositories

Expand Down
6 changes: 5 additions & 1 deletion rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const detectLibc = require('detect-libc')
const napi = require('napi-build-utils')

const env = process.env
const libc = env.LIBC || (detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || ''

const libc = env.LIBC || process.env.npm_config_libc ||
(detectLibc.isNonGlibcLinuxSync() && detectLibc.familySync()) || ''

// Get the configuration
module.exports = function (pkg) {
Expand Down Expand Up @@ -51,6 +53,8 @@ module.exports = function (pkg) {

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

rc.libc = rc.libc === detectLibc.GLIBC ? '' : rc.libc

return rc
}

Expand Down
14 changes: 13 additions & 1 deletion test/rc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ test('npm_config_* are passed on from environment into rc', function (t) {
npm_config_target: '1.4.0',
npm_config_runtime: 'electron',
npm_config_platform: 'PLATFORM',
npm_config_build_from_source: 'true'
npm_config_build_from_source: 'true',
npm_config_libc: 'testlibc'
}
runRc(t, '', env, function (rc) {
t.equal(rc.proxy, 'http://localhost/', 'proxy is set')
Expand All @@ -81,6 +82,7 @@ test('npm_config_* are passed on from environment into rc', function (t) {
t.equal(rc.runtime, 'electron', 'runtime is set')
t.equal(rc.platform, 'PLATFORM', 'platform is set')
t.equal(rc.buildFromSource, true, 'build-from-source is set')
t.equal(rc.libc, 'testlibc', 'libc is set')
t.end()
})
})
Expand Down Expand Up @@ -115,6 +117,16 @@ test('using --tag-prefix will set the tag prefix', function (t) {
})
})

test('libc glibc is passed as empty', function (t) {
const args = [
'--libc glibc'
]
runRc(t, args.join(' '), {}, function (rc, tmp) {
t.equal(rc.libc, '', 'libc family')
t.end()
})
})

function runRc (t, args, env, cb) {
const pkg = {
name: 'test',
Expand Down
2 changes: 1 addition & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getDownloadUrl (opts) {
runtime: opts.runtime || 'node',
platform: opts.platform,
arch: opts.arch,
libc: opts.libc || process.env.LIBC || '',
libc: opts.libc || '',
configuration: (opts.debug ? 'Debug' : 'Release'),
module_name: opts.pkg.binary && opts.pkg.binary.module_name,
tag_prefix: opts['tag-prefix']
Expand Down

0 comments on commit 61b48e5

Please sign in to comment.