-
Notifications
You must be signed in to change notification settings - Fork 83
How can I use WASI to open a file? #48
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
Can you try changing this: wasi, err := wasmtime.NewWasiInstance(store, wasiConfig, "wasi_unstable") To this: wasi, err := wasmtime.NewWasiInstance(store, wasiConfig, "wasi_snapshot_preview1") I think that might do it. |
Thanks. Does it mean the WASM binary was compiled against the changed helped but now I get this
|
Yes, I believe Can you show your rust code? It looks like your code might be panicking on an option |
Sure, this is the #[no_mangle]
pub extern "C" fn run_nom() {
let data = std::fs::read_to_string("data/small_access.log").unwrap();
let p = nom::CommonLogParser { input: &data };
assert_eq!(p.count(), 161761);
} EDIT: I changed the code to print the error
|
Maybe better docs here: http://docs.wasmtime.dev/c-api/wasi_8h.html#a6d738a3510c5f3aa4a6f49d7bb658cd1 If you click into the Go src you can usually find which function is being called in the wasmtime C api. Maybe try |
Thanks for the link. Still no luck. I tried a few combinations such as |
Can't get it working either. Maybe it's this issue? rust-lang/rust#79199 |
@maxmcd, thanks so much for your help. This seems to be it 🙂 |
btw, in case it's unclear. I was able to get your code working by just using the parse.wasm output. Since the parse wasm binary isn't a lib it seems to work if I update That then runs this code: https://github.com/jeschkies/common-log-parser-bench/blob/karsten/go/src/bin/parse.rs#L5 And finds the right file |
Thanks. That helped me with my original goal. I wanted to benchmark nom in WASM. How did you pass the argument to |
To confirm, I think everything here's been figured out? Or are there lingering questions I could help resolve? |
I'm not sure how to pass the main args to a WASM. However, that should be unrelated to this issue. I guess rust-lang/rust#79199 will solve this issue. |
Ah yeah I believe that'll solve those issues. In that case I'll go ahead and close this issue. |
@jeschkies you might just want to use command line arguments or environment variables. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
maybe there is some documentation somewhere but I just cannot figure out how to run a WASM binary from Go with wasmtime.
I compiled a Rust program to wasm with
cargo wasi build --release
. I want to call a method from Golang and wrote the following simple example:It prints the required imports
fd_close fd_filestat_get fd_read fd_write path_open proc_exit environ_sizes_get environ_get
and the fails with the errorpanic: unknown import:
wasi_snapshot_preview1::fd_closehas not been defined
. Shouldn'tPreopenDir
definefd_close
?How can I define the imports?
Thanks a lot 🙂
PS: I am happy to contribute with an example in the docs.
The text was updated successfully, but these errors were encountered: