From c19f3717f19033b67dc8974ed11934af15651c9f Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 29 Aug 2021 12:08:15 +0200 Subject: [PATCH] Pass --arch to node-gyp instead of --target-arch Technically it supports both but --arch is the documented option, that has more logic associated with it, while --target-arch is merely forwarded to gyp. In addition, handle multi-arch values which on our end dictate the output folder but are not understood by node-gyp. Ref https://github.com/prebuild/prebuildify/issues/52 --- README.md | 2 +- index.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80f1e3c..0421337 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ 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. -\*\* 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`. +\*\* The `arch` option is passed to [`node-gyp`][node-gyp] as `--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 (to be found by `node-gyp-build` at runtime). For example on Linux x64 prebuilds end up in `prebuilds/linux-x64`. The `arch` option can also be a multi-arch value separated by `+` (for example `x64+arm64` for a [universal binary](https://en.wikipedia.org/wiki/Universal_binary)) mainly to dictate the output folder; only the first architecture is passed on to `node-gyp`. \*\*\* The filenames of prebuilds are composed of _tags_ which by default include runtime and either `napi` or `abi`. 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. diff --git a/index.js b/index.js index 2f44b92..b139844 100644 --- a/index.js +++ b/index.js @@ -187,7 +187,11 @@ function build (target, runtime, opts, cb) { args.push('--devdir=' + path.join(cache, runtime)) if (opts.arch) { - args.push('--target_arch=' + opts.arch) + // Only pass the first architecture because node-gyp doesn't understand + // our multi-arch tuples (for example "x64+arm64"). In any case addon + // authors must modify their binding.gyp for multi-arch scenarios, + // because neither node-gyp nor prebuildify have builtin support. + args.push('--arch=' + opts.arch.split('+')[0]) } if (runtime === 'electron') {