Skip to content

Commit

Permalink
Add a CLI flag to skip wit-component process (#40)
Browse files Browse the repository at this point in the history
Can possibly be helpful when debugging various things.
  • Loading branch information
alexcrichton authored Aug 28, 2024
1 parent c15e02d commit fd6ea3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>)> {
Expand Down Expand Up @@ -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());
Expand All @@ -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(());
}

Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"], "");
Expand Down Expand Up @@ -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);
}

0 comments on commit fd6ea3f

Please sign in to comment.