From f46bcc5d9c3544b79f4c316ad766ebeeb11c8a70 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 9 Jul 2024 13:43:22 -0700 Subject: [PATCH] Print all WIT packages by default This commit changes the output of `wasm-tools component wit` to by default output all WIT packages using the multi-package syntax implemented in #1577. This means that a complete view of the WIT will be seen when running this command instead of just the top-level world. --- src/bin/wasm-tools/component.rs | 3 +-- src/lib.rs | 17 +++++++++-------- ...t-core-wasm-wit-multiple-packages.wit.stdout | 17 ++++++++++++++--- tests/cli/print-core-wasm-wit.wit.stdout | 17 ++++++++++++++--- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/bin/wasm-tools/component.rs b/src/bin/wasm-tools/component.rs index 08ac08db71..1b15b2f5a4 100644 --- a/src/bin/wasm-tools/component.rs +++ b/src/bin/wasm-tools/component.rs @@ -672,8 +672,7 @@ impl WitOpts { self.output.output( &self.general, Output::Wit { - resolve: &resolve, - ids: &main, + wit: &decoded, printer, }, )?; diff --git a/src/lib.rs b/src/lib.rs index ba5622ebc6..70210b8356 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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]), @@ -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::>(); + let output = printer.print(resolve, &ids, false)?; self.output_str(&output) } } diff --git a/tests/cli/print-core-wasm-wit-multiple-packages.wit.stdout b/tests/cli/print-core-wasm-wit-multiple-packages.wit.stdout index 75feb032d8..57c65fce90 100644 --- a/tests/cli/print-core-wasm-wit-multiple-packages.wit.stdout +++ b/tests/cli/print-core-wasm-wit-multiple-packages.wit.stdout @@ -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; + } } diff --git a/tests/cli/print-core-wasm-wit.wit.stdout b/tests/cli/print-core-wasm-wit.wit.stdout index e560f82ea0..c1eb1f6319 100644 --- a/tests/cli/print-core-wasm-wit.wit.stdout +++ b/tests/cli/print-core-wasm-wit.wit.stdout @@ -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; + } }