Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
with:
submodules: true
- name: Install Rust
run: rustup update nightly --no-self-update && rustup default nightly
run: rustup update stable --no-self-update && rustup default stable
- run: rustup target add wasm32-wasip2
- uses: ./.github/actions/install-wasi-sdk
- run: |
Expand Down
17 changes: 7 additions & 10 deletions crates/test/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res

// Now compile the runner's source code to with the above object and the
// component-type object into a final component.
let output = if produces_component(runner) {
compile.output.to_path_buf()
} else {
compile.output.with_extension("core.wasm")
};
let output = compile.output.with_extension("core.wasm");
let mut cmd = Command::new(compiler);
cmd.arg(&compile.component.path)
.arg(&bindings_object)
Expand All @@ -154,13 +150,14 @@ fn compile(runner: &Runner<'_>, compile: &Compile<'_>, compiler: PathBuf) -> Res
cmd.arg("-mexec-model=reactor");
}
}
if produces_component(runner) {
cmd.arg("-Wl,--skip-wit-component");
}
runner.run_command(&mut cmd)?;

if !produces_component(runner) {
runner
.convert_p1_to_component(&output, compile)
.with_context(|| format!("failed to convert {output:?}"))?;
}
runner
.convert_p1_to_component(&output, compile)
.with_context(|| format!("failed to convert {output:?}"))?;
Ok(())
}

Expand Down
29 changes: 22 additions & 7 deletions crates/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,17 @@ status: {}",
.context("failed to load WIT")?;
let world = resolve.select_world(&[pkg], Some(&compile.component.bindgen.world))?;
let mut module = fs::read(&p1).context("failed to read wasm file")?;
let encoded = wit_component::metadata::encode(&resolve, world, StringEncoding::UTF8, None)?;

let section = wasm_encoder::CustomSection {
name: Cow::Borrowed("component-type"),
data: Cow::Borrowed(&encoded),
};
module.push(section.id());
section.encode(&mut module);
if !has_component_type_sections(&module) {
let encoded =
wit_component::metadata::encode(&resolve, world, StringEncoding::UTF8, None)?;
let section = wasm_encoder::CustomSection {
name: Cow::Borrowed("component-type"),
data: Cow::Borrowed(&encoded),
};
module.push(section.id());
section.encode(&mut module);
}

let wasi_adapter = match compile.component.kind {
Kind::Runner => {
Expand Down Expand Up @@ -1071,6 +1074,18 @@ status: {}",
}
}

fn has_component_type_sections(wasm: &[u8]) -> bool {
for payload in wasmparser::Parser::new(0).parse_all(wasm) {
match payload {
Ok(wasmparser::Payload::CustomSection(s)) if s.name().starts_with("component-type") => {
return true
}
_ => {}
}
}
false
}

struct StepResult<'a> {
result: Result<()>,
should_fail: bool,
Expand Down
17 changes: 7 additions & 10 deletions crates/test/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ path = 'lib.rs'
// If this rust target doesn't natively produce a component then place
// the compiler output in a temporary location which is componentized
// later on.
let output = if runner.produces_component() {
compile.output.to_path_buf()
} else {
compile.output.with_extension("core.wasm")
};
let output = compile.output.with_extension("core.wasm");

// Compile all extern crates, if any
let mut externs = Vec::new();
Expand Down Expand Up @@ -216,13 +212,14 @@ path = 'lib.rs'
cmd.arg("--crate-type=cdylib");
}
}
if runner.produces_component() {
cmd.arg("-Clink-arg=--skip-wit-component");
}
runner.run_command(&mut cmd)?;

if !runner.produces_component() {
runner
.convert_p1_to_component(&output, compile)
.with_context(|| format!("failed to convert {output:?}"))?;
}
runner
.convert_p1_to_component(&output, compile)
.with_context(|| format!("failed to convert {output:?}"))?;

Ok(())
}
Expand Down