Skip to content

Commit fd6ea3f

Browse files
authored
Add a CLI flag to skip wit-component process (#40)
Can possibly be helpful when debugging various things.
1 parent c15e02d commit fd6ea3f

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ struct ComponentLdArgs {
280280
/// only used when one or more `--component-type` options are specified.
281281
#[clap(long, value_parser = parse_encoding, default_value = "utf8")]
282282
string_encoding: StringEncoding,
283+
284+
/// Skip the `wit-component`-based process to generate a component.
285+
#[clap(long)]
286+
skip_wit_component: bool,
283287
}
284288

285289
fn parse_adapter(s: &str) -> Result<(String, Vec<u8>)> {
@@ -525,7 +529,7 @@ impl App {
525529
// output directly at the desired output location. Otherwise output to a
526530
// temporary location for wit-component to read and then the real output
527531
// is created after wit-component runs.
528-
if self.shared {
532+
if self.skip_wit_component() {
529533
cmd.arg("-o").arg(self.component.output.as_ref().unwrap());
530534
} else {
531535
cmd.arg("-o").arg(lld_output.path());
@@ -541,9 +545,7 @@ impl App {
541545
bail!("failed to invoke LLD: {status}");
542546
}
543547

544-
// Skip componentization with `--shared` since that's creating a shared
545-
// library that's not a component yet.
546-
if self.shared {
548+
if self.skip_wit_component() {
547549
return Ok(());
548550
}
549551

@@ -640,6 +642,13 @@ impl App {
640642
Ok(())
641643
}
642644

645+
fn skip_wit_component(&self) -> bool {
646+
self.component.skip_wit_component
647+
// Skip componentization with `--shared` since that's creating a
648+
// shared library that's not a component yet.
649+
|| self.shared
650+
}
651+
643652
fn lld(&self) -> Command {
644653
let mut lld = self.find_lld();
645654
lld.args(&self.lld_args);

tests/all.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ fn assert_component(bytes: &[u8]) {
5050
wasmparser::Validator::new().validate_all(&bytes).unwrap();
5151
}
5252

53+
fn assert_module(bytes: &[u8]) {
54+
assert!(wasmparser::Parser::is_core_wasm(&bytes));
55+
wasmparser::Validator::new().validate_all(&bytes).unwrap();
56+
}
57+
5358
#[test]
5459
fn empty() {
5560
let output = compile(&["--crate-type", "cdylib"], "");
@@ -177,3 +182,15 @@ world root {
177182
);
178183
assert_component(&output);
179184
}
185+
186+
#[test]
187+
fn skip_component() {
188+
let output = compile(
189+
&["-Clink-arg=--skip-wit-component"],
190+
r#"
191+
fn main() {
192+
}
193+
"#,
194+
);
195+
assert_module(&output);
196+
}

0 commit comments

Comments
 (0)