Skip to content

Commit

Permalink
Print all WIT packages by default
Browse files Browse the repository at this point in the history
This commit changes the output of `wasm-tools component wit` to by
default output all WIT packages using the multi-package syntax
implemented in bytecodealliance#1577. This means that a complete view of the WIT will be
seen when running this command instead of just the top-level world.
  • Loading branch information
alexcrichton committed Jul 9, 2024
1 parent a1a5f7b commit f46bcc5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/bin/wasm-tools/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,7 @@ impl WitOpts {
self.output.output(
&self.general,
Output::Wit {
resolve: &resolve,
ids: &main,
wit: &decoded,
printer,
},
)?;
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ pub struct OutputArg {
pub enum Output<'a> {
#[cfg(feature = "component")]
Wit {
resolve: &'a wit_parser::Resolve,
ids: &'a [wit_parser::PackageId],
wit: &'a wit_component::DecodedWasm,
printer: wit_component::WitPrinter,
},
Wasm(&'a [u8]),
Expand Down Expand Up @@ -233,12 +232,14 @@ impl OutputArg {
}
Output::Json(s) => self.output_str(s),
#[cfg(feature = "component")]
Output::Wit {
resolve,
ids,
mut printer,
} => {
let output = printer.print(resolve, ids, false)?;
Output::Wit { wit, mut printer } => {
let resolve = wit.resolve();
let ids = resolve
.packages
.iter()
.map(|(id, _)| id)
.collect::<Vec<_>>();
let output = printer.print(resolve, &ids, false)?;
self.output_str(&output)
}
}
Expand Down
17 changes: 14 additions & 3 deletions tests/cli/print-core-wasm-wit-multiple-packages.wit.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package root:root;
package root:root {
world root {
import bar:bar/my-interface;
}
}


package bar:bar {
interface my-interface {
foo: func();
}

world root {
import bar:bar/my-interface;
world my-world {
import my-interface;
}
}
17 changes: 14 additions & 3 deletions tests/cli/print-core-wasm-wit.wit.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package root:root;
package root:root {
world root {
import foo:foo/my-interface;
}
}


package foo:foo {
interface my-interface {
foo: func();
}

world root {
import foo:foo/my-interface;
world my-world {
import my-interface;
}
}

0 comments on commit f46bcc5

Please sign in to comment.