When building on a non-x64 machine, GYP's host_arch variable isn't correctly set. My guess is that the header tarball referenced by dist-url has it set it to x64 in config.gypi, and it's never updated.
Steps to reproduce
On a non-x64 machine, in an empty folder, create the following two files:
binding.gyp
{
"targets": [
{
"target_name": "addon",
"sources": ["addon.cc"],
"defines": [
"GYP_HOST_ARCH=<(host_arch)"
]
}
]
}
addon.cc
#include <node_api.h>
NAPI_MODULE_INIT() {
return exports;
}
Then run the following commands:
npm install --save-dev @electron/rebuild
DEBUG=electron-rebuild npx electron-rebuild -f -w addon -v 38.2.2
The build succeeds, and output shows it's correctly targeting the arch of the system.
However if I check build/config.gypi, I see "host_arch": "x64",, and build/addon.target.mk contains '-DGYP_HOST_ARCH=x64', indicating host_arch is incorrectly set to x64.
Diagnosis
Looking at node-gyp's source, it looks like the generated build/config.gypi is usually based off process.config unless a disturl is supplied, in which case, it uses the supplied config.gypi. As electron-rebuild provides such a config.gypi, the host_arch variable is copied verbatim, which is always x64 regardless of the host system's arch.
host_arch would need to be updated to match whatever process.config reports to fix this. I don't know if other variables need similar treatment.
When building on a non-x64 machine, GYP's
host_archvariable isn't correctly set. My guess is that the header tarball referenced by dist-url has it set it to x64 in config.gypi, and it's never updated.Steps to reproduce
On a non-x64 machine, in an empty folder, create the following two files:
binding.gyp
{ "targets": [ { "target_name": "addon", "sources": ["addon.cc"], "defines": [ "GYP_HOST_ARCH=<(host_arch)" ] } ] }addon.cc
Then run the following commands:
The build succeeds, and output shows it's correctly targeting the arch of the system.
However if I check build/config.gypi, I see
"host_arch": "x64",, and build/addon.target.mk contains'-DGYP_HOST_ARCH=x64', indicatinghost_archis incorrectly set to x64.Diagnosis
Looking at node-gyp's source, it looks like the generated build/config.gypi is usually based off
process.configunless adisturlis supplied, in which case, it uses the supplied config.gypi. As electron-rebuild provides such a config.gypi, thehost_archvariable is copied verbatim, which is always x64 regardless of the host system's arch.host_archwould need to be updated to match whateverprocess.configreports to fix this. I don't know if other variables need similar treatment.