Skip to content

Commit

Permalink
Update Wasmtime for upcoming WIT changes
Browse files Browse the repository at this point in the history
This PR integrates bytecodealliance/wasm-tools#1027 into Wasmtime. The
main changes here are:

* WIT syntax is updated with WebAssembly/component-model#193
* Generated bindings in the `bindgen!` macro have been updated to
  reflect the new structure of WIT.
* The accepted component model binary format has been updated to account
  for changes.

This PR disables wasi-http tests and the on-by-default feature because
the WIT syntax has been updated but the submodule containing the WITs
has not been updated yet so there's no way to get that building
temporarily. Once that's updated then this can be reenabled.
  • Loading branch information
alexcrichton committed May 17, 2023
1 parent 63ffbe2 commit cf306c4
Show file tree
Hide file tree
Showing 43 changed files with 444 additions and 249 deletions.
25 changes: 8 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ default = [
"vtune",
"wasi-nn",
"wasi-threads",
"wasi-http",
# TODO: the WIT needs to be updated
#"wasi-http",
"pooling-allocator",
]
jitdump = ["wasmtime/jitdump"]
Expand Down Expand Up @@ -288,3 +289,12 @@ debug-assertions = false
# string initializers.
overflow-checks = false

[patch.crates-io]
wasm-encoder = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wasm-mutate = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wasm-smith = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wasmparser = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wasmprinter = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wast = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wat = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
wit-parser = { git = 'https://github.com/alexcrichton/wasm-tools', branch = 'wit-changes' }
4 changes: 3 additions & 1 deletion ci/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

# TODO: add this flag back in
#--features "test-programs/test_programs_http" \

cargo test \
--features "test-programs/test_programs" \
--features "test-programs/test_programs_http" \
--features wasi-threads \
--workspace \
--exclude 'wasmtime-wasi-*' \
Expand Down
2 changes: 1 addition & 1 deletion cranelift/wasm/src/code_translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
));
}
Operator::I31New | Operator::I31GetS | Operator::I31GetU => {
unimplemented!("GC operators not yet implemented")
return Err(wasm_unsupported!("proposed GC operator {:?}", op));
}
};
Ok(())
Expand Down
26 changes: 13 additions & 13 deletions crates/component-macro/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,24 @@ impl Parse for Config {
if inline.is_some() {
return Err(Error::new(s.span(), "cannot specify a second source"));
}
inline = Some(format!("default world interfaces {{ {} }}", s.value()));
inline = Some(format!(
"
package wasmtime:component-macro-synthesized
world interfaces {{
{}
}}
",
s.value()
));

if world.is_some() {
return Err(Error::new(
s.span(),
"cannot specify a world with `interfaces`",
));
}
world = Some("macro-input.interfaces".to_string());
world = Some("interfaces".to_string());

opts.only_interfaces = true;
}
Expand Down Expand Up @@ -130,7 +139,7 @@ fn parse_source(
} else {
let pkg = UnresolvedPackage::parse_file(path)?;
files.extend(pkg.source_files().map(|s| s.to_owned()));
resolve.push(pkg, &Default::default())
resolve.push(pkg)
}
};

Expand All @@ -141,16 +150,7 @@ fn parse_source(
};

let inline_pkg = if let Some(inline) = inline {
let deps = resolve
.packages
.iter()
.map(|(id, p)| (p.name.clone(), id))
.collect();

Some(resolve.push(
UnresolvedPackage::parse("macro-input".as_ref(), &inline)?,
&deps,
)?)
Some(resolve.push(UnresolvedPackage::parse("macro-input".as_ref(), &inline)?)?)
} else {
None
};
Expand Down
6 changes: 0 additions & 6 deletions crates/component-macro/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ macro_rules! gentest {
mod sugar {
wasmtime::component::bindgen!(in $path);
}
mod normal {
wasmtime::component::bindgen!($name in $path);
}
mod async_ {
wasmtime::component::bindgen!({
path: $path,
Expand All @@ -16,15 +13,12 @@ macro_rules! gentest {
mod tracing {
wasmtime::component::bindgen!({
path: $path,
world: $name,
tracing: true,
duplicate_if_necessary: true,
});
}
}
// ...
};

}

component_macro_test_helpers::foreach!(gentest);
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/char.wit
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package foo:foo

interface chars {
/// A function that accepts a character
take-char: func(x: char)
/// A function that returns a character
return-char: func() -> char
}

default world the-world {
import imports: self.chars
export exports: self.chars
world the-world {
import chars
export chars
}
7 changes: 4 additions & 3 deletions crates/component-macro/tests/codegen/conventions.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// hello 🐱 world
package foo:foo

interface conventions {
kebab-case: func()
Expand Down Expand Up @@ -32,7 +33,7 @@ interface conventions {
%bool: func()
}

default world the-world {
import imports: self.conventions
export exports: self.conventions
world the-world {
import conventions
export conventions
}
4 changes: 3 additions & 1 deletion crates/component-macro/tests/codegen/direct-import.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
default world foo {
package foo:foo

world foo {
import foo: func()
}
3 changes: 2 additions & 1 deletion crates/component-macro/tests/codegen/empty.wit
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
default world empty {}
package foo:foo
world empty {}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/flags.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface flegs {
flags flag1 {
b0,
Expand Down Expand Up @@ -47,7 +49,7 @@ interface flegs {
roundtrip-flag64: func(x: flag64) -> flag64
}

default world the-flags {
import import-flags: self.flegs
export export-flags: self.flegs
world the-flags {
import flegs
export flegs
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/floats.wit
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package foo:foo

interface floats {
float32-param: func(x: float32)
float64-param: func(x: float64)
float32-result: func() -> float32
float64-result: func() -> float64
}

default world the-world {
import imports: self.floats
export exports: self.floats
world the-world {
import floats
export floats
}
3 changes: 2 additions & 1 deletion crates/component-macro/tests/codegen/function-new.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
default world foo {
package foo:foo
world foo {
export new: func()
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/integers.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface integers {
a1: func(x: u8)
a2: func(x: s8)
Expand Down Expand Up @@ -32,7 +34,7 @@ interface integers {
pair-ret: func() -> tuple<s64, u8>
}

default world the-world {
import imports: self.integers
export exports: self.integers
world the-world {
import integers
export integers
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/lists.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface lists {
list-u8-param: func(x: list<u8>)
list-u16-param: func(x: list<u16>)
Expand Down Expand Up @@ -77,7 +79,7 @@ interface lists {
load-store-everything: func(a: load-store-all-sizes) -> load-store-all-sizes
}

default world the-lists {
import import-lists: self.lists
export export-lists: self.lists
world the-lists {
import lists
export lists
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/many-arguments.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface manyarg {
many-args: func(
a1: u64,
Expand Down Expand Up @@ -44,7 +46,7 @@ interface manyarg {
big-argument: func(x: big-struct)
}

default world the-world {
import imports: self.manyarg
export exports: self.manyarg
world the-world {
import manyarg
export manyarg
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/multi-return.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface multi-return {
mra: func()
mrb: func() -> ()
Expand All @@ -6,7 +8,7 @@ interface multi-return {
mre: func() -> (a: u32, b: float32)
}

default world the-world {
import imports: self.multi-return
export exports: self.multi-return
world the-world {
import multi-return
export multi-return
}
8 changes: 5 additions & 3 deletions crates/component-macro/tests/codegen/records.wit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package foo:foo

interface records {
tuple-arg: func(x: tuple<char, u32>)
tuple-result: func() -> tuple<char, u32>
Expand Down Expand Up @@ -53,7 +55,7 @@ interface records {
typedef-inout: func(e: tuple-typedef2) -> s32
}

default world the-world {
import imports: self.records
export exports: self.records
world the-world {
import records
export records
}
10 changes: 6 additions & 4 deletions crates/component-macro/tests/codegen/rename.wit
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package foo:foo

interface red {
use self.green.{thing}
use green.{thing}

foo: func() -> thing
}
Expand All @@ -8,7 +10,7 @@ interface green {
type thing = s32
}

default world neptune {
import blue: self.red
import orange: self.green
world neptune {
import red
import green
}
Loading

0 comments on commit cf306c4

Please sign in to comment.