Skip to content

Commit 24dae94

Browse files
authored
Allow generate-raw to run single witx files (#45)
* Make witx-bindgen run directly on witx files * Document how to use witx-bindgen * Update failed `assert_same_as_src` test instructions
1 parent 47bea2e commit 24dae94

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

crates/witx-bindgen/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# witx-bindgen
2+
3+
Generate Rust code matching a witx interface.
4+
5+
### Use
6+
7+
```
8+
cargo run [path to witx file]
9+
```

crates/witx-bindgen/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::env;
22
use std::path::PathBuf;
33

44
fn main() {
5-
let wasi_dir: PathBuf = env::args_os().nth(1).unwrap().into();
6-
let witx_path = wasi_dir.join("phases/snapshot/witx/wasi_snapshot_preview1.witx");
5+
let witx_path: PathBuf = env::args_os().nth(1).unwrap().into();
76
print!("{}", witx_bindgen::generate(&[witx_path]));
87
}

crates/witx-bindgen/tests/verify.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#[test]
22
fn assert_same_as_src() {
33
let actual = include_str!("../../../src/lib_generated.rs");
4-
let expected =
5-
witx_bindgen::generate(&["WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx"]);
4+
let witx_path = "WASI/phases/snapshot/witx/wasi_snapshot_preview1.witx";
5+
let expected = witx_bindgen::generate(&[witx_path]);
66
if actual == expected {
77
return;
88
}
99
panic!(
1010
"
1111
12-
the generate `raw.rs` does not match the actual source `raw.rs`, it's
12+
the generated `raw.rs` does not match the actual source `raw.rs`, it's
1313
recommended to run this command from the root of the repository:
1414
15-
cargo run -p witx-bindgen crates/witx-bindgen/WASI > src/lib_generated.rs
15+
cargo run -p witx-bindgen crates/witx-bindgen/{} > src/lib_generated.rs
1616
17-
"
17+
",
18+
witx_path
1819
);
1920
}

0 commit comments

Comments
 (0)