Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fc0bff6
fix(moonbit): update syntax and add tests (#1352)
peter-jerry-ye Aug 14, 2025
eaf42f6
Update dev container & testing documentation. (#1353)
badeend Aug 14, 2025
92cca96
fix(core): result check for async function (#1355)
vados-cosmonic Aug 18, 2025
859a7ea
Parse `wit` folder in `generate!` with `inline` (#1356)
alexcrichton Aug 19, 2025
ecb620e
Disable C# in CI testing for now (#1362)
alexcrichton Aug 22, 2025
0e2201b
Prioritize `inline` worlds, not external ones (#1358)
alexcrichton Aug 22, 2025
bd16b31
fix(msrv): add rust-version based on ground truth (#1364)
billf Aug 22, 2025
7bb0545
Add Rust support for fallible resource constructors. (#1360)
badeend Aug 23, 2025
90031e8
Redefine `with` in the Rust generator to only apply to imports (#1367)
alexcrichton Aug 26, 2025
05249c3
Support lists of WIT directories on the CLI. (#1368)
sunfishcode Aug 26, 2025
f61634f
Refactor the `wit-bindgen` crate for being suitable again to include …
alexcrichton Aug 26, 2025
a028b82
feat(moonbit): set default target (#1370)
peter-jerry-ye Aug 27, 2025
1ee3108
Release wit-bindgen 0.45.0 (#1371)
github-actions[bot] Aug 27, 2025
93c9ee3
Disable unused-import warnings on `__with_name*` aliases. (#1372)
sunfishcode Aug 27, 2025
ca55f12
fix(core): results for async task generation (#1374)
vados-cosmonic Sep 3, 2025
3db0056
Fill out missing `StreamRead::cancel` implementation (#1376)
alexcrichton Sep 5, 2025
5d37dfb
Release wit-bindgen 0.45.1 (#1378)
github-actions[bot] Sep 5, 2025
0950dd9
merge: `wit-bindgen 0.45`
rvolosatovs Jun 22, 2026
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
58 changes: 9 additions & 49 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ wasmtime-cli-flags = { version = "45", default-features = false }
wasmtime-wasi = { version = "45", default-features = false }
wasmtime-wasi-http = { version = "45", default-features = false }
wit-bindgen = { version = "0.45", default-features = false }
wit-bindgen-core = { version = "0.44", default-features = false }
wit-bindgen-core = { version = "0.45", default-features = false }
wit-bindgen-wrpc = { version = "0.11", default-features = false, path = "./crates/wit-bindgen" }
wit-bindgen-wrpc-go = { version = "0.13", default-features = false, path = "./crates/wit-bindgen-go" }
wit-bindgen-wrpc-rust = { version = "0.11", default-features = false, path = "./crates/wit-bindgen-rust" }
wit-bindgen-wrpc-rust-macro = { version = "0.11", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
wit-bindgen-wrpc-test = { version = "0.1", default-features = false, path = "./crates/wit-bindgen-test" }
wit-component = { version = "0.252", default-features = false }
wit-parser = { version = "0.236", default-features = false }
wit-parser = { version = "0.238", default-features = false }
wrpc-cli = { version = "0.8", path = "./crates/cli", default-features = false }
wrpc-introspect = { version = "0.7", default-features = false, path = "./crates/introspect" }
wrpc-pack = { version = "0.4", path = "./crates/pack", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/test-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ pub fn run_world_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 world = resolve.select_world(&[pkg], 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(&[pkg], Some("imports")).unwrap()
});
(resolve, world)
}
6 changes: 3 additions & 3 deletions crates/wit-bindgen-rust-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn select_world(
world: Option<&str>,
) -> anyhow::Result<WorldId> {
if pkgs.len() == 1 {
resolve.select_world(pkgs[0], world)
resolve.select_world(pkgs, world)
} else {
assert!(!pkgs.is_empty());
if let Some(name) = world {
Expand All @@ -190,11 +190,11 @@ fn select_world(

// This will ignore the package argument due to the fully
// qualified name being used.
resolve.select_world(pkgs[0], world)
resolve.select_world(pkgs, world)
} else {
let worlds = pkgs
.iter()
.filter_map(|p| resolve.select_world(*p, None).ok())
.filter_map(|p| resolve.select_world(&[*p], None).ok())
.collect::<Vec<_>>();
match &worlds[..] {
[] => anyhow::bail!("no packages have a world"),
Expand Down
30 changes: 18 additions & 12 deletions crates/wit-bindgen-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ pub struct Opts {
#[cfg_attr(feature = "clap", arg(long, value_name = "NAME"))]
pub additional_derive_ignore: Vec<String>,

/// Remapping of interface names to rust module names.
/// Remapping of wit import interface and type names to Rust module names
/// and types.
///
/// Argument must be of the form `k=v` and this option can be passed
/// multiple times or one option can be comma separated, for example
Expand Down Expand Up @@ -352,17 +353,28 @@ impl RustWrpc {
is_export: bool,
) -> Result<bool> {
let with_name = resolve.name_world_key(name);
let Some(remapping) = self.with.get(&with_name) else {
bail!("no remapping found for {with_name:?} - use the `generate!` macro's `with` option to force the interface to be generated or specify where it is already defined:
// `with` remappings only apply to imports; exports are always generated
// since their types are defined by the implementation.
let remapping = if is_export {
&TypeGeneration::Generate
} else {
let Some(remapping) = self.with.get(&with_name) else {
bail!("no remapping found for {with_name:?} - use the `generate!` macro's `with` option to force the interface to be generated or specify where it is already defined:
```
with: {{\n\t{with_name:?}: generate\n}}
```")
};
remapping
};
self.generated_types.insert(with_name);
let entry = match remapping {
TypeGeneration::Remap(remapped_path) => {
let name = format!("__with_name{}", self.with_name_counter);
self.with_name_counter += 1;
uwriteln!(
self.src,
"#[allow(unfulfilled_lint_expectations, unused_imports)]"
);
uwriteln!(self.src, "use {remapped_path} as {name};");
InterfaceName {
remapped: true,
Expand Down Expand Up @@ -511,7 +523,7 @@ impl WorldGenerator for RustWrpc {

let world = &resolve.worlds[world];
// Specify that all imports local to the world's package should be generated
for (key, item) in world.imports.iter().chain(world.exports.iter()) {
for (key, item) in world.imports.iter() {
if let WorldItem::Interface { id, .. } = item
&& resolve.interfaces[*id].package == world.package
{
Expand Down Expand Up @@ -615,14 +627,8 @@ impl WorldGenerator for RustWrpc {
let mut to_define = Vec::new();
for (name, ty_id) in resolve.interfaces[id].types.iter() {
let full_name = full_wit_type_name(resolve, *ty_id);
if let Some(type_gen) = self.with.get(&full_name) {
// skip type definition generation for remapped types
if type_gen.generated() {
to_define.push((name, ty_id));
}
} else {
to_define.push((name, ty_id));
}
// `with` remappings only apply to imports; exported types are always generated.
to_define.push((name, ty_id));
self.generated_types.insert(full_name);
}

Expand Down
33 changes: 33 additions & 0 deletions crates/wit-bindgen-rust/tests/codegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![allow(unused_macros)]
#![allow(dead_code, unused_variables)]

#[allow(unused)]
mod multiple_paths {
wit_bindgen_wrpc::generate!({
inline: r#"
package test:paths;

world test {
import paths:path1/test;
export paths:path2/test;
}
"#,
path: ["tests/wit/path1", "tests/wit/path2"],
generate_all,
});
}

#[allow(unused)]
mod inline_and_path {
wit_bindgen_wrpc::generate!({
inline: r#"
package test:paths;

world test {
import test:inline-and-path/bar;
}
"#,
path: ["tests/wit/path3"],
generate_all,
});
}
3 changes: 3 additions & 0 deletions crates/wit-bindgen-rust/tests/wit/path3/package.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package test:inline-and-path;

interface bar {}
12 changes: 8 additions & 4 deletions crates/wit-bindgen-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ impl Runner<'_> {
),
};
resolve
.select_world(pkg, Some(runner_world.as_str()))
.select_world(&[pkg], Some(runner_world.as_str()))
.with_context(|| {
format!("failed to find expected `{runner_world}` world to generate bindings")
})?;
resolve
.select_world(pkg, Some(test_world.as_str()))
.select_world(&[pkg], Some(test_world.as_str()))
.with_context(|| {
format!("failed to find expected `{test_world}` world to generate bindings")
})?;
Expand Down Expand Up @@ -521,8 +521,12 @@ impl Runner<'_> {
let mut resolve = wit_parser::Resolve::default();
let (pkg, _) = resolve.push_path(test).context("failed to load WIT")?;
let world = resolve
.select_world(pkg, None)
.or_else(|err| resolve.select_world(pkg, Some("imports")).map_err(|_| err))
.select_world(&[pkg], None)
.or_else(|err| {
resolve
.select_world(&[pkg], Some("imports"))
.map_err(|_| err)
})
.context("failed to select a world for bindings generation")?;
let world = resolve.worlds[world].name.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/bin/wit-bindgen-wrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn gen_world(
}
}
let (pkg, _files) = resolve.push_path(&opts.wit)?;
let world = resolve.select_world(pkg, opts.world.as_deref())?;
let world = resolve.select_world(&[pkg], opts.world.as_deref())?;
generator.generate(&resolve, world, files)?;

Ok(())
Expand Down
12 changes: 12 additions & 0 deletions tests/codegen/resource-fallible-constructor.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package my:resources;

interface fallible-constructor {
resource x {
constructor(s: string) -> result<x, string>;
}
}

world resources {
import fallible-constructor;
export fallible-constructor;
}
Loading