-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Question about cross compile Node-API addon to wasm with emnapi and emscripten on Windows/macOS #2823
Comments
anyone could help? |
@toyobayashi just noticed this issue. May not be the right group to discuss the issues around node-gyp but if you come to the Node-api team meeting on Friday at 11 ET (https://zoom.us/j/363665824 I think we'd be intersted in better understanding what you are trying to do and the current issues. Might be one way to find people who might be interested in helping. |
@mhdawson Thanks for your invitation! But I'm sorry I think my English listening and speaking skills are not enough for me to attend the meeting. I just want to find a way that make node-gyp can work fine on win/linux/mac for emscripten target, currently it only works on linux via --nodedir and -- -f make. |
I'm not sure if its a reasonable suggestion but I think @legendecas is in the same region as you and maybe you two could talk more easily? Just a suggestions as I do know there are still different languages in the region. One thing I wondered was how hard the dependency on node-gyp was versus using something like cmake which I know is also a possiblity for node-addon-api modules. |
@mhdawson CMake is easy to integrate cause emscripten has already provided the toolchain file, while node-gyp no. emnapi support user to use CMake build Node-API wasm module. On the other hand, not only does node-gyp not have a toolchain config file for emscripten, the generator will also generate platform-specific compilation options based on the operating system, for example on Windows it will generate VS solution by default, even if I tell it generate makefile, the path separator is incorrect, and on macOS it generates Although CMake can indeed easily build Node-API wasm modules, most native modules in Node.js community are built using node-gyp. For example, sharp is using emnapi to build wasm that can run on StackBlitz, they still prefer using node-gyp (https://github.com/lovell/sharp/blob/main/src/emscripten/common.gypi) instead of maintaining another CMake configuration for emnapi. So I think it is so nice if node-gyp can work on all platform cause this can reduce the cost for native module maintainers to compile Node-API into wasm modules. @legendecas Are you interested in taking a look? |
I am not familiar with windows builds but I would try this out on mac. Also, please feel free to message me on OpenJS Slack. |
@legendecas The link seems to be broken. Just now I found out how to make it work on mac, pushed emnapi-node-gyp-test. I added these environment variables and place link flags in
emmake node-gyp rebuild --verbose --nodedir=./wasm -- -f make |
Does the same trick address the problem on Windows as well? |
For what it's worth, I can build with https://github.com/toyobayashi/emnapi-node-gyp-test/blob/main/build.sh with following patch: export GYP_CROSSCOMPILE=1
export AR_host=ar
export CC_host=clang
export CXX_host=clang++
export AR_target=emar
export CC_target=emcc
export CXX_target=em++
emmake node-gyp rebuild --verbose --nodedir=./wasm -- -f make |
No, makefile generator generates linux commands which is not supported on windows. I tried to use Cygwin but the path separator "" generated in makefile doesn't work. |
After some hard trying, finally build successfully on Windows with some tricks. Pushed emnapi-node-gyp-test.
This is just for such a simple example, if for a more complex project, I think there will be more gyp source code that needs to be modified. Can gyp consider make |
Hello @toyobayashi I had a similar issue trying to install emnapi on Windows. At the end I just installed it with Windows Powershell and I had not issue. It's a workaround, but it works. |
Hi! I'm the creator of emnapi which is a Node-API implementation for emscripten/wasi-sdk, it can be used for porting existing Node-API native addon to WebAssembly. I'm wondering if node-gyp can be used for building wasm with emscripten, then I have a test repo https://github.com/toyobayashi/emnapi-node-gyp-test here, seems that node-gyp cross compiling with emscripten only works on Linux, both Windows and macOS are failed.
Steps to reproduce:
git clone https://github.com/toyobayashi/emnapi-node-gyp-test cd emnapi-node-gyp-test npm install --ignore-scripts node-gyp clean node-gyp configure --nodedir=./wasm -- -f make emmake make -C build
Logs and reason:
Windows 11 22H2 22621.1413
Failed due to the generated Makefile still use unix tools, even if execute make under WSL 2 then failed due to
\\
path seperator.WSL 2 Ubuntu 20.04 (Success)
macOS 13.2.1 (M2 Pro)
Failed due to emcc doesn't support
-arch arm64
compile flag.Is there any way to workaround such gyp default behavior on different OS? Does it require upstream gyp code change to support? Or is there any way to solve these problem via configuration or some command line flags?
The text was updated successfully, but these errors were encountered: