buttplug-rs-ffi icon indicating copy to clipboard operation
buttplug-rs-ffi copied to clipboard

Add node native bindings and prebuild

Open itsame-luigi opened this issue 3 years ago • 4 comments

This adds native bindings for NodeJS, instead of depending on a WASM build. The WASM build is still used for the browser. I also added a script to run on npm install that will fetch a specific release build (configured in package.json as "ffi-version").

Also, it is no longer necessary to invoke buttplugInit() in NodeJS (though it is still necessary in the browser).

There are a few things that still need to be worked out and tested:

  • [x] Testing prebuilds of the bindings.
  • [ ] Testing on other OSes (only tested in Windows so far)
  • ~~I could not get rust to build x64 dll on Windows for some reason, so the script currently fetches a release build. I'm not familiar enough with Rust to resolve this currently.~~
    • I was able to work out the issue with x64 builds, but I'm still fetching latest from the github releases since that happens on install anyways.

itsame-luigi avatar Jul 02 '21 07:07 itsame-luigi

I've made some progress on this, and done some additional cleanup on the js side. I've removed the parts of modularize.cjs that dealt with WASM functionality in NodeJS that I added in #80, since WASM is no longer used for NodeJS. I've also changed the browser-specific build outputs back to ./dist/web/... to keep the URL consistent for anyone loading via CDN.

I've also reorganized the scripts in package.json to break things down by build task, and added some clean tasks to make it easier to get back to a clean JS environment.

With these changes, the web output should be mostly unchanged from what it was prior to #80, except for a minor source path change as I moved src/buttplug-rs-ffi to src/web/buttplug-rs-ffi to keep the "node"- and "web"-specific components isolated from each other.

I need to run a few more tests in NodeJS by installing the package on various OSes (probably by packing it into a tarball to avoid needing to publish to npm), but the overall design should be fairly solid now.

itsame-luigi avatar Aug 09 '21 09:08 itsame-luigi

Also, it seems the "Core Library + Nuget" builds are failing though I haven't made any changes that should be causing those errors. I'm not sure if its just because its a PR from a forked repository, or if there's some other reason for the failure.

It does look like the CI setup needs to include a scenario for building/testing JS.

itsame-luigi avatar Aug 09 '21 09:08 itsame-luigi

@qdot, I think this is as ready as I can make it, if you're able to review.

I can't test the new Nodejs bindings on MacOS, but I've tested it on Windows. I can try and see if it works on Linux via WSL, but I don't have any physical hardware with Linux+Bluetooth aside from WSL.

itsame-luigi avatar Aug 15 '21 02:08 itsame-luigi

Great, thanks for letting me know! Right now I'm neck deep in trying to release buttplug v5, but once that's done I'm hoping to take a look at this. I've got all 3 platforms running on dedicated hardware so I can test those too.

qdot avatar Aug 15 '21 07:08 qdot