vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.33k stars 1.02k forks source link

Impossible to link to own shared library from native node module #1911

Closed Zubnix closed 1 year ago

Zubnix commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18

What operating system are you using?

Ubuntu 22.10

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node18-linux-x64

Describe the Bug

Currently Pkg extracts the native node modules to disk so it can be loaded by node (as per the docs). However, occasionally these native node modules can link to other shared libraries inside node_modules (often build & packaged in the same dependency). What happens is that Pkg can not find these 'deeply nested' native dependencies as it has no idea what do with these even if you include them as an asset.

Expected Behavior

Pkg should probably not try to handle this automatically as this could be quite complex (hello LD functionality), however this could easily be resolved by allowing the user to provide a set of assets which should be extracted alongside a native node module.

To Reproduce

build a native node module that links to a shared foo library that is not available on the system (but is packaged in node_modules and included as an asset). Run the generated executable and witness: Error: libfoo.so: cannot open shared object file: No such file or directory

clarkttfu commented 1 year ago

The only way I found working is to link to absolute path, and put an extra copy of the shared library there 😮‍💨

Zubnix commented 1 year ago

I "solved" it by copying the native dependencies next to the executable, and running the executable through a separate script with an LD_PRELOAD env var set. Obviously this only works on Linux (Mac too?).

clarkttfu commented 1 year ago

I found the dlopen code in the other issues. So I hack ed the code a little bit to extract my shared lib (as asset) to same path of the dependent native addon. It's hard coded but avoid distributing extra files though..

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 1 year ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.