-
Notifications
You must be signed in to change notification settings - Fork 285
Rust/WASI example #619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I shot around in the dark too. The main thing is TinyGo builds in support for WASI and rust doesn't. That said, I agree this is time well spent to add something however it can be achieved. |
I'm wondering if we could piggy back off of this. https://github.com/bytecodealliance/wasi/blob/main/src/lib_generated.rs |
looks fine.. seems to have no dependency on wasmtime at the moment https://crates.io/crates/wasi/0.11.0+wasi-snapshot-preview1/dependencies If you'd like to give this a go, mainly just follow the structure of the allocation example and make a new directory with the same ("ish") code for rust that's done in tinygo? |
Ah, silly me. Rust already has a WASI implementation and toolchain. I can still work on getting a complete example created if that would be helpful.
More details are available here and https://github.com/bytecodealliance/wasi/blob/9ec04a7d8ebb1bbb9e3291503425cee1ec38a560/README.md?plain=1#L19-L21 |
silly me, too, then :) I think it would be worth doing one if you have time. try to lift the same templating from the allocation example, though I think you won't actually need the allocator in order to do the cat example. If you run out of time, you can still push an incomplete PR up and it would help vs starting from scratch! |
circling back on this, I started to make a rust/wasi example, but I think it is untenable to host the binary here as it is massive. Ex. if you build the cargo-wasi's hello world, it is almost 2MB. Ex. just this
If you do it manually with That's too large a binary to check into our source. It seems this is related to a dependency on wasi-libc, which we'll test directly with C. If that changes in the future, we can think about hosting a demo here, but meanwhile I think existing docs or a separate example repo are best. |
That works for me. The alternative is just to slap this at the top of the example go generate cargo build --release --target wasm32-wasi |
I'll add it to the README. good idea |
sorry I meant to say I'll add a how to into the README as I think primarily pointers were missing in how to find rust stuff. Rust is the most over served language in WebAssembly, most maintained, most docs, most control, most people working on it. Basically, I think with pointers to rust projects and also to our other rust example, should be good enough, especially with WASI as it should act the same regardless of toolchain. I don't really want to special-case a generation step over this, but that doesn't mean eliminate pointers to where to go in other words. |
Actually the release build using |
This uses cargo-wasi because the default target creates almost 2MB of wasm for a simple cat program. Fixes #619 Signed-off-by: Adrian Cole <[email protected]>
@codefromthecrypt thanks! Sorry for not getting around to rolling an example. Things got chaotic on my side, as always 🙄. |
This uses cargo-wasi because the default target creates almost 2MB of wasm for a simple cat program. Fixes #619
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
I've copied the WASI example nearly exactly but I can't seem to get it to work with a Rust guest, for example, my scripts panic when I try to use
time::Instant
, and the.WithArgs
aren't available when callingstd::env::args()
. Is there an example or anything special I need to do to get it working? If I were just shooting in the dark, I'd say that Rust just isn't expecting those host functions to go into thewasi_snapshot_preview1
module name, but again, I'm just spitballing.Describe the solution you'd like
An example of using Rust and WASI.
The text was updated successfully, but these errors were encountered: