mmomtchev / swig

This is SWIG JavaScript Evolution, a fork of the SWIG project with modern JavaScript/TypeScript support including WASM and async
http://www.swig.org
Other
9 stars 0 forks source link

...JAVASCRIPT_wrap.cxx:238:10: fatal error: 'uv.h' file not found #58

Closed mateusz-plociennik closed 1 month ago

mateusz-plociennik commented 1 month ago

Hi, I am trying out current main branch (as of 15/07/2024). I am trying your fork to get smart pointers support. It seems there's a strong libuv dependency, which I am trying to sort out. I decided to go with cmake-js build and I am using UseSWIG macros. I use -c++ -javascript -napi args. I am getting the following error:

/build/CMakeFiles/rpc.dir/rpcJAVASCRIPT_wrap.cxx:238:10: fatal error: 'uv.h' file not found
#include <uv.h>
         ^~~~~~
1 error generated.
make[2]: *** [CMakeFiles/rpc.dir/CMakeFiles/rpc.dir/rpcJAVASCRIPT_wrap.cxx.o] Error 1
make[1]: *** [CMakeFiles/rpc.dir/all] Error 2
make: *** [all] Error 2

What is the best approach to get pass this error? Should I include emnapi?

mateusz-plociennik commented 1 month ago

I commented out the include in https://github.com/mmomtchev/swig/blob/cd411c4edff7ab523943be883b4ea2d18cee395c/Lib/javascript/napi/javascriptruntime.swg#L35 and that works for me, so maybe that should be included conditionally for WASM?

mmomtchev commented 1 month ago

uv.h is part of the Node.js distribution and it must be in the same directory as node_api.h. If it is missing, you have a problem with your Node.js distribution. emnapi overrides it with its own version.

mateusz-plociennik commented 1 month ago

I think I am facing the issue with cmake-js you mentioned here.

If I remove "binary": {"napi_versions": [7]} from package.json, then I get -DCMAKE_JS_INC=/Users/mateuszp/.cmake-js/node-arm64/v22.4.1/include/node otherwise: -DCMAKE_JS_INC=/opt/homebrew/lib/node_modules/cmake-js/node_modules/node-api-headers/include;/Users/mateuszp/Developer/sw/AppiumDriver/node_modules/node-addon-api

According to https://github.com/nodejs/node-addon-api/blob/main/doc/README.md#abi-stability-guideline

It is important to remember that other Node.js interfaces such as libuv (included in a project via #include ) are not ABI-stable across Node.js major versions.

The generated SWIG code doesn't seem to use any of uv_* API, so why do we need to include it? Is it required for async?

mmomtchev commented 1 month ago

How does the include of node_api.h work then?

mateusz-plociennik commented 1 month ago

Through node-api-headers package:

> tree /opt/homebrew/lib/node_modules/cmake-js/node_modules/node-api-headers/include
/opt/homebrew/lib/node_modules/cmake-js/node_modules/node-api-headers/include
├── js_native_api.h
├── js_native_api_types.h
├── node_api.h
└── node_api_types.h