diff --git a/README.md b/README.md index 6e7d94e..aaea6a5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/rc.js b/rc.js index 16d5bb4..f81c0da 100644 --- a/rc.js +++ b/rc.js @@ -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) { @@ -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 } diff --git a/test/rc-test.js b/test/rc-test.js index 72f8976..4860edc 100644 --- a/test/rc-test.js +++ b/test/rc-test.js @@ -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') @@ -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() }) }) @@ -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', diff --git a/util.js b/util.js index 3b529db..4d00351 100644 --- a/util.js +++ b/util.js @@ -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']