synadia-io / nex

The NATS execution engine
https://docs.nats.io/using-nats/nex
Apache License 2.0
184 stars 14 forks source link

Arm and Mac M-Series Support for V8 #331

Open MikeHawkesCapventis opened 1 month ago

MikeHawkesCapventis commented 1 month ago

Proposed change

I love the functionality of nex and would like to extend the V8 services to 'wrap' our own libraries. I can do this by editing v8.go (I almost raised an issue to suggest providing an abstraction to allow devs to add functions to the v8 layer, but guess that's beyond the scope of nex). However, the current build restricts v8 compilation to linux/amd64, so we're unable to develop lambda-style functions on Mac M-series or Arm machines without running something like Ubuntu emulations.

The lambda-style functions are extremely exciting to us - even more so if we can get it on different architectures.

Use case

V8 function development and deployment on NATS/Nex for Mac M-Series and Arm devices.

Contribution

Potentially looking at this - but not. yet. If you already have something in the pipeline, then I'd prefer to go with the official build.

autodidaddict commented 1 month ago

The limitation on V8 execution is coming from the V8 library itself. It will only work in a small set of targets. We've been checking into the possibility of providing a more broadly supported JavaScript runtime. Until then, plugins are a workaround.

We now have pluggable workload execution providers, so one could be written that uses a different JavaScript hosting engine than what we're using now.

MikeHawkesCapventis commented 1 month ago

Thanks for the reply - I get where you're coming from. The pluggable execution providers will definitely help.

Having had a delve, I managed to get everything compiling in a dev container on the Mac - the trick being to build the environment using a docker file with platform: linux/amd64 - that lets me build and run (in no_sandbox mode). With that I could then edit the v8.go to put an extra global object after the hostServices... you add. That brought our custom functions into the V8 environment without issue - the only downside being that I had to edit your v8.go to do it.

Overall, it's got to a good place ... with just a little inconvenience / hackery around extensions for V8. I appreciate it's a bit of a V8 vs Nex thing, but it is relatively easy to do. For the Arm and Mac executables, I think we might end up resorting to something like github.com/robertkrimen/otto just for the ease of adding functions in go natively.