Skip to content
Open
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
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Options can be provided via (in order of precedence) the programmatic API, the C
|:---------------------|:---------------------|:-------------------------------|:------------
| `--target -t` | - | Depends. | One or more targets\*
| `--all -a` | - | `false` | Build all known targets.<br>Takes precedence over `--target`.
| `--napi` | - | `false` | Make [N-API][n-api] build(s).<br>Targets default to latest node which is compatible with Electron > 3, which can be overridden with `--target`. Note: `--all` should be avoided for now because it includes targets that don't support N-API.
| `--electron-compat` | - | `false` | Make two N-API builds, one for node and one for Electron. Useful if you support Electron <= 3.
| `--napi` | - | `false` | Make [N-API][n-api] build(s).<br>Targets default to latest node which is compatible with Electron > 3, which can be overridden with `--target`.
| `--electron-compat` | - | `false` | Make two N-API builds, one for node and one for Electron. Provide this to make sure Electron abi is supported.
| `--debug` | - | `false` | Make Debug build(s)
| `--arch` | `PREBUILD_ARCH` | [`os.arch()`]([os-arch]) | Target architecture\*\*
| `--platform` | `PREBUILD_PLATFORM` | [`os.platform()`][os-platform] | Target platform\*\*
Expand All @@ -106,8 +106,22 @@ Options can be provided via (in order of precedence) the programmatic API, the C

\* A target takes the form of `(runtime@)?version`, where `runtime` defaults to `'node'`. For example: `-t 8.14.0 -t electron@3.0.0`. At least one of `--target`, `--all` or `--napi` must be specified.

```
prebuildify --napi -all # all the napi versions that are supported by Node
prebuildify --napi --electron-compat -all # all the napi versions that are supported by Node or Electron
prebuildify --napi # last napi version supported by Node
prebuildify --napi --electron-compat # last napi version supported by Node
prebuildify --all # all the targets
prebuildify -t 8.14.0 -t electron@3.0.0 # specific targets
```

\*\* The `arch` option is passed to [`node-gyp`][node-gyp] as `--target-arch`. Target architecture and platform (what you're building _for_) default to the host platform and architecture (what you're building _on_). They can be overridden for cross-compilation, in which case you'll likely also want to override the strip binary. The platform and architecture dictate the output folder. For example on Linux x64 prebuilds end up in `prebuilds/linux-x64`.

```
prebuildify --napi --electron-compat # uses the architecture of running process
prebuildify --arch=ia32 --napi --electron-compat # windows x86 architecture
```

\*\*\* The filenames of prebuilds are composed of _tags_ which by default include runtime and either `napi` or `abi<version>`. For example: `electron.abi40.node`. To make more specific prebuilds (for `node-gyp-build` to select) you can add additional tags. Values for these tags are auto-detected. For example, `--napi --tag-uv --tag-armv` could result in a build called `node.napi.uv1.armv8.node` if the host machine has an ARM architecture. When cross-compiling you can override values either through the relevant option (`--tag-armv --armv 7`) or the tag (`--tag-armv 7`) as a shortcut. They're separate because you may want to build a certain version without tagging the prebuild as such, assuming that the prebuild is forward compatible.

\*\*\*\* To enable the use of forks like [`nodejs-mobile-gyp`](https://www.npmjs.com/package/nodejs-mobile-gyp).
Expand Down
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,16 @@ function resolveTargets (targets, all, napi, electronCompat) {
}
})

// TODO: also support --lts and get versions from travis
if (all) {
targets = abi.supportedTargets.slice(0)
// napi and all
if (napi && all) {
targets = abi.supportedTargets.filter(onlyNapiNode)

// add electron if --electron-compat is provided
if (electronCompat) {
targets.push(...abi.supportedTargets.filter(onlyNapiElectron))
}
} else if (all) { // TODO: also support --lts and get versions from travis
targets = abi.supportedTargets
}

// Should be the default once napi is stable
Expand All @@ -313,6 +320,16 @@ function onlyElectron (t) {
return t.runtime === 'electron'
}

function onlyNapiNode (t) {
// n-api is supported as of Node 8 which is abi 57
// https://github.com/lgeiger/node-abi/blob/41217a504e4adb28a36a850c9981812c99086d3a/index.js#L96
return t.runtime === 'node' && parseInt(t.abi, 10) > 57
}

function onlyNapiElectron (t) {
return t.runtime === 'electron' && parseInt(t.abi, 10) > 57
}

function uv () {
return (process.versions.uv || '').split('.')[0]
}
Expand Down