napi-rs / napi-rs

A framework for building compiled Node.js add-ons in Rust via Node-API
https://napi.rs
Other
6k stars 267 forks source link

Support for Linking with libnode.so When Building for NodeJS-mobile on Android #1661

Open vincent-herlemont opened 1 year ago

vincent-herlemont commented 1 year ago

I'm trying to use napi-rs to create a native Node.js module for use with NodeJS-mobile on Android. In order to get native modules to work correctly with NodeJS-mobile on Android, they need to be linked with NodeJS-mobile's libnode.so at build time. This is because Android requires an entry for libnode.so in the ELF header of the module, or it will not look for the linked functions at runtime.

Related to https://github.com/JaneaSystems/nodejs-mobile-gyp/issues/4#issuecomment-459449632

# While loading a native node module, Android needs to have a
# (NEEDED) entry for libnode.so, or it won't be able to locate
# referenced symbols.
# We link to the binary libraries that are distributed with the
# nodejs-mobile headers so the (NEEDED) entry is created
[ 'target_arch=="arm"', {
  'libraries': ['>(node_root_dir)/bin/armeabi-v7a/libnode.so'],
}],
[ 'target_arch=="arm64"', {
  'libraries': ['>(node_root_dir)/bin/arm64-v8a/libnode.so'],
}],
[ 'target_arch=="x86"', {
  'libraries': ['>(node_root_dir)/bin/x86/libnode.so'],
}],
[ 'target_arch=="x86_64"', {
  'libraries': ['>(node_root_dir)/bin/x86_64/libnode.so'],
}],

Would it be possible to deal with that with napi-rs?

yorkie commented 9 months ago

Node.js provides linked binding for this usecase, this could be possible to work with napi-rs IMO.

Kreijstal commented 6 months ago

you might get away which just looking for the path in napi build.rs and linking statically