-
Notifications
You must be signed in to change notification settings - Fork 184
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
native modules #4
Comments
Hi @lukaskollmer, We've been successful in adding a native Node.js module using NAPI by embedding it in our React-Native and Cordova plugins and it is able to call into C++/Java code. Our technique is registering it as a builtin module and embedding it in the application. You can check the current version in the React Native plugin repo, for instance. With some changes, native modules can be compiled/linked with the application and seen as builtin modules. We are still designing our solution for using native npm modules on iOS, hopefully it won't take long. In your specific case, the I hope that helped. |
Does this approach only work with the |
Hi @lukaskollmer, You are able to register modules written with the
One of the You do have to use another macro, provided in You can also use |
Currently when running the test without an internet connection there are two JavaScript test failures and one cctest. The cctest only fails on Mac as far as I know. (I've only tested using Mac and Linux thus far). This commit moves the two JavaScript tests to test/internet. The details for test_inspector_socket_server.cc: [ RUN ] InspectorSocketServerTest.FailsToBindToNodejsHost make[1]: *** [cctest] Segmentation fault: 11 make: *** [test] Error 2 lldb output: [ RUN ] InspectorSocketServerTest.FailsToBindToNodejsHost Process 63058 stopped * thread #1: tid = 0x7b175, 0x00007fff96d04384 * libsystem_info.dylib`_gai_simple + 87, queue = * 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, * address=0x0) frame #0: 0x00007fff96d04384 libsystem_info.dylib`_gai_simple + 87 libsystem_info.dylib`_gai_simple: -> 0x7fff96d04384 <+87>: movw (%rdx), %ax 0x7fff96d04387 <+90>: movw %ax, -0x2a(%rbp) 0x7fff96d0438b <+94>: movq %r13, -0x38(%rbp) 0x7fff96d0438f <+98>: movq 0x18(%rbp), %rcx (lldb) bt * thread #1: tid = 0x7b175, 0x00007fff96d04384 * libsystem_info.dylib`_gai_simple + 87, queue = * 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, * address=0x0) * frame #0: 0x00007fff96d04384 libsystem_info.dylib`_gai_simple + 87 frame #1: 0x00007fff96cfe98b libsystem_info.dylib`search_addrinfo + 179 frame #2: 0x00007fff96cfafef libsystem_info.dylib`si_addrinfo + 2255 frame #3: 0x00007fff96cfa67b libsystem_info.dylib`getaddrinfo + 179 frame #4: 0x00000001017d8888 cctest`uv__getaddrinfo_work(w=0x00007fff5fbfe210) + 72 at getaddrinfo.c:102 frame #5: 0x00000001017d880e cctest`uv_getaddrinfo(loop=0x000000010287cb80, req=0x00007fff5fbfe1c8, cb=0x0000000000000000, hostname="nodejs.org", service="0", hints=0x00007fff5fbfe268) + 734 at getaddrinfo.c:192 frame #6: 0x000000010171f781 cctest`node::inspector::InspectorSocketServer::Start(this=0x00007fff5fbfe658) + 801 at inspector_socket_server.cc:398 frame #7: 0x00000001016ed590 cctest`InspectorSocketServerTest_FailsToBindToNodejsHost_Test::TestBody(this=0x0000000105001fd0) + 288 at test_inspector_socket_server.cc:593 I'm not sure about the exact cause for this but when using a standalone c program to simulate this it seems like when the ai_flags `AI_NUMERICSERV` is set, which is done in inspector_socket_server.cc line 394, the servname (the port in the FailsToBindToNodejsHost test) is expected to be a numeric port string to avoid looking it up in /etc/services. When the port is 0 as is it was before this commit the segment fault occurs but not if it is non-zero. PR-URL: nodejs/node#16255 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Hi @jaimecbernardo! I am trying to understand how to connect the dots between the runtimes.
Thanks! |
Hi, @oleksandr-yefremov A way of looking into how the current React-Native bridge acts is like this:
Regarding the questions:
I hope this was helpful. |
Thanks for detailed answer! I was just exploring the options to run non-UI JS code which would communicate to Native code without React Native and it seems like I should further look into option 1 ("…is possible if you extend the bridge to do that, but it's not implemented in the current version."). If I got it right, I'd need to extend C++(bridge) of Node.js to do at least the type conversion between JS and Native, plus some other stuff. |
Strings are already there, used in the bridge. Strings are sent to and received from Node through the Node Runner modules. |
Apologies for the simple nature of my question. But I have not yet had much experience compiling my own native modules (beyond just using npm install!). In basic terms, how do I get a native node module - like leveldown to work with nodejs mobile? |
Hi @carrotalan, We are currently working on a solution to bring support to native modules from npm to |
Currently when running the test without an internet connection there are two JavaScript test failures and one cctest. The cctest only fails on Mac as far as I know. (I've only tested using Mac and Linux thus far). This commit moves the two JavaScript tests to test/internet. The details for test_inspector_socket_server.cc: [ RUN ] InspectorSocketServerTest.FailsToBindToNodejsHost make[1]: *** [cctest] Segmentation fault: 11 make: *** [test] Error 2 lldb output: [ RUN ] InspectorSocketServerTest.FailsToBindToNodejsHost Process 63058 stopped * thread #1: tid = 0x7b175, 0x00007fff96d04384 * libsystem_info.dylib`_gai_simple + 87, queue = * 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, * address=0x0) frame #0: 0x00007fff96d04384 libsystem_info.dylib`_gai_simple + 87 libsystem_info.dylib`_gai_simple: -> 0x7fff96d04384 <+87>: movw (%rdx), %ax 0x7fff96d04387 <+90>: movw %ax, -0x2a(%rbp) 0x7fff96d0438b <+94>: movq %r13, -0x38(%rbp) 0x7fff96d0438f <+98>: movq 0x18(%rbp), %rcx (lldb) bt * thread #1: tid = 0x7b175, 0x00007fff96d04384 * libsystem_info.dylib`_gai_simple + 87, queue = * 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, * address=0x0) * frame #0: 0x00007fff96d04384 libsystem_info.dylib`_gai_simple + 87 frame #1: 0x00007fff96cfe98b libsystem_info.dylib`search_addrinfo + 179 frame #2: 0x00007fff96cfafef libsystem_info.dylib`si_addrinfo + 2255 frame #3: 0x00007fff96cfa67b libsystem_info.dylib`getaddrinfo + 179 frame #4: 0x00000001017d8888 cctest`uv__getaddrinfo_work(w=0x00007fff5fbfe210) + 72 at getaddrinfo.c:102 frame #5: 0x00000001017d880e cctest`uv_getaddrinfo(loop=0x000000010287cb80, req=0x00007fff5fbfe1c8, cb=0x0000000000000000, hostname="nodejs.org", service="0", hints=0x00007fff5fbfe268) + 734 at getaddrinfo.c:192 frame #6: 0x000000010171f781 cctest`node::inspector::InspectorSocketServer::Start(this=0x00007fff5fbfe658) + 801 at inspector_socket_server.cc:398 frame #7: 0x00000001016ed590 cctest`InspectorSocketServerTest_FailsToBindToNodejsHost_Test::TestBody(this=0x0000000105001fd0) + 288 at test_inspector_socket_server.cc:593 I'm not sure about the exact cause for this but when using a standalone c program to simulate this it seems like when the ai_flags `AI_NUMERICSERV` is set, which is done in inspector_socket_server.cc line 394, the servname (the port in the FailsToBindToNodejsHost test) is expected to be a numeric port string to avoid looking it up in /etc/services. When the port is 0 as is it was before this commit the segment fault occurs but not if it is non-zero. PR-URL: nodejs/node#16255 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Now that native node modules can be built on linux & mac osx, do you have any plans for bringing support of building android native node modules on windows? |
Hi @bil-ash , Thank you for the question. We'd love to bring support for building android native modules on Windows, eventually, but we still need to evaluate the effort required. It could be that it may work in the "Windows Subsystem for Linux" already. If you're able to install and run the android SDK and build-tools for building Android applications in WSL, it may be possible to build the native modules there already. If you decide to give it a try, please let us know of any results. |
Thanks for the clarification. |
We've recently added support for native modules in the cordova and react-native plugins latest update but we still need to validate that it will pass App Store review and we might need to make some tweaks in order to get there. If anyone has the opportunity to submit an app for review that uses native modules, that would definitely help us expedite the process and would be greatly appreciated. If you are able to help, please get in touch. We are going to work with you at high priority to address any possible issues that arise from the review. Please note that currently the support for native modules is off by default and needs to be switched on. Instructions on how to turn it on can be found on the commits right before the automatic detection was turned off. Here for Cordova: https://github.com/janeasystems/nodejs-mobile-cordova/tree/c4cd7ec65cf68d3224ae9ddcb3246e988b1cbbc2#native-modules Thank you! |
@jaimecbernardo
What should I do to solve the problem? |
Hi @bil-ash , Thank you for giving it a try. In this case, it seems like In the future, we will fix this by looking for I hope this was helpful. |
@jaimecbernardo Thanks very much. It was too naive of me to not have noticed that. That solved the node-gyp problem but now there is another problem regarding ndk. The native node module compilation fails due to two errors, as it cannot find fgetpos and fsetpos globally. Although I have next to nothing knowledge about c++, but what I understood is that it is a problem with ndk(issue nodejs#480 in ndk) and there seem to be multiple solutions depending on the use case. I tried one but that didn't solve the problem. Hope you can help |
@bil-ash I'd need to have more info. |
@jaimecbernardo Here is the log
|
Hi @bil-ash , I've tried building with the From the contents of the NDK issue, it's possible that it is related to the Android NDK version, since that issue seems to be fixed on later versions. |
@jaimecbernardo Yeah updating to ndk r16 did solve the problem. Thanks very much. |
@bil-ash Thanks a lot for making it work and letting us know :) |
Native Modules are now supported and their detection is automatic once again, after the v0.2.0 releases of the Cordova plugin and React Native plugin The method for iOS is a new one, which is confirmed to go through App Store submission, so if you depend on this feature, give the updated versions a try. |
Got next error on 0.2.0 version.
I ran it using next command:
On 0.1.5 build it working. My environment: Also I notice that my project don't start if build.gradle contain next setup:
If I change it on: It works well. |
Hi @britishd , So, is v0.2.0 working now after changing Regarding getting more info on why, it's not building correctly, it might be useful to get more information by trying to build it with the flags gradle is suggesting. Here's an example of how to do it, from your Cordova project root path:
Is this a case of a project that was created with v0.1.5 and then upgraded to v0.2.0?
I hope this was helpful. Please let us know if you figure out what's happening. |
@bil-ash Hello, I am also trying to setup the build env (for native modules) on WSL, since I have already installed the android SDK, NDK, etc on windows, Could I directly use them in the WSL context? Or actually I should install those things start from scratch on WSL? Any help is highly appreciated! Best regards, Jason |
@xeoshow You would have to install everything. wsl is linux without the gui. So you would have to install everything(nodejs,jdk,android sdk,ndk,etc) for linux(from within wsl) |
@bil-ash Understood and thank you so much! |
I have native modules working mostly great in a test app using Is there a good way to do this at the moment? Or do I just have to transplant parts of the |
Hi @DuBistKomisch , |
@jaimecbernardo thanks for confirming, no worries, will hack away at it for now. |
In your announcement blog post you write
How does this work exactly?
I'm trying to use the
ffi
on iOS. I ship my ownnode_modules
folder, which I add toprocess.env.NODE_PATH
at runtime.The issue is that
node-gyp
simply didn't build the native modules for arm64 in the first place.throws the following error:
Is it possible to build native node addons written in c++ (that use the v8 api or the newer N-API) to work with nodejs-mobile?
The text was updated successfully, but these errors were encountered: