Skip to content

Commit 61e1c3e

Browse files
authored
Upgrade to wasm-tools 211 and wasmtime 21 (#978)
* upgrade to wasm-tools 211 * upgrade to wasmtime 21 * tests: update for wasmtime 21 in wasmtime 21, component::bindgen stopped making import functions trappable unless you ask for them specifically, which is a great idea and I totally missed it when it landed. Lots of text diff but ultimately getting rid of the totally-unused ability to trap in import functions. * fix test-helpers * fix c codegen test * fix new code introduced on main
1 parent 4336237 commit 61e1c3e

30 files changed

+416
-460
lines changed

Cargo.lock

Lines changed: 164 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ indexmap = "2.0.0"
3030
prettyplease = "0.2.20"
3131
syn = { version = "2.0", features = ["printing"] }
3232

33-
wasmparser = "0.209.0"
34-
wasm-encoder = "0.209.0"
35-
wasm-metadata = "0.209.0"
36-
wit-parser = "0.209.0"
37-
wit-component = "0.209.0"
33+
wasmparser = "0.211.0"
34+
wasm-encoder = "0.211.0"
35+
wasm-metadata = "0.211.0"
36+
wit-parser = "0.211.0"
37+
wit-component = "0.211.0"
3838

3939
wit-bindgen-core = { path = 'crates/core', version = '0.26.0' }
4040
wit-bindgen-c = { path = 'crates/c', version = '0.26.0' }
@@ -81,8 +81,8 @@ csharp-mono = ['csharp']
8181

8282
[dev-dependencies]
8383
heck = { workspace = true }
84-
wasmtime = { version = "20.0.0", features = ['component-model'] }
85-
wasmtime-wasi = { version = "20.0.0" }
84+
wasmtime = { version = "21.0.0", features = ['component-model'] }
85+
wasmtime-wasi = { version = "21.0.0" }
8686
test-artifacts = { path = 'crates/test-rust-wasm/artifacts' }
8787
wit-parser = { workspace = true }
8888
wasmparser = { workspace = true }

crates/c/tests/codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use heck::*;
33
use std::env;
44
use std::path::{Path, PathBuf};
55
use std::process::Command;
6-
use wit_parser::{Resolve, UnresolvedPackage};
6+
use wit_parser::{Resolve, UnresolvedPackageGroup};
77

88
macro_rules! codegen_test {
99
($id:ident $name:tt $test:tt) => {
@@ -94,8 +94,8 @@ fn rename_option() -> Result<()> {
9494
opts.rename.push(("c".to_string(), "rename3".to_string()));
9595

9696
let mut resolve = Resolve::default();
97-
let pkg = resolve.push(UnresolvedPackage::parse(
98-
"input.wit".as_ref(),
97+
let pkgs = resolve.push_group(UnresolvedPackageGroup::parse(
98+
"input.wit",
9999
r#"
100100
package foo:bar;
101101
@@ -118,7 +118,7 @@ fn rename_option() -> Result<()> {
118118
}
119119
"#,
120120
)?)?;
121-
let world = resolve.select_world(pkg, None)?;
121+
let world = resolve.select_world(&pkgs, None)?;
122122
let mut files = Default::default();
123123
opts.build().generate(&resolve, world, &mut files)?;
124124
for (file, contents) in files.iter() {

crates/guest-rust/macro/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
66
use syn::parse::{Error, Parse, ParseStream, Result};
77
use syn::punctuated::Punctuated;
88
use syn::{braced, token, Token};
9-
use wit_bindgen_core::wit_parser::{PackageId, Resolve, UnresolvedPackage, WorldId};
9+
use wit_bindgen_core::wit_parser::{PackageId, Resolve, UnresolvedPackageGroup, WorldId};
1010
use wit_bindgen_rust::{Opts, Ownership, WithOption};
1111

1212
#[proc_macro]
@@ -131,10 +131,10 @@ impl Parse for Config {
131131
source = Some(Source::Path(input.parse::<syn::LitStr>()?.value()));
132132
}
133133
}
134-
let (resolve, pkg, files) =
134+
let (resolve, pkgs, files) =
135135
parse_source(&source, &features).map_err(|err| anyhow_to_syn(call_site, err))?;
136136
let world = resolve
137-
.select_world(pkg, world.as_deref())
137+
.select_world(&pkgs, world.as_deref())
138138
.map_err(|e| anyhow_to_syn(call_site, e))?;
139139
Ok(Config {
140140
opts,
@@ -149,7 +149,7 @@ impl Parse for Config {
149149
fn parse_source(
150150
source: &Option<Source>,
151151
features: &[String],
152-
) -> anyhow::Result<(Resolve, PackageId, Vec<PathBuf>)> {
152+
) -> anyhow::Result<(Resolve, Vec<PackageId>, Vec<PathBuf>)> {
153153
let mut resolve = Resolve::default();
154154
resolve.features.extend(features.iter().cloned());
155155
let mut files = Vec::new();
@@ -164,7 +164,7 @@ fn parse_source(
164164
if let Some(p) = path {
165165
parse(&root.join(p))?;
166166
}
167-
resolve.push(UnresolvedPackage::parse("macro-input".as_ref(), s)?)?
167+
resolve.push_group(UnresolvedPackageGroup::parse("macro-input", s)?)?
168168
}
169169
Some(Source::Path(s)) => parse(&root.join(s))?,
170170
None => parse(&root.join("wit"))?,

crates/test-helpers/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ pub fn run_component_codegen_test(
143143

144144
fn parse_wit(path: &Path) -> (Resolve, WorldId) {
145145
let mut resolve = Resolve::default();
146-
let (pkg, _files) = resolve.push_path(path).unwrap();
147-
let world = resolve.select_world(pkg, None).unwrap_or_else(|_| {
146+
let (pkgs, _files) = resolve.push_path(path).unwrap();
147+
let world = resolve.select_world(&pkgs, None).unwrap_or_else(|_| {
148148
// note: if there are multiples worlds in the wit package, we assume the "imports" world
149-
resolve.select_world(pkg, Some("imports")).unwrap()
149+
resolve.select_world(&pkgs, Some("imports")).unwrap()
150150
});
151151
(resolve, world)
152152
}

src/bin/wit-bindgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ fn gen_world(
181181
resolve.features.insert(feature.to_string());
182182
}
183183
}
184-
let (pkg, _files) = resolve.push_path(&opts.wit)?;
185-
let world = resolve.select_world(pkg, opts.world.as_deref())?;
184+
let (pkgs, _files) = resolve.push_path(&opts.wit)?;
185+
let world = resolve.select_world(&pkgs, opts.world.as_deref())?;
186186
generator.generate(&resolve, world, files)?;
187187

188188
Ok(())

tests/runtime/flavorful.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,96 +12,88 @@ pub struct MyImports {
1212
}
1313

1414
impl test_imports::Host for MyImports {
15-
fn f_list_in_record1(&mut self, ty: test_imports::ListInRecord1) -> Result<()> {
15+
fn f_list_in_record1(&mut self, ty: test_imports::ListInRecord1) {
1616
assert_eq!(ty.a, "list_in_record1");
17-
Ok(())
1817
}
1918

20-
fn f_list_in_record2(&mut self) -> Result<test_imports::ListInRecord2> {
21-
Ok(test_imports::ListInRecord2 {
19+
fn f_list_in_record2(&mut self) -> test_imports::ListInRecord2 {
20+
test_imports::ListInRecord2 {
2221
a: "list_in_record2".to_string(),
23-
})
22+
}
2423
}
2524

26-
fn f_list_in_record3(
27-
&mut self,
28-
a: test_imports::ListInRecord3,
29-
) -> Result<test_imports::ListInRecord3> {
25+
fn f_list_in_record3(&mut self, a: test_imports::ListInRecord3) -> test_imports::ListInRecord3 {
3026
assert_eq!(a.a, "list_in_record3 input");
31-
Ok(test_imports::ListInRecord3 {
27+
test_imports::ListInRecord3 {
3228
a: "list_in_record3 output".to_string(),
33-
})
29+
}
3430
}
3531

36-
fn f_list_in_record4(
37-
&mut self,
38-
a: test_imports::ListInAlias,
39-
) -> Result<test_imports::ListInAlias> {
32+
fn f_list_in_record4(&mut self, a: test_imports::ListInAlias) -> test_imports::ListInAlias {
4033
assert_eq!(a.a, "input4");
41-
Ok(test_imports::ListInRecord4 {
34+
test_imports::ListInRecord4 {
4235
a: "result4".to_string(),
43-
})
36+
}
4437
}
4538

4639
fn f_list_in_variant1(
4740
&mut self,
4841
a: test_imports::ListInVariant1V1,
4942
b: test_imports::ListInVariant1V2,
50-
) -> Result<()> {
43+
) {
5144
assert_eq!(a.unwrap(), "foo");
5245
assert_eq!(b.unwrap_err(), "bar");
53-
Ok(())
5446
}
5547

56-
fn f_list_in_variant2(&mut self) -> Result<Option<String>> {
57-
Ok(Some("list_in_variant2".to_string()))
48+
fn f_list_in_variant2(&mut self) -> Option<String> {
49+
Some("list_in_variant2".to_string())
5850
}
5951

60-
fn f_list_in_variant3(&mut self, a: test_imports::ListInVariant3) -> Result<Option<String>> {
52+
fn f_list_in_variant3(&mut self, a: test_imports::ListInVariant3) -> Option<String> {
6153
assert_eq!(a.unwrap(), "input3");
62-
Ok(Some("output3".to_string()))
54+
Some("output3".to_string())
6355
}
6456

65-
fn errno_result(&mut self) -> Result<Result<(), test_imports::MyErrno>> {
57+
fn errno_result(&mut self) -> Result<(), test_imports::MyErrno> {
6658
if self.errored {
67-
return Ok(Ok(()));
59+
return Ok(());
6860
}
6961
test_imports::MyErrno::A.to_string();
7062
format!("{:?}", test_imports::MyErrno::A);
7163
fn assert_error<T: std::error::Error>() {}
7264
assert_error::<test_imports::MyErrno>();
7365
self.errored = true;
74-
Ok(Err(test_imports::MyErrno::B))
66+
Err(test_imports::MyErrno::B)
7567
}
7668

7769
fn list_typedefs(
7870
&mut self,
7971
a: test_imports::ListTypedef,
8072
b: test_imports::ListTypedef3,
81-
) -> Result<(test_imports::ListTypedef2, test_imports::ListTypedef3)> {
73+
) -> (test_imports::ListTypedef2, test_imports::ListTypedef3) {
8274
assert_eq!(a, "typedef1");
8375
assert_eq!(b.len(), 1);
8476
assert_eq!(b[0], "typedef2");
85-
Ok((b"typedef3".to_vec(), vec!["typedef4".to_string()]))
77+
(b"typedef3".to_vec(), vec!["typedef4".to_string()])
8678
}
8779

8880
fn list_of_variants(
8981
&mut self,
9082
bools: Vec<bool>,
9183
results: Vec<Result<(), ()>>,
9284
enums: Vec<test_imports::MyErrno>,
93-
) -> Result<(Vec<bool>, Vec<Result<(), ()>>, Vec<test_imports::MyErrno>)> {
85+
) -> (Vec<bool>, Vec<Result<(), ()>>, Vec<test_imports::MyErrno>) {
9486
assert_eq!(bools, [true, false]);
9587
assert_eq!(results, [Ok(()), Err(())]);
9688
assert_eq!(
9789
enums,
9890
[test_imports::MyErrno::Success, test_imports::MyErrno::A]
9991
);
100-
Ok((
92+
(
10193
vec![false, true],
10294
vec![Err(()), Ok(())],
10395
vec![test_imports::MyErrno::A, test_imports::MyErrno::B],
104-
))
96+
)
10597
}
10698
}
10799

tests/runtime/lists.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,98 +9,92 @@ wasmtime::component::bindgen!({
99
pub struct MyImports;
1010

1111
impl test::lists::test::Host for MyImports {
12-
fn empty_list_param(&mut self, a: Vec<u8>) -> Result<()> {
12+
fn empty_list_param(&mut self, a: Vec<u8>) {
1313
assert!(a.is_empty());
14-
Ok(())
1514
}
1615

17-
fn empty_string_param(&mut self, a: String) -> Result<()> {
16+
fn empty_string_param(&mut self, a: String) {
1817
assert_eq!(a, "");
19-
Ok(())
2018
}
2119

22-
fn empty_list_result(&mut self) -> Result<Vec<u8>> {
23-
Ok(Vec::new())
20+
fn empty_list_result(&mut self) -> Vec<u8> {
21+
Vec::new()
2422
}
2523

26-
fn empty_string_result(&mut self) -> Result<String> {
27-
Ok(String::new())
24+
fn empty_string_result(&mut self) -> String {
25+
String::new()
2826
}
2927

30-
fn list_param(&mut self, list: Vec<u8>) -> Result<()> {
28+
fn list_param(&mut self, list: Vec<u8>) {
3129
assert_eq!(list, [1, 2, 3, 4]);
32-
Ok(())
3330
}
3431

35-
fn list_param2(&mut self, ptr: String) -> Result<()> {
32+
fn list_param2(&mut self, ptr: String) {
3633
assert_eq!(ptr, "foo");
37-
Ok(())
3834
}
3935

40-
fn list_param3(&mut self, ptr: Vec<String>) -> Result<()> {
36+
fn list_param3(&mut self, ptr: Vec<String>) {
4137
assert_eq!(ptr.len(), 3);
4238
assert_eq!(ptr[0], "foo");
4339
assert_eq!(ptr[1], "bar");
4440
assert_eq!(ptr[2], "baz");
45-
Ok(())
4641
}
4742

48-
fn list_param4(&mut self, ptr: Vec<Vec<String>>) -> Result<()> {
43+
fn list_param4(&mut self, ptr: Vec<Vec<String>>) {
4944
assert_eq!(ptr.len(), 2);
5045
assert_eq!(ptr[0][0], "foo");
5146
assert_eq!(ptr[0][1], "bar");
5247
assert_eq!(ptr[1][0], "baz");
53-
Ok(())
5448
}
5549

56-
fn list_result(&mut self) -> Result<Vec<u8>> {
57-
Ok(vec![1, 2, 3, 4, 5])
50+
fn list_result(&mut self) -> Vec<u8> {
51+
vec![1, 2, 3, 4, 5]
5852
}
5953

60-
fn list_result2(&mut self) -> Result<String> {
61-
Ok("hello!".to_string())
54+
fn list_result2(&mut self) -> String {
55+
"hello!".to_string()
6256
}
6357

64-
fn list_result3(&mut self) -> Result<Vec<String>> {
65-
Ok(vec!["hello,".to_string(), "world!".to_string()])
58+
fn list_result3(&mut self) -> Vec<String> {
59+
vec!["hello,".to_string(), "world!".to_string()]
6660
}
6761

68-
fn list_roundtrip(&mut self, list: Vec<u8>) -> Result<Vec<u8>> {
69-
Ok(list.to_vec())
62+
fn list_roundtrip(&mut self, list: Vec<u8>) -> Vec<u8> {
63+
list.to_vec()
7064
}
7165

72-
fn string_roundtrip(&mut self, s: String) -> Result<String> {
73-
Ok(s.to_string())
66+
fn string_roundtrip(&mut self, s: String) -> String {
67+
s.to_string()
7468
}
7569

76-
fn list_minmax8(&mut self, u: Vec<u8>, s: Vec<i8>) -> Result<(Vec<u8>, Vec<i8>)> {
70+
fn list_minmax8(&mut self, u: Vec<u8>, s: Vec<i8>) -> (Vec<u8>, Vec<i8>) {
7771
assert_eq!(u, [u8::MIN, u8::MAX]);
7872
assert_eq!(s, [i8::MIN, i8::MAX]);
79-
Ok((u, s))
73+
(u, s)
8074
}
8175

82-
fn list_minmax16(&mut self, u: Vec<u16>, s: Vec<i16>) -> Result<(Vec<u16>, Vec<i16>)> {
76+
fn list_minmax16(&mut self, u: Vec<u16>, s: Vec<i16>) -> (Vec<u16>, Vec<i16>) {
8377
assert_eq!(u, [u16::MIN, u16::MAX]);
8478
assert_eq!(s, [i16::MIN, i16::MAX]);
85-
Ok((u, s))
79+
(u, s)
8680
}
8781

88-
fn list_minmax32(&mut self, u: Vec<u32>, s: Vec<i32>) -> Result<(Vec<u32>, Vec<i32>)> {
82+
fn list_minmax32(&mut self, u: Vec<u32>, s: Vec<i32>) -> (Vec<u32>, Vec<i32>) {
8983
assert_eq!(u, [u32::MIN, u32::MAX]);
9084
assert_eq!(s, [i32::MIN, i32::MAX]);
91-
Ok((u, s))
85+
(u, s)
9286
}
9387

94-
fn list_minmax64(&mut self, u: Vec<u64>, s: Vec<i64>) -> Result<(Vec<u64>, Vec<i64>)> {
88+
fn list_minmax64(&mut self, u: Vec<u64>, s: Vec<i64>) -> (Vec<u64>, Vec<i64>) {
9589
assert_eq!(u, [u64::MIN, u64::MAX]);
9690
assert_eq!(s, [i64::MIN, i64::MAX]);
97-
Ok((u, s))
91+
(u, s)
9892
}
9993

100-
fn list_minmax_float(&mut self, u: Vec<f32>, s: Vec<f64>) -> Result<(Vec<f32>, Vec<f64>)> {
94+
fn list_minmax_float(&mut self, u: Vec<f32>, s: Vec<f64>) -> (Vec<f32>, Vec<f64>) {
10195
assert_eq!(u, [f32::MIN, f32::MAX, f32::NEG_INFINITY, f32::INFINITY]);
10296
assert_eq!(s, [f64::MIN, f64::MAX, f64::NEG_INFINITY, f64::INFINITY]);
103-
Ok((u, s))
97+
(u, s)
10498
}
10599
}
106100

tests/runtime/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
777777
#[allow(dead_code)] // not used by all generators
778778
fn resolve_wit_dir(dir: &PathBuf) -> (Resolve, WorldId) {
779779
let mut resolve = Resolve::new();
780-
let (pkg, _files) = resolve.push_path(dir).unwrap();
781-
let world = resolve.select_world(pkg, None).unwrap();
780+
let (pkgs, _files) = resolve.push_path(dir).unwrap();
781+
let world = resolve.select_world(&pkgs, None).unwrap();
782782
(resolve, world)
783783
}

tests/runtime/many_arguments.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl imports::Host for MyImports {
2525
a14: u64,
2626
a15: u64,
2727
a16: u64,
28-
) -> Result<()> {
28+
) {
2929
assert_eq!(a1, 1);
3030
assert_eq!(a2, 2);
3131
assert_eq!(a3, 3);
@@ -42,7 +42,6 @@ impl imports::Host for MyImports {
4242
assert_eq!(a14, 14);
4343
assert_eq!(a15, 15);
4444
assert_eq!(a16, 16);
45-
Ok(())
4645
}
4746
}
4847

0 commit comments

Comments
 (0)