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
321 changes: 164 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ indexmap = "2.0.0"
prettyplease = "0.2.20"
syn = { version = "2.0", features = ["printing"] }

wasmparser = "0.209.0"
wasm-encoder = "0.209.0"
wasm-metadata = "0.209.0"
wit-parser = "0.209.0"
wit-component = "0.209.0"
wasmparser = "0.211.0"
wasm-encoder = "0.211.0"
wasm-metadata = "0.211.0"
wit-parser = "0.211.0"
wit-component = "0.211.0"

wit-bindgen-core = { path = 'crates/core', version = '0.26.0' }
wit-bindgen-c = { path = 'crates/c', version = '0.26.0' }
Expand Down Expand Up @@ -81,8 +81,8 @@ csharp-mono = ['csharp']

[dev-dependencies]
heck = { workspace = true }
wasmtime = { version = "20.0.0", features = ['component-model'] }
wasmtime-wasi = { version = "20.0.0" }
wasmtime = { version = "21.0.0", features = ['component-model'] }
wasmtime-wasi = { version = "21.0.0" }
test-artifacts = { path = 'crates/test-rust-wasm/artifacts' }
wit-parser = { workspace = true }
wasmparser = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/c/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use heck::*;
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
use wit_parser::{Resolve, UnresolvedPackage};
use wit_parser::{Resolve, UnresolvedPackageGroup};

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

let mut resolve = Resolve::default();
let pkg = resolve.push(UnresolvedPackage::parse(
"input.wit".as_ref(),
let pkgs = resolve.push_group(UnresolvedPackageGroup::parse(
"input.wit",
r#"
package foo:bar;

Expand All @@ -118,7 +118,7 @@ fn rename_option() -> Result<()> {
}
"#,
)?)?;
let world = resolve.select_world(pkg, None)?;
let world = resolve.select_world(&pkgs, None)?;
let mut files = Default::default();
opts.build().generate(&resolve, world, &mut files)?;
for (file, contents) in files.iter() {
Expand Down
10 changes: 5 additions & 5 deletions crates/guest-rust/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::{braced, token, Token};
use wit_bindgen_core::wit_parser::{PackageId, Resolve, UnresolvedPackage, WorldId};
use wit_bindgen_core::wit_parser::{PackageId, Resolve, UnresolvedPackageGroup, WorldId};
use wit_bindgen_rust::{Opts, Ownership, WithOption};

#[proc_macro]
Expand Down Expand Up @@ -131,10 +131,10 @@ impl Parse for Config {
source = Some(Source::Path(input.parse::<syn::LitStr>()?.value()));
}
}
let (resolve, pkg, files) =
let (resolve, pkgs, files) =
parse_source(&source, &features).map_err(|err| anyhow_to_syn(call_site, err))?;
let world = resolve
.select_world(pkg, world.as_deref())
.select_world(&pkgs, world.as_deref())
.map_err(|e| anyhow_to_syn(call_site, e))?;
Ok(Config {
opts,
Expand All @@ -149,7 +149,7 @@ impl Parse for Config {
fn parse_source(
source: &Option<Source>,
features: &[String],
) -> anyhow::Result<(Resolve, PackageId, Vec<PathBuf>)> {
) -> anyhow::Result<(Resolve, Vec<PackageId>, Vec<PathBuf>)> {
let mut resolve = Resolve::default();
resolve.features.extend(features.iter().cloned());
let mut files = Vec::new();
Expand All @@ -164,7 +164,7 @@ fn parse_source(
if let Some(p) = path {
parse(&root.join(p))?;
}
resolve.push(UnresolvedPackage::parse("macro-input".as_ref(), s)?)?
resolve.push_group(UnresolvedPackageGroup::parse("macro-input", s)?)?
}
Some(Source::Path(s)) => parse(&root.join(s))?,
None => parse(&root.join("wit"))?,
Expand Down
6 changes: 3 additions & 3 deletions crates/test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ pub fn run_component_codegen_test(

fn parse_wit(path: &Path) -> (Resolve, WorldId) {
let mut resolve = Resolve::default();
let (pkg, _files) = resolve.push_path(path).unwrap();
let world = resolve.select_world(pkg, None).unwrap_or_else(|_| {
let (pkgs, _files) = resolve.push_path(path).unwrap();
let world = resolve.select_world(&pkgs, None).unwrap_or_else(|_| {
// note: if there are multiples worlds in the wit package, we assume the "imports" world
resolve.select_world(pkg, Some("imports")).unwrap()
resolve.select_world(&pkgs, Some("imports")).unwrap()
});
(resolve, world)
}
4 changes: 2 additions & 2 deletions src/bin/wit-bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ fn gen_world(
resolve.features.insert(feature.to_string());
}
}
let (pkg, _files) = resolve.push_path(&opts.wit)?;
let world = resolve.select_world(pkg, opts.world.as_deref())?;
let (pkgs, _files) = resolve.push_path(&opts.wit)?;
let world = resolve.select_world(&pkgs, opts.world.as_deref())?;
generator.generate(&resolve, world, files)?;

Ok(())
Expand Down
54 changes: 23 additions & 31 deletions tests/runtime/flavorful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,96 +12,88 @@ pub struct MyImports {
}

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

fn f_list_in_record2(&mut self) -> Result<test_imports::ListInRecord2> {
Ok(test_imports::ListInRecord2 {
fn f_list_in_record2(&mut self) -> test_imports::ListInRecord2 {
test_imports::ListInRecord2 {
a: "list_in_record2".to_string(),
})
}
}

fn f_list_in_record3(
&mut self,
a: test_imports::ListInRecord3,
) -> Result<test_imports::ListInRecord3> {
fn f_list_in_record3(&mut self, a: test_imports::ListInRecord3) -> test_imports::ListInRecord3 {
assert_eq!(a.a, "list_in_record3 input");
Ok(test_imports::ListInRecord3 {
test_imports::ListInRecord3 {
a: "list_in_record3 output".to_string(),
})
}
}

fn f_list_in_record4(
&mut self,
a: test_imports::ListInAlias,
) -> Result<test_imports::ListInAlias> {
fn f_list_in_record4(&mut self, a: test_imports::ListInAlias) -> test_imports::ListInAlias {
assert_eq!(a.a, "input4");
Ok(test_imports::ListInRecord4 {
test_imports::ListInRecord4 {
a: "result4".to_string(),
})
}
}

fn f_list_in_variant1(
&mut self,
a: test_imports::ListInVariant1V1,
b: test_imports::ListInVariant1V2,
) -> Result<()> {
) {
assert_eq!(a.unwrap(), "foo");
assert_eq!(b.unwrap_err(), "bar");
Ok(())
}

fn f_list_in_variant2(&mut self) -> Result<Option<String>> {
Ok(Some("list_in_variant2".to_string()))
fn f_list_in_variant2(&mut self) -> Option<String> {
Some("list_in_variant2".to_string())
}

fn f_list_in_variant3(&mut self, a: test_imports::ListInVariant3) -> Result<Option<String>> {
fn f_list_in_variant3(&mut self, a: test_imports::ListInVariant3) -> Option<String> {
assert_eq!(a.unwrap(), "input3");
Ok(Some("output3".to_string()))
Some("output3".to_string())
}

fn errno_result(&mut self) -> Result<Result<(), test_imports::MyErrno>> {
fn errno_result(&mut self) -> Result<(), test_imports::MyErrno> {
if self.errored {
return Ok(Ok(()));
return Ok(());
}
test_imports::MyErrno::A.to_string();
format!("{:?}", test_imports::MyErrno::A);
fn assert_error<T: std::error::Error>() {}
assert_error::<test_imports::MyErrno>();
self.errored = true;
Ok(Err(test_imports::MyErrno::B))
Err(test_imports::MyErrno::B)
}

fn list_typedefs(
&mut self,
a: test_imports::ListTypedef,
b: test_imports::ListTypedef3,
) -> Result<(test_imports::ListTypedef2, test_imports::ListTypedef3)> {
) -> (test_imports::ListTypedef2, test_imports::ListTypedef3) {
assert_eq!(a, "typedef1");
assert_eq!(b.len(), 1);
assert_eq!(b[0], "typedef2");
Ok((b"typedef3".to_vec(), vec!["typedef4".to_string()]))
(b"typedef3".to_vec(), vec!["typedef4".to_string()])
}

fn list_of_variants(
&mut self,
bools: Vec<bool>,
results: Vec<Result<(), ()>>,
enums: Vec<test_imports::MyErrno>,
) -> Result<(Vec<bool>, Vec<Result<(), ()>>, Vec<test_imports::MyErrno>)> {
) -> (Vec<bool>, Vec<Result<(), ()>>, Vec<test_imports::MyErrno>) {
assert_eq!(bools, [true, false]);
assert_eq!(results, [Ok(()), Err(())]);
assert_eq!(
enums,
[test_imports::MyErrno::Success, test_imports::MyErrno::A]
);
Ok((
(
vec![false, true],
vec![Err(()), Ok(())],
vec![test_imports::MyErrno::A, test_imports::MyErrno::B],
))
)
}
}

Expand Down
66 changes: 30 additions & 36 deletions tests/runtime/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,98 +9,92 @@ wasmtime::component::bindgen!({
pub struct MyImports;

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

fn empty_string_param(&mut self, a: String) -> Result<()> {
fn empty_string_param(&mut self, a: String) {
assert_eq!(a, "");
Ok(())
}

fn empty_list_result(&mut self) -> Result<Vec<u8>> {
Ok(Vec::new())
fn empty_list_result(&mut self) -> Vec<u8> {
Vec::new()
}

fn empty_string_result(&mut self) -> Result<String> {
Ok(String::new())
fn empty_string_result(&mut self) -> String {
String::new()
}

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

fn list_param2(&mut self, ptr: String) -> Result<()> {
fn list_param2(&mut self, ptr: String) {
assert_eq!(ptr, "foo");
Ok(())
}

fn list_param3(&mut self, ptr: Vec<String>) -> Result<()> {
fn list_param3(&mut self, ptr: Vec<String>) {
assert_eq!(ptr.len(), 3);
assert_eq!(ptr[0], "foo");
assert_eq!(ptr[1], "bar");
assert_eq!(ptr[2], "baz");
Ok(())
}

fn list_param4(&mut self, ptr: Vec<Vec<String>>) -> Result<()> {
fn list_param4(&mut self, ptr: Vec<Vec<String>>) {
assert_eq!(ptr.len(), 2);
assert_eq!(ptr[0][0], "foo");
assert_eq!(ptr[0][1], "bar");
assert_eq!(ptr[1][0], "baz");
Ok(())
}

fn list_result(&mut self) -> Result<Vec<u8>> {
Ok(vec![1, 2, 3, 4, 5])
fn list_result(&mut self) -> Vec<u8> {
vec![1, 2, 3, 4, 5]
}

fn list_result2(&mut self) -> Result<String> {
Ok("hello!".to_string())
fn list_result2(&mut self) -> String {
"hello!".to_string()
}

fn list_result3(&mut self) -> Result<Vec<String>> {
Ok(vec!["hello,".to_string(), "world!".to_string()])
fn list_result3(&mut self) -> Vec<String> {
vec!["hello,".to_string(), "world!".to_string()]
}

fn list_roundtrip(&mut self, list: Vec<u8>) -> Result<Vec<u8>> {
Ok(list.to_vec())
fn list_roundtrip(&mut self, list: Vec<u8>) -> Vec<u8> {
list.to_vec()
}

fn string_roundtrip(&mut self, s: String) -> Result<String> {
Ok(s.to_string())
fn string_roundtrip(&mut self, s: String) -> String {
s.to_string()
}

fn list_minmax8(&mut self, u: Vec<u8>, s: Vec<i8>) -> Result<(Vec<u8>, Vec<i8>)> {
fn list_minmax8(&mut self, u: Vec<u8>, s: Vec<i8>) -> (Vec<u8>, Vec<i8>) {
assert_eq!(u, [u8::MIN, u8::MAX]);
assert_eq!(s, [i8::MIN, i8::MAX]);
Ok((u, s))
(u, s)
}

fn list_minmax16(&mut self, u: Vec<u16>, s: Vec<i16>) -> Result<(Vec<u16>, Vec<i16>)> {
fn list_minmax16(&mut self, u: Vec<u16>, s: Vec<i16>) -> (Vec<u16>, Vec<i16>) {
assert_eq!(u, [u16::MIN, u16::MAX]);
assert_eq!(s, [i16::MIN, i16::MAX]);
Ok((u, s))
(u, s)
}

fn list_minmax32(&mut self, u: Vec<u32>, s: Vec<i32>) -> Result<(Vec<u32>, Vec<i32>)> {
fn list_minmax32(&mut self, u: Vec<u32>, s: Vec<i32>) -> (Vec<u32>, Vec<i32>) {
assert_eq!(u, [u32::MIN, u32::MAX]);
assert_eq!(s, [i32::MIN, i32::MAX]);
Ok((u, s))
(u, s)
}

fn list_minmax64(&mut self, u: Vec<u64>, s: Vec<i64>) -> Result<(Vec<u64>, Vec<i64>)> {
fn list_minmax64(&mut self, u: Vec<u64>, s: Vec<i64>) -> (Vec<u64>, Vec<i64>) {
assert_eq!(u, [u64::MIN, u64::MAX]);
assert_eq!(s, [i64::MIN, i64::MAX]);
Ok((u, s))
(u, s)
}

fn list_minmax_float(&mut self, u: Vec<f32>, s: Vec<f64>) -> Result<(Vec<f32>, Vec<f64>)> {
fn list_minmax_float(&mut self, u: Vec<f32>, s: Vec<f64>) -> (Vec<f32>, Vec<f64>) {
assert_eq!(u, [f32::MIN, f32::MAX, f32::NEG_INFINITY, f32::INFINITY]);
assert_eq!(s, [f64::MIN, f64::MAX, f64::NEG_INFINITY, f64::INFINITY]);
Ok((u, s))
(u, s)
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/runtime/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ fn tests(name: &str, dir_name: &str) -> Result<Vec<PathBuf>> {
#[allow(dead_code)] // not used by all generators
fn resolve_wit_dir(dir: &PathBuf) -> (Resolve, WorldId) {
let mut resolve = Resolve::new();
let (pkg, _files) = resolve.push_path(dir).unwrap();
let world = resolve.select_world(pkg, None).unwrap();
let (pkgs, _files) = resolve.push_path(dir).unwrap();
let world = resolve.select_world(&pkgs, None).unwrap();
(resolve, world)
}
3 changes: 1 addition & 2 deletions tests/runtime/many_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl imports::Host for MyImports {
a14: u64,
a15: u64,
a16: u64,
) -> Result<()> {
) {
assert_eq!(a1, 1);
assert_eq!(a2, 2);
assert_eq!(a3, 3);
Expand All @@ -42,7 +42,6 @@ impl imports::Host for MyImports {
assert_eq!(a14, 14);
assert_eq!(a15, 15);
assert_eq!(a16, 16);
Ok(())
}
}

Expand Down
Loading