Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally support prebuilds for libc and arm flavors #14

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ without having to compile on install time AND will work in both node and electro

Users can override `node-gyp-build` and force compiling by doing `npm install --build-from-source`.

## Supported prebuild names

If so desired you can bundle more specific flavors, for example `musl` builds to support Alpine, or targeting a numbered ARM architecture version.

These prebuilds can be bundled in addition to generic prebuilds; `node-gyp-build` will try to find the most specific flavor first. In order of precedence:

- If `arch` is `'arm'` or `'arm64'`:
- `${platform}${libc}-${arch}-v${arm_version}`
- `${platform}-${arch}-v${arm_version}`
- `${platform}${libc}-${arch}`
- `${platform}-${arch}`

The `libc` flavor and `arm_version` are auto-detected but can be overridden through the `LIBC` and `ARM_VERSION` environment variables, respectively.

## License

MIT
29 changes: 22 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('fs')
var path = require('path')
var os = require('os')
var detectLibc = require('detect-libc')
vweevers marked this conversation as resolved.
Show resolved Hide resolved

// Workaround to fix webpack's build warnings: 'the request of a dependency is an expression'
var runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require // eslint-disable-line
Expand All @@ -9,6 +10,8 @@ var abi = process.versions.modules // TODO: support old node where this is undef
var runtime = isElectron() ? 'electron' : 'node'
var arch = os.arch()
var platform = os.platform()
var libc = process.env.LIBC || detectLibc.family || ''
var armv = process.env.ARM_VERSION || (arch === 'arm64' ? '8' : process.config.variables.arm_version) || ''

module.exports = load

Expand All @@ -30,16 +33,28 @@ load.path = function (dir) {
var debug = getFirst(path.join(dir, 'build/Debug'), matchBuild)
if (debug) return debug

var prebuild = getFirst(path.join(dir, 'prebuilds/' + platform + '-' + arch), matchPrebuild)
if (prebuild) return prebuild
var names = [platform + '-' + arch]
if (libc) names.push(platform + libc + '-' + arch)

var napiRuntime = getFirst(path.join(dir, 'prebuilds/' + platform + '-' + arch), matchNapiRuntime)
if (napiRuntime) return napiRuntime
if ((arch === 'arm' || arch === 'arm64') && armv) {
names.forEach(function (name) {
names.push(name + '-v' + armv)
})
}

// Find most specific flavor first
for (var i = names.length; i--;) {
var prebuild = getFirst(path.join(dir, 'prebuilds/' + names[i]), matchPrebuild)
if (prebuild) return prebuild

var napi = getFirst(path.join(dir, 'prebuilds/' + platform + '-' + arch), matchNapi)
if (napi) return napi
var napiRuntime = getFirst(path.join(dir, 'prebuilds/' + names[i]), matchNapiRuntime)
if (napiRuntime) return napiRuntime

var napi = getFirst(path.join(dir, 'prebuilds/' + names[i]), matchNapi)
if (napi) return napi
}

throw new Error('No native build was found for runtime=' + runtime + ' abi=' + abi + ' platform=' + platform + ' arch=' + arch)
throw new Error('No native build was found for runtime=' + runtime + ' abi=' + abi + ' platform=' + platform + libc + ' arch=' + arch)
}

function getFirst (dir, filter) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"node-gyp-build-optional": "./optional.js",
"node-gyp-build-test": "./build-test.js"
},
"dependencies": {
"detect-libc": "~1.0.3"
},
"repository": {
"type": "git",
"url": "https://github.com/mafintosh/node-gyp-build.git"
Expand Down