Tl;dr
如何为苹果和英特尔芯片交叉编译包含本机插件的electron.js应用程序?
详细信息
我有一台安装了macos12.x的MacbookM1机器。当我试图使用electron-builder
交叉编译electron.js应用程序时,该应用程序中使用的本机插件会引发此错误。
应用程序的arm64
版本编译得很好,但x64
不断抛出错误。
ld: warning: ignoring file /opt/homebrew/opt/llvm/lib/libc++.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: in '/opt/homebrew/opt/llvm/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已将electron-builder
目标设置为:
"target": {
"target": "default",
"arch": [
"arm64",
"x64"
]
}
$ yarn build && cross-env electron-builder build --mac --publish never
项目的完整源代码可在此处获得:OpenMTP
我在这里附上截断的构建日志:
• rebuilding native dependency name=ffi-napi version=4.0.3
• rebuilding native dependency name=node-mac-permissions version=2.2.0
• rebuilding native dependency name=usb-detection version=4.13.0
• rebuilding native dependency name=ref-napi version=3.0.3
⨯ cannot execute cause=exit status 1
node-gyp-build
CC(target) Release/obj.target/nothing/../node-addon-api/nothing.o
LIBTOOL-STATIC Release/nothing.a
CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
CC(target) Release/obj.target/ffi/deps/libffi/src/types.o
CC(target) Release/obj.target/ffi/deps/libffi/src/raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/java_raw_api.o
CC(target) Release/obj.target/ffi/deps/libffi/src/closures.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffiw64.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/ffi64.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/unix64.o
CC(target) Release/obj.target/ffi/deps/libffi/src/x86/win64.o
LIBTOOL-STATIC Release/libffi.a
CXX(target) Release/obj.target/ffi_bindings/src/ffi.o
CXX(target) Release/obj.target/ffi_bindings/src/callback_info.o
CXX(target) Release/obj.target/ffi_bindings/src/threaded_callback_invokation.o
SOLINK_MODULE(target) Release/ffi_bindings.node
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
errorOut=gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@16.14.0 | darwin | arm64
gyp info find Python using Python version 3.9.10 found at "/opt/homebrew/opt/python@3.9/bin/python3.9"
gyp info spawn /opt/homebrew/opt/python@3.9/bin/python3.9
gyp info spawn args [
gyp info spawn args '/Users/home/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/path/to/project/node_modules/ffi-napi/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/home/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/home/.electron-gyp/17.0.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/home/.electron-gyp/17.0.0',
gyp info spawn args '-Dnode_gyp_dir=/Users/home/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/home/.electron-gyp/17.0.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/path/to/project/node_modules/ffi-napi',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
warning: nothing.o has no symbols
../deps/libffi/src/java_raw_api.c:328:46: warning: 'ffi_java_raw_size' is deprecated [-Wdeprecated-declarations]
ffi_java_raw *raw = (ffi_java_raw*)alloca (ffi_java_raw_size (cif));
^
../deps/libffi/config/mac/x64/ffi.h:299:56: note: 'ffi_java_raw_size' has been explicitly marked deprecated here
size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated));
^
../deps/libffi/src/java_raw_api.c:331:3: warning: 'ffi_java_ptrarray_to_raw' is deprecated [-Wdeprecated-declarations]
ffi_java_ptrarray_to_raw (cif, avalue, raw);
^
../deps/libffi/config/mac/x64/ffi.h:295:93: note: 'ffi_java_ptrarray_to_raw' has been explicitly marked deprecated here
void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw) __attribute__((deprecated));
^
2 warnings generated.
In file included from ../deps/libffi/src/closures.c:524:
../deps/libffi/src/dlmalloc.c:2937:33: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
used = fp - (m->topsize + TOP_FOOT_SIZE);
^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:2193:17: note: expanded from macro 'TOP_FOOT_SIZE'
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
~~~~~~~~~~~~~^~~~~~~~~~~~~
../deps/libffi/src/dlmalloc.c:1693:55: note: expanded from macro 'chunk2mem'
#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES))
........
truncated
........
~~~ ^ ~~~~~~~~~
29 warnings generated.
ld: warning: ignoring file /opt/homebrew/opt/llvm/lib/libc++.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: in '/opt/homebrew/opt/llvm/lib/libunwind.dylib', building for macOS-x86_64 but attempting to link with file built for macOS-arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/ffi_bindings.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/home/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (node:events:520:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.3.0
gyp ERR! command "/Users/home/.nvm/versions/node/v16.14.0/bin/node" "/Users/home/.nvm/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /path/to/project/node_modules/ffi-napi
gyp ERR! node -v v16.14.0
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok
error Command failed with exit code 1.
我能够通过将npmRebuild: false
添加到package.json文件中的build
对象来解决我的问题。
"build": {
.....
"npmRebuild": false,
}
Github问题