From fd6ea3faeb952bae0a2b4573a08d4192b5895dca Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 28 Aug 2024 10:20:43 -0500 Subject: [PATCH] Add a CLI flag to skip wit-component process (#40) Can possibly be helpful when debugging various things. --- src/lib.rs | 17 +++++++++++++---- tests/all.rs | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b536601..d188e4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -280,6 +280,10 @@ struct ComponentLdArgs { /// only used when one or more `--component-type` options are specified. #[clap(long, value_parser = parse_encoding, default_value = "utf8")] string_encoding: StringEncoding, + + /// Skip the `wit-component`-based process to generate a component. + #[clap(long)] + skip_wit_component: bool, } fn parse_adapter(s: &str) -> Result<(String, Vec)> { @@ -525,7 +529,7 @@ impl App { // output directly at the desired output location. Otherwise output to a // temporary location for wit-component to read and then the real output // is created after wit-component runs. - if self.shared { + if self.skip_wit_component() { cmd.arg("-o").arg(self.component.output.as_ref().unwrap()); } else { cmd.arg("-o").arg(lld_output.path()); @@ -541,9 +545,7 @@ impl App { bail!("failed to invoke LLD: {status}"); } - // Skip componentization with `--shared` since that's creating a shared - // library that's not a component yet. - if self.shared { + if self.skip_wit_component() { return Ok(()); } @@ -640,6 +642,13 @@ impl App { Ok(()) } + fn skip_wit_component(&self) -> bool { + self.component.skip_wit_component + // Skip componentization with `--shared` since that's creating a + // shared library that's not a component yet. + || self.shared + } + fn lld(&self) -> Command { let mut lld = self.find_lld(); lld.args(&self.lld_args); diff --git a/tests/all.rs b/tests/all.rs index bacdc78..c6eee66 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -50,6 +50,11 @@ fn assert_component(bytes: &[u8]) { wasmparser::Validator::new().validate_all(&bytes).unwrap(); } +fn assert_module(bytes: &[u8]) { + assert!(wasmparser::Parser::is_core_wasm(&bytes)); + wasmparser::Validator::new().validate_all(&bytes).unwrap(); +} + #[test] fn empty() { let output = compile(&["--crate-type", "cdylib"], ""); @@ -177,3 +182,15 @@ world root { ); assert_component(&output); } + +#[test] +fn skip_component() { + let output = compile( + &["-Clink-arg=--skip-wit-component"], + r#" +fn main() { +} + "#, + ); + assert_module(&output); +}