Closed abrown closed 2 years ago
Gentle ping @abrown.
Hi,
I'm curious, is there a way to check out the correctness of the syntax of the wasi-nn.witx
? I'm trying to use witx-codegen
to generate the official wasi-nn types and interfaces, but went into a mistake when witnext
unable to parse the wasi-nn.witx
file.
To further test it, I also tried witx-bindgen
, which seems to be used to generate the current rust interface. But still, unable to parse.
I rolled back the master
branch to test the old wasi_ephemeral_nn.witx
and still got the same parse errors.
Errors' log for witx-bindgen
:
↪ RUST_BACKTRACE=1 cargo run ~/Desktop/wasm/wasi-nn/phases/ephemeral/witx/wasi_ephemeral_nn.witx
Finished dev [unoptimized + debuginfo] target(s) in 0.09s
Running `/Users/gus/Desktop/wasm/wasi/target/debug/witx-bindgen /Users/gus/Desktop/wasm/wasi-nn/phases/ephemeral/witx/wasi_ephemeral_nn.witx`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parse(Error { inner: ErrorInner { text: Some(Text { line: 17, col: 8, snippet: " (enum u16" }), file: Some("/Users/gus/Desktop/wasm/wasi-nn/phases/ephemeral/witx/wasi_ephemeral_nn.witx"), span: Span { offset: 944 }, kind: Custom("expected an identifier") } })', /Users/gus/Desktop/wasm/wasi/crates/witx-bindgen/src/lib.rs:9:38
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::result::unwrap_failed
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
3: core::result::Result<T,E>::unwrap
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1018:23
4: witx_bindgen::generate
at ./src/lib.rs:9:15
5: witx_bindgen::main
at ./src/main.rs:9:18
6: core::ops::function::FnOnce::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
Errors' log for witx-codegen
:
↪ RURUST_BACKTRACE=1 target/debug/witx-codegen --output-type cpp ~/Desktop/wasm/wasi-nn/phases/ephemeral/witx/wasi_ephemeral_nn.witx
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parse(Error { inner: ErrorInner { text: Some(Text { line: 12, col: 0, snippet: "(typename $buffer_size u32)" }), file: Some("/Users/gus/Desktop/wasm/wasi-nn/phases/ephemeral/witx/wasi_ephemeral_nn.witx"), span: Span { offset: 757 }, kind: Custom("extra tokens remaining after parse") } })', src/lib.rs:123:42
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::result::unwrap_failed
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1690:5
3: core::result::Result<T,E>::unwrap
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/result.rs:1018:23
4: witx_codegen::generate
at ./src/lib.rs:123:20
5: witx_codegen::main
at ./src/main.rs:11:5
6: core::ops::function::FnOnce::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@gusye1234, thanks for the heads up. Let me take a look tomorrow and see if I can't replicate what you found.
@gusye1234, I looked into this today and I'm not sure I can replicate what you see. One issue is that I'm not familiar with witnext
and witx-codegen
so I only tried witx-bindgen
and that seemed to work. I also wonder if the switch that happened from master
to main
some time ago might be causing some issues. But, anyways, here is what I found:
witx-bindgen
:$ cd .../wasi/crates/witx-bindgen
$ git checkout main
$ git pull
$ git submodule update --init
$ cargo build
$ file ../../target/debug/witx-bindgen
$ cd .../wasi-nn
$ git checkout main
$ git pull
$ ../../wasi/target/debug/witx-bindgen ../../wasi-nn/wasi-nn.witx
Not sure what is going on with your environment; does this step-by-step explanation highlight anything that might be different?
Thanks for your detailed reply!
I cleaned out all my local repos and ran the witx-bindgen
following your scripts, It works now.
Probably there were some files outdated.
After some discussion with
wit-bindgen
maintainers, it is clear that that tool is not yet ready to use for implementing WASI APIs inside engines (e.g., Wasmtime). Since the existing Wasmtime infrastructure,wiggle
, uses the WITX syntax, this change re-adds the WITX version of the wasi-nn API. This allowswiggle
to continue to pull the WITX specification directly from this repository until it is replaced bywit-bindgen
. All documentation has been removed fromwasi-nn.witx
since we expect the WIT version to be the official version (at some point, it would be nice to check in CI that the WITX and WIT versions expose an identical API but this API does not do that).