termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.9k stars 2.97k forks source link

NodeJS native extensions can't access libraries APIs #2674

Open nicolasnoble opened 6 years ago

nicolasnoble commented 6 years ago

I'm not sure if this one is even fixable, but the normal NodeJS runtime exposes libraries' API such as zlib or openssl to native addons. See https://nodejs.org/api/addons.html#addons_linking_to_node_js_own_dependencies

With termux's nodejs package, it seems this isn't working properly. See attached screenshot, when trying to load grpc (npm install grpc)

screenshot_20180721-013647

fornwall commented 5 years ago

@nicolasnoble Thanks for reporting!

Could this issue explain the problem: https://github.com/android-ndk/ndk/issues/201 or is it something else? Do you have any idea how to improve things (I don't know much about node.js internals myself)?

nicolasnoble commented 5 years ago

It's very likely the case, yes. NodeJS is expecting its dependencies to be transitively available to its addons. If LD_PRELOAD is a way to put the dependents in the global space, we could wrap the Node binary to make sure that all of its dependencies are pre-loaded.

I'll give it a try.

nicolasnoble commented 5 years ago

Yes, it's making it load using a wrapper script that LD_PRELOAD all the node libraries. I don't know yet if the module works properly, but that's outside the scope of this bug :-)

I'd recommend that the termux package ships with a similar script by renaming the binary to something else, and having the wrapper be the name "node", this way the node binary on Termux will behave the same as the official distribution.

image

nicolasnoble commented 5 years ago

Also, the module seems to be working flawlessly, so only the wrapper script around the node binary is needed to properly fix this issue.

stale[bot] commented 2 years ago

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

nicolasnoble commented 2 years ago

¯\(ツ)

xtkoba commented 2 years ago

The problem(?) is that there is more than one way to fix this.

I would rather do something like:

CXXFLAGS="-I$TERMUX_PREFIX/include" LDFLAGS="-L$TERMUX_PREFIX/lib -lz" npm install grpc

Of course the LD_PRELOAD hack will also work, as suggested above. And to patchelf the binaries is yet another.

twaik commented 7 months ago

Is this still reproducible?