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 all commits
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
32 changes: 25 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 || (isAlpine(platform) ? 'musl' : 'glibc')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

var armv = process.env.ARM_VERSION || (arch === 'arm64' ? '8' : process.config.variables.arm_version) || ''

module.exports = load

Expand All @@ -30,16 +32,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 napiRuntime = getFirst(path.join(dir, 'prebuilds/' + names[i]), matchNapiRuntime)
if (napiRuntime) return napiRuntime

var napi = getFirst(path.join(dir, 'prebuilds/' + platform + '-' + arch), matchNapi)
if (napi) return napi
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 Expand Up @@ -73,3 +87,7 @@ function isElectron () {
if (process.env.ELECTRON_RUN_AS_NODE) return true
return typeof window !== 'undefined' && window.process && window.process.type === 'renderer'
}

function isAlpine (platform) {
return platform === 'linux' && fs.existsSync('/etc/alpine-release')
}