johnstonskj / rust-atelier

Rust native core model for the AWS Smithy IDL
MIT License
77 stars 11 forks source link

Use Wasm for plugin mechanism #40

Open eduardomourar opened 2 years ago

eduardomourar commented 2 years ago

Is your feature request related to a problem? Currently, plugins for Smithy can only be developed in Rust, but I would like to use TypeScript (AssemblyScript) instead.

Describe the solution you'd like By using a different plugin system based on Wasm [1], any language that can target WebAssembly (which includes Rust) can be used to extend Smithy. It is important to note that Rust provides first class support for WebAssembly [2] and that others have used that same mechanism successfully [3] [4].

Describe alternatives you've considered You can find a few alternatives with explanations in this blog post [4].

Additional context [1] https://webassembly.org/ [2] https://sendilkumarn.com/blog/rustwasm-introduction/ [3] https://istio.io/latest/docs/concepts/wasm/ [4] https://nullderef.com/blog/plugin-tech/#wasm

stevelr commented 2 years ago

I'm curious to know what's the use case. I'm not sure I get why a webassembly plugin makes sense here. Most of the rust-atelier features are in libraries already, and the plugin model as described in some of those links above are more applicable to servers or cli tools.

swaits commented 2 years ago

I second what stevelr says here. When I first saw the call for WASM plugins I was confused. I'm all for that in the right place, which is an application which wants to support loading foreign code in order to serve additional use cases without recompilation. For that, WASM is promising. However rust-atelier is a library meant to do one thing well, parse smithy and operate on the resulting models. WASM has no place here.

On Sun, Dec 5, 2021, at 15:25, stevelr wrote:

I'm curious to know what's the use case. I'm not sure I get why a webassembly plugin makes sense here. Most of the rust-atelier features are in libraries already, and the plugin model as described in some of those links above are more applicable to servers or cli tools.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/johnstonskj/rust-atelier/issues/40#issuecomment-986311714, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABRNBCAGDATAAZDIPCPY3UPPREBANCNFSM5JMAXJRQ.

johnstonskj commented 2 years ago

I wouldn't say it has no place, if there was a clear need to support polyglot plugins where anything that can compile to WASM works, it would be an interesting approach. Currently the intent is to support the Rust community with Rust-native tooling.

swaits commented 2 years ago

That's fair. "No place" is indeed strong. But still feels foreign to me.

On Mon, Dec 6, 2021, at 07:36, Simon Johnston wrote:

I wouldn't say it has no place, if there was a clear need to support polyglot plugins where anything that can compile to WASM works, it would be an interesting approach. Currently the intent is to support the Rust community with Rust-native tooling.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/johnstonskj/rust-atelier/issues/40#issuecomment-986834419, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABRNDOAF64V2UFT3TTJRDUPTC6TANCNFSM5JMAXJRQ.

eduardomourar commented 2 years ago

My intention here was to bring this up in the core Smithy repository (https://github.com/awslabs/smithy/issues/1001), but it makes more sense if using Rust than in Java where you would have the overhead of introducing another VM. From my personal perspective, I would like to use Smithy but I have limited knowledge of both Rust and Java (the same applies in the company I work for). So, if the AWS intention is to make the Smithy ecosystem broader, then Wasm should at least be considered as a viable approach.

stevelr commented 2 years ago

In case it's useful to anybody here, I wrote a rust library weld-codegen that uses rust-atelier to build models from .smithy files, and generate Rust traits, structures, and other types. The generated code does run in WebAssembly, and in fact does sort of support a plugin model (with wasmcloud). The only complete code generator is for Rust but more target languages should be supported in the future.

To be clear, weld-codegen (and rust-atelier that it's built on) is only invoked from cli tools, and there is no rust-atelier code being used from within the generated code or from WebAssembly. rust-atelier has dependencies on file io and other libraries that don't work in wasm. so porting it to wasm would take some non-trivial work.

The code generator is part of the open source wasmcloud ecosystem, but there aren't dependencies on wasmcloud and I hope that it can be generally useful to others for other purposes. Please let me know if you're interested in collaborating on it.