neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
8k stars 283 forks source link

Question on cargo-cp-artifact #960

Closed amarjanica closed 1 year ago

amarjanica commented 1 year ago

Hi, first of all, great project!

I recently published a node package https://www.npmjs.com/package/node-el-slugify?activeTab=explore, my first native module for node, and I have a couple of questions:

Sorry, maybe I'm using it all wrong :) Thanks!

kjvalencik commented 1 year ago

Yes, built in this way it will require Rust and the index.node doesn't need to be included. As of now, Neon does not have an official recommendation for delivering prebuilt binaries; however, there are several ways.

Method Advantage Disadvantage
Bundle index.nod for all platforms. Dynamically require the correct one. Simple Makes the native package very large
Publish platform specific versions of the module (e.g., node-el-slugify-macos-x86_64). These become optionalDependencies with a postinstall script that installs the correct one. Small bundle. Publishing lots of modules instead of one.
node-pre-gyp or similar to download the correct artifact from some store like S3 or Github releases. Small bundle, flexible and one package. Complicated.

Some of those are documented in https://github.com/neon-bindings/neon/issues/117. I am going to close this issue since I believe your request is covered by that, but feel free to ask more questions or we can re-open if I misunderstood.