From 14ff1c8584e88abb4a9289a1d6921f79876c099b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 15 Nov 2024 14:34:38 -0800 Subject: [PATCH 01/10] Fix printing of the preamble in generated Rust code. (#1087) In the generated Rust bindings, Generate the preamble comments in a separate string, because `prettyplease` does not preserve comments. Also, add several more options to the preamble printing code. Fixes #1086. --- crates/rust/src/lib.rs | 76 +++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 6edb6be2..e6899487 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -27,6 +27,7 @@ struct InterfaceName { #[derive(Default)] struct RustWasm { types: Types, + src_preamble: Source, src: Source, opts: Opts, import_modules: Vec<(String, Vec)>, @@ -837,44 +838,90 @@ macro_rules! __export_{world_name}_impl {{ impl WorldGenerator for RustWasm { fn preprocess(&mut self, resolve: &Resolve, world: WorldId) { - wit_bindgen_core::generated_preamble(&mut self.src, env!("CARGO_PKG_VERSION")); + wit_bindgen_core::generated_preamble(&mut self.src_preamble, env!("CARGO_PKG_VERSION")); // Render some generator options to assist with debugging and/or to help // recreate it if the original generation command is lost. - uwriteln!(self.src, "// Options used:"); + uwriteln!(self.src_preamble, "// Options used:"); if self.opts.std_feature { - uwriteln!(self.src, "// * std_feature"); + uwriteln!(self.src_preamble, "// * std_feature"); } if self.opts.raw_strings { - uwriteln!(self.src, "// * raw_strings"); + uwriteln!(self.src_preamble, "// * raw_strings"); } if !self.opts.skip.is_empty() { - uwriteln!(self.src, "// * skip: {:?}", self.opts.skip); + uwriteln!(self.src_preamble, "// * skip: {:?}", self.opts.skip); + } + if self.opts.stubs { + uwriteln!(self.src_preamble, "// * stubs"); + } + if let Some(export_prefix) = &self.opts.export_prefix { + uwriteln!( + self.src_preamble, + "// * export_prefix: {:?}", + export_prefix + ); + } + if let Some(runtime_path) = &self.opts.runtime_path { + uwriteln!(self.src_preamble, "// * runtime_path: {:?}", runtime_path); + } + if let Some(bitflags_path) = &self.opts.bitflags_path { + uwriteln!( + self.src_preamble, + "// * bitflags_path: {:?}", + bitflags_path + ); } if !matches!(self.opts.ownership, Ownership::Owning) { - uwriteln!(self.src, "// * ownership: {:?}", self.opts.ownership); + uwriteln!( + self.src_preamble, + "// * ownership: {:?}", + self.opts.ownership + ); } if !self.opts.additional_derive_attributes.is_empty() { uwriteln!( - self.src, + self.src_preamble, "// * additional derives {:?}", self.opts.additional_derive_attributes ); } for (k, v) in self.opts.with.iter() { - uwriteln!(self.src, "// * with {k:?} = {v}"); + uwriteln!(self.src_preamble, "// * with {k:?} = {v}"); + } + if let Some(type_section_suffix) = &self.opts.type_section_suffix { + uwriteln!( + self.src_preamble, + "// * type_section_suffix: {:?}", + type_section_suffix + ); } if let Some(default) = &self.opts.default_bindings_module { - uwriteln!(self.src, "// * default-bindings-module: {default:?}"); + uwriteln!( + self.src_preamble, + "// * default-bindings-module: {default:?}" + ); } if self.opts.disable_run_ctors_once_workaround { - uwriteln!(self.src, "// * disable-run-ctors-once-workaround"); + uwriteln!( + self.src_preamble, + "// * disable-run-ctors-once-workaround" + ); } if let Some(s) = &self.opts.export_macro_name { - uwriteln!(self.src, "// * export-macro-name: {s}"); + uwriteln!(self.src_preamble, "// * export-macro-name: {s}"); } if self.opts.pub_export_macro { - uwriteln!(self.src, "// * pub-export-macro"); + uwriteln!(self.src_preamble, "// * pub-export-macro"); + } + if self.opts.generate_unused_types { + uwriteln!(self.src_preamble, "// * generate_unused_types"); + } + if self.opts.disable_custom_section_link_helpers { + uwriteln!( + self.src_preamble, + "// * disable_custom_section_link_helpers" + ); } self.types.analyze(resolve); self.world = Some(world); @@ -1101,6 +1148,11 @@ impl WorldGenerator for RustWasm { *src.as_mut_string() = prettyplease::unparse(&syntax_tree); } + // Prepend the preamble. We do this after formatting because + // `syn::parse_file` + `prettyplease::unparse` does not preserve comments. + let src_preamble = mem::take(&mut self.src_preamble); + *src.as_mut_string() = format!("{}{}", src_preamble.as_str(), src.as_str()); + let module_name = name.to_snake_case(); files.push(&format!("{module_name}.rs"), src.as_bytes()); From dd15b0eca1ff893b7a7e5de839b5e9c5b8212993 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 15 Nov 2024 20:27:37 -0800 Subject: [PATCH 02/10] Add `#[rustfmt::skip]` to disable rustfmt on generated code. (#1088) Add `#[rustfmt::skip]` to generated Rust code when we're using prettyplease, so that users don't see spurious diffs when running `cargo fmt` over their projects. --- crates/rust/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index e6899487..8c546c1f 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -292,6 +292,14 @@ impl RustWasm { } cur.contents.push(module); } + + // Disable rustfmt. By default we already format the code + // using prettyplease, so we don't want `cargo fmt` to create + // extra diffs for users to deal with. + if self.opts.format { + uwriteln!(self.src, "#[rustfmt::skip]"); + } + emit(&mut self.src, map); fn emit(me: &mut Source, module: Module) { for (name, submodule) in module.submodules { @@ -366,6 +374,12 @@ impl RustWasm { if self.rt_module.is_empty() { return; } + + // As above, disable rustfmt, as we use prettyplease. + if self.opts.format { + uwriteln!(self.src, "#[rustfmt::skip]"); + } + self.src.push_str("mod _rt {\n"); let mut emitted = IndexSet::new(); while !self.rt_module.is_empty() { From 064062532e3a8ebf9224ee14e52f0044ec508f6d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 18 Nov 2024 10:34:03 -0800 Subject: [PATCH 03/10] Avoid emitting redundant `#[allow(dead_code)]` directives. (#1089) Only emit `#[allow(dead_code)]` on top-level modules, and emit `#[rustfmt::skip]` on all top-level modules. --- crates/rust/src/interface.rs | 1 - crates/rust/src/lib.rs | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index 8a746896..ba42bbff 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -439,7 +439,6 @@ macro_rules! {macro_name} {{ }; let module = format!( "\ - #[allow(dead_code, clippy::all)] pub mod {snake} {{ {used_static} {module} diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 8c546c1f..2d7f71e5 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -293,23 +293,25 @@ impl RustWasm { cur.contents.push(module); } - // Disable rustfmt. By default we already format the code - // using prettyplease, so we don't want `cargo fmt` to create - // extra diffs for users to deal with. - if self.opts.format { - uwriteln!(self.src, "#[rustfmt::skip]"); - } - - emit(&mut self.src, map); - fn emit(me: &mut Source, module: Module) { + emit(&mut self.src, map, &self.opts, true); + fn emit(me: &mut Source, module: Module, opts: &Opts, toplevel: bool) { for (name, submodule) in module.submodules { - // Ignore dead-code warnings. If the bindings are only used - // within a crate, and not exported to a different crate, some - // parts may be unused, and that's ok. - uwriteln!(me, "#[allow(dead_code)]"); + if toplevel { + // Disable rustfmt. By default we already format the code + // using prettyplease, so we don't want `cargo fmt` to create + // extra diffs for users to deal with. + if opts.format { + uwriteln!(me, "#[rustfmt::skip]"); + } + + // Ignore dead-code and clippy warnings. If the bindings are + // only used within a crate, and not exported to a different + // crate, some parts may be unused, and that's ok. + uwriteln!(me, "#[allow(dead_code, clippy::all)]"); + } uwriteln!(me, "pub mod {name} {{"); - emit(me, submodule); + emit(me, submodule, opts, false); uwriteln!(me, "}}"); } for submodule in module.contents { From 6d0120fa32d90e53ffdf059ac083b657d40d4b01 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 18 Nov 2024 12:11:14 -0800 Subject: [PATCH 04/10] Rust: Add interface doc comments. (#1090) Add interface documentation as doc comments for the generated Rust modules. --- crates/rust/src/interface.rs | 8 +++++++- crates/rust/src/lib.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index ba42bbff..2002016f 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -422,8 +422,13 @@ macro_rules! {macro_name} {{ (snake, module_path) } - pub fn finish_append_submodule(mut self, snake: &str, module_path: Vec) { + pub fn finish_append_submodule(mut self, snake: &str, module_path: Vec, docs: &Docs) { let module = self.finish(); + + self.rustdoc(docs); + let docs = mem::take(&mut self.src).to_string(); + let docs = docs.trim_end(); + let path_to_root = self.path_to_root(); let used_static = if self.gen.opts.disable_custom_section_link_helpers { String::new() @@ -439,6 +444,7 @@ macro_rules! {macro_name} {{ }; let module = format!( "\ + {docs} pub mod {snake} {{ {used_static} {module} diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 2d7f71e5..50ba0b3d 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -984,7 +984,9 @@ impl WorldGenerator for RustWasm { gen.generate_imports(resolve.interfaces[id].functions.values()); - gen.finish_append_submodule(&snake, module_path); + let docs = &resolve.interfaces[id].docs; + + gen.finish_append_submodule(&snake, module_path, docs); Ok(()) } @@ -1022,7 +1024,10 @@ impl WorldGenerator for RustWasm { gen.types(id); let macro_name = gen.generate_exports(Some((id, name)), resolve.interfaces[id].functions.values())?; - gen.finish_append_submodule(&snake, module_path); + + let docs = &resolve.interfaces[id].docs; + + gen.finish_append_submodule(&snake, module_path, docs); self.export_macros .push((macro_name, self.interface_names[&id].path.clone())); From 1739caf3771f9497d5cfaf13df33850e0a025322 Mon Sep 17 00:00:00 2001 From: yowl Date: Tue, 19 Nov 2024 10:40:18 -0500 Subject: [PATCH 05/10] [C#] minor improvement to reduce unused using statements (#1070) * minor improvement to reduce unused using statements * tidy usings, update to net10 * cargo fmt --- crates/csharp/src/csproj.rs | 4 +- crates/csharp/src/lib.rs | 138 +++++++++++++++++++++++++++++------- 2 files changed, 116 insertions(+), 26 deletions(-) diff --git a/crates/csharp/src/csproj.rs b/crates/csharp/src/csproj.rs index 626e89df..fe5aa24b 100644 --- a/crates/csharp/src/csproj.rs +++ b/crates/csharp/src/csproj.rs @@ -92,8 +92,8 @@ impl CSProjectLLVMBuilder { csproj.push_str( r#" - - + + "#, ); diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs index 6f11ef47..ff4c767c 100644 --- a/crates/csharp/src/lib.rs +++ b/crates/csharp/src/lib.rs @@ -25,18 +25,6 @@ use wit_component::{StringEncoding, WitPrinter}; mod csproj; pub use csproj::CSProject; -//TODO remove unused -const CSHARP_IMPORTS: &str = "\ -using System; -using System.Runtime.CompilerServices; -using System.Collections; -using System.Runtime.InteropServices; -using System.Text; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -"; - #[derive(Default, Debug, Clone)] #[cfg_attr(feature = "clap", derive(clap::Args))] pub struct Opts { @@ -106,6 +94,8 @@ struct InterfaceFragment { csharp_src: String, csharp_interop_src: String, stub: String, + usings: HashSet, + interop_usings: HashSet, } pub struct InterfaceTypeAndFragments { @@ -133,6 +123,8 @@ pub enum FunctionLevel { pub struct CSharp { opts: Opts, name: String, + usings: HashSet, + interop_usings: HashSet, return_area_size: usize, return_area_align: usize, tuple_counts: HashSet, @@ -180,6 +172,8 @@ impl CSharp { resolve, name, direction, + usings: HashSet::::new(), + interop_usings: HashSet::::new(), } } @@ -196,6 +190,20 @@ impl CSharp { (String::new(), String::new()) } } + + fn require_using(&mut self, using_ns: &str) { + if !self.usings.contains(using_ns) { + let using_ns_string = using_ns.to_string(); + self.usings.insert(using_ns_string); + } + } + + fn require_interop_using(&mut self, using_ns: &str) { + if !self.interop_usings.contains(using_ns) { + let using_ns_string = using_ns.to_string(); + self.interop_usings.insert(using_ns_string); + } + } } impl WorldGenerator for CSharp { @@ -405,10 +413,11 @@ impl WorldGenerator for CSharp { let access = self.access_modifier(); + let using_pos = src.len(); + uwrite!( src, - "{CSHARP_IMPORTS} - + " namespace {world_namespace} {{ {access} interface I{name}World {{ @@ -424,6 +433,16 @@ impl WorldGenerator for CSharp { .join("\n"), ); + let usings: Vec<_> = self + .world_fragments + .iter() + .flat_map(|f| &f.usings) + .cloned() + .collect(); + usings.iter().for_each(|u| { + self.require_using(u); + }); + let mut producers = wasm_metadata::Producers::empty(); producers.add( "processed-by", @@ -434,6 +453,7 @@ impl WorldGenerator for CSharp { src.push_str("}\n"); if self.needs_result { + self.require_using("System.Runtime.InteropServices"); uwrite!( src, r#" @@ -495,6 +515,7 @@ impl WorldGenerator for CSharp { } if self.needs_option { + self.require_using("System.Diagnostics.CodeAnalysis"); uwrite!( src, r#" @@ -525,6 +546,8 @@ impl WorldGenerator for CSharp { } if self.needs_interop_string { + self.require_using("System.Text"); + self.require_using("System.Runtime.InteropServices"); uwrite!( src, r#" @@ -568,6 +591,8 @@ impl WorldGenerator for CSharp { let (array_size, element_type) = dotnet_aligned_array(self.return_area_size, self.return_area_align); + + self.require_using("System.Runtime.CompilerServices"); uwrite!( ret_area_str, " @@ -607,6 +632,17 @@ impl WorldGenerator for CSharp { src.push_str("\n"); src.push_str("namespace exports {\n"); + + src.push_str( + &self + .world_fragments + .iter() + .flat_map(|f| &f.interop_usings) + .map(|s| "using ".to_owned() + s + ";") + .collect::>() + .join("\n"), + ); + src.push_str(&format!("{access} static class {name}World\n")); src.push_str("{"); @@ -623,6 +659,16 @@ impl WorldGenerator for CSharp { src.push_str("}\n"); + src.insert_str( + using_pos, + &self + .usings + .iter() + .map(|s| "using ".to_owned() + s + ";") + .collect::>() + .join("\n"), + ); + files.push(&format!("{name}.cs"), indent(&src).as_bytes()); let generate_stub = |name: String, files: &mut Files, stubs: Stubs| { @@ -668,8 +714,6 @@ impl WorldGenerator for CSharp { let body = format!( "{header} - {CSHARP_IMPORTS} - namespace {fully_qualified_namespace}; {access} partial class {stub_class_name} : {interface_or_class_name} {{ @@ -789,14 +833,20 @@ impl WorldGenerator for CSharp { if body.len() > 0 { let body = format!( "{header} - {CSHARP_IMPORTS} + {0} namespace {namespace}; {access} interface {interface_name} {{ {body} }} - " + ", + fragments + .iter() + .flat_map(|f| &f.usings) + .map(|s| "using ".to_owned() + s + ";") + .collect::>() + .join("\n"), ); files.push(&format!("{full_name}.cs"), indent(&body).as_bytes()); @@ -812,7 +862,7 @@ impl WorldGenerator for CSharp { let class_name = interface_name.strip_prefix("I").unwrap(); let body = format!( "{header} - {CSHARP_IMPORTS} + {0} namespace {namespace} {{ @@ -820,7 +870,13 @@ impl WorldGenerator for CSharp { {body} }} }} - " + ", + fragments + .iter() + .flat_map(|f| &f.interop_usings) + .map(|s| "using ".to_owned() + s + ";\n") + .collect::>() + .join(""), ); files.push( @@ -845,6 +901,8 @@ struct InterfaceGenerator<'a> { resolve: &'a Resolve, name: &'a str, direction: Direction, + usings: HashSet, + interop_usings: HashSet, } impl InterfaceGenerator<'_> { @@ -956,6 +1014,8 @@ impl InterfaceGenerator<'_> { csharp_src: self.src, csharp_interop_src: self.csharp_interop_src, stub: self.stub, + usings: self.usings, + interop_usings: self.interop_usings, }); } @@ -964,6 +1024,8 @@ impl InterfaceGenerator<'_> { csharp_src: self.src, csharp_interop_src: self.csharp_interop_src, stub: self.stub, + usings: self.usings, + interop_usings: self.interop_usings, }); } @@ -1083,8 +1145,10 @@ impl InterfaceGenerator<'_> { let import_name = &func.name; let target = if let FunctionKind::Freestanding = &func.kind { + self.require_interop_using("System.Runtime.InteropServices"); &mut self.csharp_interop_src } else { + self.require_using("System.Runtime.InteropServices"); &mut self.src }; @@ -1229,6 +1293,7 @@ impl InterfaceGenerator<'_> { let export_name = func.legacy_core_export_name(core_module_name.as_deref()); let access = self.gen.access_modifier(); + self.require_interop_using("System.Runtime.InteropServices"); uwrite!( self.csharp_interop_src, r#" @@ -1429,6 +1494,20 @@ impl InterfaceGenerator<'_> { } } + fn require_using(&mut self, using_ns: &str) { + if !self.usings.contains(using_ns) { + let using_ns_string = using_ns.to_string(); + self.usings.insert(using_ns_string); + } + } + + fn require_interop_using(&mut self, using_ns: &str) { + if !self.interop_usings.contains(using_ns) { + let using_ns_string = using_ns.to_string(); + self.interop_usings.insert(using_ns_string); + } + } + fn start_resource(&mut self, id: TypeId, key: Option<&WorldKey>) { let access = self.gen.access_modifier(); let qualified = self.type_name_with_qualifier(&Type::Id(id), true); @@ -1444,6 +1523,7 @@ impl InterfaceGenerator<'_> { .map(|key| self.resolve.name_world_key(key)) .unwrap_or_else(|| "$root".into()); + self.require_using("System.Runtime.InteropServices"); // As of this writing, we cannot safely drop a handle to an imported resource from a .NET finalizer // because it may still have one or more open child resources. Once WIT has explicit syntax for // indicating parent/child relationships, we should be able to use that information to keep track @@ -1482,6 +1562,7 @@ impl InterfaceGenerator<'_> { .map(|s| format!("{}#", self.resolve.name_world_key(s))) .unwrap_or_else(String::new); + self.require_interop_using("System.Runtime.InteropServices"); uwrite!( self.csharp_interop_src, r#" @@ -1500,6 +1581,7 @@ impl InterfaceGenerator<'_> { .map(|key| format!("[export]{}", self.resolve.name_world_key(key))) .unwrap_or_else(|| "[export]$root".into()); + self.require_using("System.Runtime.InteropServices"); // The ergonomics of exported resources are not ideal, currently. Implementing such a resource // requires both extending a class and implementing an interface. The reason for the class is to // allow implementers to inherit code which tracks and disposes of the resource handle; the reason @@ -2584,10 +2666,18 @@ impl Bindgen for FunctionBindgen<'_, '_> { self.gen.gen.needs_interop_string = true; } - Instruction::StringLift { .. } => results.push(format!( - "Encoding.UTF8.GetString((byte*){}, {})", - operands[0], operands[1] - )), + Instruction::StringLift { .. } => { + if FunctionKind::Freestanding == *self.kind || self.gen.direction == Direction::Export { + self.gen.require_interop_using("System.Text"); + } else { + self.gen.require_using("System.Text"); + } + + results.push(format!( + "Encoding.UTF8.GetString((byte*){}, {})", + operands[0], operands[1] + )); + } Instruction::ListLower { element, realloc } => { let Block { From 563956d071cadab5fe4d0f26e2db5113cbd3f259 Mon Sep 17 00:00:00 2001 From: yowl Date: Tue, 19 Nov 2024 20:19:28 -0500 Subject: [PATCH 06/10] [C#] Idiomatic formatting (#1083) * minor improvement to reduce unused using statements * use more idiomatic c# casing and bracket style * index on tidy-usings: f38910be use more idiomatic c# casing and bracket style * cargo fmr * remove TODO comment --------- Co-authored-by: Timmy Silesmo --- crates/csharp/src/lib.rs | 188 ++++++++++++++++------ tests/runtime/resource_aggregates/wasm.cs | 12 +- tests/runtime/results/wasm.cs | 12 +- tests/runtime/variants/wasm.cs | 22 +-- 4 files changed, 164 insertions(+), 70 deletions(-) diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs index ff4c767c..744239a9 100644 --- a/crates/csharp/src/lib.rs +++ b/crates/csharp/src/lib.rs @@ -461,7 +461,7 @@ impl WorldGenerator for CSharp { {access} readonly struct None {{}} [StructLayout(LayoutKind.Sequential)] - {access} readonly struct Result + {access} readonly struct Result {{ {access} readonly byte Tag; private readonly object value; @@ -472,43 +472,50 @@ impl WorldGenerator for CSharp { this.value = value; }} - {access} static Result ok(Ok ok) + {access} static Result Ok(TOk ok) {{ - return new Result(OK, ok!); + return new Result(Tags.Ok, ok!); }} - {access} static Result err(Err err) + {access} static Result Err(TErr err) {{ - return new Result(ERR, err!); + return new Result(Tags.Err, err!); }} - {access} bool IsOk => Tag == OK; - {access} bool IsErr => Tag == ERR; + {access} bool IsOk => Tag == Tags.Ok; + {access} bool IsErr => Tag == Tags.Err; - {access} Ok AsOk + {access} TOk AsOk {{ get {{ - if (Tag == OK) - return (Ok)value; - else - throw new ArgumentException("expected OK, got " + Tag); + if (Tag == Tags.Ok) + {{ + return (TOk)value; + }} + + throw new ArgumentException("expected k, got " + Tag); }} }} - {access} Err AsErr + {access} TErr AsErr {{ get {{ - if (Tag == ERR) - return (Err)value; - else - throw new ArgumentException("expected ERR, got " + Tag); + if (Tag == Tags.Err) + {{ + return (TErr)value; + }} + + throw new ArgumentException("expected Err, got " + Tag); }} }} - {access} const byte OK = 0; - {access} const byte ERR = 1; + {access} class Tags + {{ + {access} const byte Ok = 0; + {access} const byte Err = 1; + }} }} "#, ) @@ -1144,6 +1151,8 @@ impl InterfaceGenerator<'_> { let import_name = &func.name; + self.gen.require_using("System.Runtime.InteropServices"); + let target = if let FunctionKind::Freestanding = &func.kind { self.require_interop_using("System.Runtime.InteropServices"); &mut self.csharp_interop_src @@ -1865,7 +1874,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { .iter() .map(|case| { let case_name = case.name.to_csharp_ident(); - let tag = case.name.to_shouty_snake_case(); + let tag = case.name.to_csharp_ident_upper(); let (parameter, argument) = if let Some(ty) = self.non_empty_type(case.ty.as_ref()) { ( @@ -1877,8 +1886,8 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { }; format!( - "{access} static {name} {case_name}({parameter}) {{ - return new {name}({tag}, {argument}); + "{access} static {name} {tag}({parameter}) {{ + return new {name}(Tags.{tag}, {argument}); }} " ) @@ -1892,14 +1901,14 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { .filter_map(|case| { self.non_empty_type(case.ty.as_ref()).map(|ty| { let case_name = case.name.to_upper_camel_case(); - let tag = case.name.to_shouty_snake_case(); + let tag = case.name.to_csharp_ident_upper(); let ty = self.type_name(ty); format!( r#"{access} {ty} As{case_name} {{ get {{ - if (Tag == {tag}) + if (Tag == Tags.{tag}) return ({ty})value!; else throw new ArgumentException("expected {tag}, got " + Tag); @@ -1917,7 +1926,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { .iter() .enumerate() .map(|(i, case)| { - let tag = case.name.to_shouty_snake_case(); + let tag = case.name.to_csharp_ident_upper(); format!("{access} const {tag_type} {tag} = {i};") }) .collect::>() @@ -1937,7 +1946,10 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { {constructors} {accessors} - {tags} + + {access} class Tags {{ + {tags} + }} }} " ); @@ -2195,7 +2207,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> { String::new() }; - let method = case_name.to_csharp_ident(); + let method = case_name.to_csharp_ident_upper(); let call = if let Some(position) = generics_position { let (ty, generics) = ty.split_at(position); @@ -2557,7 +2569,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { result, .. } => self.lower_variant( - &[("ok", result.ok), ("err", result.err)], + &[("Ok", result.ok), ("Err", result.err)], lowered_types, &operands[0], results, @@ -2565,7 +2577,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { Instruction::ResultLift { result, ty } => self.lift_variant( &Type::Id(*ty), - &[("ok", result.ok), ("err", result.err)], + &[("Ok", result.ok), ("Err", result.err)], &operands[0], results, ), @@ -2844,13 +2856,13 @@ impl Bindgen for FunctionBindgen<'_, '_> { format!( "\ case {index}: {{ - ret = {head}{ty}.err(({err_ty}) e.Value){tail}; + ret = {head}{ty}.Err(({err_ty}) e.Value){tail}; break; }} " ) ); - oks.push(format!("{ty}.ok(")); + oks.push(format!("{ty}.Ok(")); payload_is_void = result.ok.is_none(); } if !self.results.is_empty() { @@ -3382,28 +3394,110 @@ fn is_primitive(ty: &Type) -> bool { } trait ToCSharpIdent: ToOwned { + fn csharp_keywords() -> Vec<&'static str>; fn to_csharp_ident(&self) -> Self::Owned; + fn to_csharp_ident_upper(&self) -> Self::Owned; } impl ToCSharpIdent for str { + // Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ + fn csharp_keywords() -> Vec<&'static str> { + vec![ + "abstract", + "as", + "base", + "bool", + "break", + "byte", + "case", + "catch", + "char", + "checked", + "class", + "const", + "continue", + "decimal", + "default", + "delegate", + "do", + "double", + "else", + "enum", + "event", + "explicit", + "extern", + "false", + "finally", + "fixed", + "float", + "for", + "foreach", + "goto", + "if", + "implicit", + "in", + "int", + "interface", + "internal", + "is", + "lock", + "long", + "namespace", + "new", + "null", + "object", + "operator", + "out", + "override", + "params", + "private", + "protected", + "public", + "readonly", + "ref", + "return", + "sbyte", + "sealed", + "short", + "sizeof", + "stackalloc", + "static", + "string", + "struct", + "switch", + "this", + "throw", + "true", + "try", + "typeof", + "uint", + "ulong", + "unchecked", + "unsafe", + "ushort", + "using", + "virtual", + "void", + "volatile", + "while", + ] + } + fn to_csharp_ident(&self) -> String { // Escape C# keywords - // Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ - - //TODO: Repace with actual keywords - match self { - "abstract" | "as" | "base" | "bool" | "break" | "byte" | "case" | "catch" | "char" - | "checked" | "class" | "const" | "continue" | "decimal" | "default" | "delegate" - | "do" | "double" | "else" | "enum" | "event" | "explicit" | "extern" | "false" - | "finally" | "fixed" | "float" | "for" | "foreach" | "goto" | "if" | "implicit" - | "in" | "int" | "interface" | "internal" | "is" | "lock" | "long" | "namespace" - | "new" | "null" | "object" | "operator" | "out" | "override" | "params" - | "private" | "protected" | "public" | "readonly" | "ref" | "return" | "sbyte" - | "sealed" | "short" | "sizeof" | "stackalloc" | "static" | "string" | "struct" - | "switch" | "this" | "throw" | "true" | "try" | "typeof" | "uint" | "ulong" - | "unchecked" | "unsafe" | "ushort" | "using" | "virtual" | "void" | "volatile" - | "while" => format!("@{self}"), - _ => self.to_lower_camel_case(), + if Self::csharp_keywords().contains(&self) { + format!("@{}", self) + } else { + self.to_lower_camel_case() + } + } + + fn to_csharp_ident_upper(&self) -> String { + // Escape C# keywords + if Self::csharp_keywords().contains(&self) { + format!("@{}", self) + } else { + self.to_upper_camel_case() } } } diff --git a/tests/runtime/resource_aggregates/wasm.cs b/tests/runtime/resource_aggregates/wasm.cs index 964b799a..28414f62 100644 --- a/tests/runtime/resource_aggregates/wasm.cs +++ b/tests/runtime/resource_aggregates/wasm.cs @@ -33,8 +33,8 @@ public static uint Foo( var ir3 = new Import.R3(((Thing) r3.thing1).val, ((Thing) r3.thing2).val); var it1 = (((Thing) t1.Item1).val, new Import.R1(((Thing) t1.Item2.thing).val)); var it2 = ((Thing) t2).val; - var iv1 = Import.V1.thing(((Thing) v1.AsThing).val); - var iv2 = Import.V2.thing(((Thing) v2.AsThing).val); + var iv1 = Import.V1.Thing(((Thing) v1.AsThing).val); + var iv2 = Import.V2.Thing(((Thing) v2.AsThing).val); var il1 = new List(); foreach (var thing in l1) { @@ -52,11 +52,11 @@ public static uint Foo( ? ((Thing) o2).val : null; var iresult1 = result1.IsOk - ? Result.ok(((Thing) result1.AsOk).val) - : Result.err(new None()); + ? Result.Ok(((Thing) result1.AsOk).val) + : Result.Err(new None()); var iresult2 = result2.IsOk - ? Result.ok(((Thing) result2.AsOk).val) - : Result.err(new None()); + ? Result.Ok(((Thing) result2.AsOk).val) + : Result.Err(new None()); return Host.Foo(ir1, ir2, ir3, it1, it2, iv1, iv2, il1, il2, io1, io2, iresult1, iresult2) + 4; } diff --git a/tests/runtime/results/wasm.cs b/tests/runtime/results/wasm.cs index bca72de5..81ca3296 100644 --- a/tests/runtime/results/wasm.cs +++ b/tests/runtime/results/wasm.cs @@ -44,19 +44,19 @@ public static float VariantError(float a) } catch (WitException e) { var value = (ResultsWorld.wit.imports.test.results.ITest.E3) e.Value; switch (value.Tag) { - case ResultsWorld.wit.imports.test.results.ITest.E3.E1: + case ResultsWorld.wit.imports.test.results.ITest.E3.Tags.E1: switch (value.AsE1) { case ResultsWorld.wit.imports.test.results.ITest.E.A: - throw new WitException(ITest.E3.e1(ITest.E.A), 0); + throw new WitException(ITest.E3.E1(ITest.E.A), 0); case ResultsWorld.wit.imports.test.results.ITest.E.B: - throw new WitException(ITest.E3.e1(ITest.E.B), 0); + throw new WitException(ITest.E3.E1(ITest.E.B), 0); case ResultsWorld.wit.imports.test.results.ITest.E.C: - throw new WitException(ITest.E3.e1(ITest.E.C), 0); + throw new WitException(ITest.E3.E1(ITest.E.C), 0); default: throw new Exception("unreachable"); } - case ResultsWorld.wit.imports.test.results.ITest.E3.E2: { - throw new WitException(ITest.E3.e2(new ITest.E2(value.AsE2.line, value.AsE2.column)), 0); + case ResultsWorld.wit.imports.test.results.ITest.E3.Tags.E2: { + throw new WitException(ITest.E3.E2(new ITest.E2(value.AsE2.line, value.AsE2.column)), 0); } default: throw new Exception("unreachable"); diff --git a/tests/runtime/variants/wasm.cs b/tests/runtime/variants/wasm.cs index 66235c76..6ee29b8f 100644 --- a/tests/runtime/variants/wasm.cs +++ b/tests/runtime/variants/wasm.cs @@ -14,10 +14,10 @@ public static void TestImports() Debug.Assert(TestInterop.RoundtripOption(null).HasValue == false); Debug.Assert(TestInterop.RoundtripOption(2.0f).Value == 2); - Debug.Assert(TestInterop.RoundtripResult(Result.ok(2)) == 2.0); - Debug.Assert(TestInterop.RoundtripResult(Result.ok(4)) == 4.0); + Debug.Assert(TestInterop.RoundtripResult(Result.Ok(2)) == 2.0); + Debug.Assert(TestInterop.RoundtripResult(Result.Ok(4)) == 4.0); try { - TestInterop.RoundtripResult(Result.err(5.3f)); + TestInterop.RoundtripResult(Result.Err(5.3f)); throw new Exception(); } catch (WitException e) { Debug.Assert((byte)e.Value == 5); @@ -30,7 +30,7 @@ public static void TestImports() Debug.Assert(TestInterop.InvertBool(false) == true); var (a1, a2, a3, a4, a5, a6) = - TestInterop.VariantCasts((ITest.C1.a(1), ITest.C2.a(2), ITest.C3.a(3), ITest.C4.a(4), ITest.C5.a(5), ITest.C6.a(6.0f))); + TestInterop.VariantCasts((ITest.C1.A(1), ITest.C2.A(2), ITest.C3.A(3), ITest.C4.A(4), ITest.C5.A(5), ITest.C6.A(6.0f))); Debug.Assert(a1.AsA == 1); Debug.Assert(a2.AsA == 2); Debug.Assert(a3.AsA == 3); @@ -39,7 +39,7 @@ public static void TestImports() Debug.Assert(a6.AsA == 6.0f); var (b1, b2, b3, b4, b5, b6) = -TestInterop.VariantCasts((ITest.C1.b(1), ITest.C2.b(2), ITest.C3.b(3), ITest.C4.b(4), ITest.C5.b(5), ITest.C6.b(6.0))); +TestInterop.VariantCasts((ITest.C1.B(1), ITest.C2.B(2), ITest.C3.B(3), ITest.C4.B(4), ITest.C5.B(5), ITest.C6.B(6.0))); Debug.Assert(b1.AsB == 1); Debug.Assert(b2.AsB == 2.0f); Debug.Assert(b3.AsB == 3.0f); @@ -48,23 +48,23 @@ public static void TestImports() Debug.Assert(b6.AsB == 6.0); var (za1, za2, za3, za4) = -TestInterop.VariantZeros((ITest.Z1.a(1), ITest.Z2.a(2), ITest.Z3.a(3.0f), ITest.Z4.a(4.0f))); +TestInterop.VariantZeros((ITest.Z1.A(1), ITest.Z2.A(2), ITest.Z3.A(3.0f), ITest.Z4.A(4.0f))); Debug.Assert(za1.AsA == 1); Debug.Assert(za2.AsA == 2); Debug.Assert(za3.AsA == 3.0f); Debug.Assert(za4.AsA == 4.0f); var (zb1, zb2, zb3, zb4) = -TestInterop.VariantZeros((ITest.Z1.b(), ITest.Z2.b(), ITest.Z3.b(), ITest.Z4.b())); +TestInterop.VariantZeros((ITest.Z1.B(), ITest.Z2.B(), ITest.Z3.B(), ITest.Z4.B())); //TODO: Add comparison operator to variants and None //Debug.Assert(zb1.AsB == ITest.Z1.b()); //Debug.Assert(zb2.AsB == ITest.Z2.b()); //Debug.Assert(zb3.AsB == ITest.Z3.b()); //Debug.Assert(zb4.AsB == ITest.Z4.b()); - TestInterop.VariantTypedefs(null, false, Result.err(new None())); + TestInterop.VariantTypedefs(null, false, Result.Err(new None())); - var (a, b, c) = TestInterop.VariantEnums(true, Result.ok(new None()), ITest.MyErrno.SUCCESS); + var (a, b, c) = TestInterop.VariantEnums(true, Result.Ok(new None()), ITest.MyErrno.SUCCESS); Debug.Assert(a == false); var test = b.AsErr; Debug.Assert(c == ITest.MyErrno.A); @@ -85,8 +85,8 @@ public static double RoundtripResult(Result a) { switch (a.Tag) { - case Result.OK: return (double)a.AsOk; - case Result.ERR: throw new WitException((byte)a.AsErr, 0); + case Result.Tags.Ok: return (double)a.AsOk; + case Result.Tags.Err: throw new WitException((byte)a.AsErr, 0); default: throw new ArgumentException(); } } From d92b53b261433e946c144349298d079b14f1dbc1 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 20 Nov 2024 08:09:33 -0800 Subject: [PATCH 07/10] Ensure module attributes are applied to all top-level modules. (#1091) Effectively revert #1089, and go back to putting `#[allow(dead_code)]` on all modules for now, because the code in #1089 didn't work for interfaces defined inline inside of worlds, which turn into top-level modules in the Rust bindings. --- crates/rust/src/interface.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index 2002016f..d8a601db 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -445,6 +445,7 @@ macro_rules! {macro_name} {{ let module = format!( "\ {docs} + #[allow(dead_code, clippy::all)] pub mod {snake} {{ {used_static} {module} From 327efdcc52027e1eb9383cb7447a059ba5e1dfdb Mon Sep 17 00:00:00 2001 From: Victor Adossi <123968127+vados-cosmonic@users.noreply.github.com> Date: Fri, 22 Nov 2024 03:55:31 +0900 Subject: [PATCH 08/10] remove unused deps, force newer syn, some lint fixes (#1095) * chore(deps): remove unused dep from csharp bindgen Signed-off-by: Victor Adossi * chore(deps): remove unused dep from moonbit bindgen Signed-off-by: Victor Adossi * chore(deps): remove unused dep from markdown bindgen Signed-off-by: Victor Adossi * chore(deps): update syn dep to avoid regression This commit addresses the regression noted upstream in `proc-macro2` by way of `syn` (see dtolnay/proc-macro2 #484) Signed-off-by: Victor Adossi * chore(csharp): fix some lint warnings in csharp bindgen Signed-off-by: Victor Adossi --------- Signed-off-by: Victor Adossi --- Cargo.lock | 11 ++++------- Cargo.toml | 2 +- crates/csharp/Cargo.toml | 1 - crates/csharp/src/lib.rs | 4 +++- crates/markdown/Cargo.toml | 1 - crates/moonbit/Cargo.toml | 2 -- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b7bf461..a83cc52e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,9 +1130,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" dependencies = [ "unicode-ident", ] @@ -1410,9 +1410,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.79" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -2413,7 +2413,6 @@ dependencies = [ "heck 0.5.0", "pulldown-cmark", "wit-bindgen-core", - "wit-component", ] [[package]] @@ -2424,9 +2423,7 @@ dependencies = [ "clap", "heck 0.5.0", "test-helpers", - "wasm-metadata", "wit-bindgen-core", - "wit-component", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b8cbf23b..acd1d3fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ pulldown-cmark = { version = "0.9", default-features = false } clap = { version = "4.3.19", features = ["derive"] } indexmap = "2.0.0" prettyplease = "0.2.20" -syn = { version = "2.0", features = ["printing"] } +syn = { version = "2.0.89", features = ["printing"] } wasmparser = "0.220.0" wasm-encoder = "0.220.0" diff --git a/crates/csharp/Cargo.toml b/crates/csharp/Cargo.toml index e2d1c16d..04bf0215 100644 --- a/crates/csharp/Cargo.toml +++ b/crates/csharp/Cargo.toml @@ -16,7 +16,6 @@ doctest = false test = false [dependencies] -wasm-encoder = { workspace = true } wit-bindgen-core = { workspace = true } wit-component = { workspace = true } wit-parser = { workspace = true } diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs index 744239a9..2081a433 100644 --- a/crates/csharp/src/lib.rs +++ b/crates/csharp/src/lib.rs @@ -124,6 +124,7 @@ pub struct CSharp { opts: Opts, name: String, usings: HashSet, + #[allow(unused)] interop_usings: HashSet, return_area_size: usize, return_area_align: usize, @@ -198,6 +199,7 @@ impl CSharp { } } + #[allow(unused)] fn require_interop_using(&mut self, using_ns: &str) { if !self.interop_usings.contains(using_ns) { let using_ns_string = using_ns.to_string(); @@ -2691,7 +2693,7 @@ impl Bindgen for FunctionBindgen<'_, '_> { )); } - Instruction::ListLower { element, realloc } => { + Instruction::ListLower { element, .. } => { let Block { body, results: block_results, diff --git a/crates/markdown/Cargo.toml b/crates/markdown/Cargo.toml index 057eb8fd..99cec78f 100644 --- a/crates/markdown/Cargo.toml +++ b/crates/markdown/Cargo.toml @@ -20,4 +20,3 @@ heck = { workspace = true } pulldown-cmark = { workspace = true } clap = { workspace = true, optional = true } wit-bindgen-core = { workspace = true } -wit-component = { workspace = true } diff --git a/crates/moonbit/Cargo.toml b/crates/moonbit/Cargo.toml index 119761cf..cdd81870 100644 --- a/crates/moonbit/Cargo.toml +++ b/crates/moonbit/Cargo.toml @@ -14,8 +14,6 @@ through the `wit-bindgen-cli` crate. [dependencies] anyhow = { workspace = true } wit-bindgen-core = { workspace = true } -wit-component = { workspace = true } -wasm-metadata = { workspace = true } heck = { workspace = true } clap = { workspace = true, optional = true } From 811b5e67f08ac244853e70527659d6a446ab0469 Mon Sep 17 00:00:00 2001 From: yowl Date: Fri, 22 Nov 2024 09:55:27 -0500 Subject: [PATCH 09/10] add another element of type f32 to the variant test (#1094) --- crates/csharp/src/lib.rs | 2 +- tests/codegen/variants.wit | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/csharp/src/lib.rs b/crates/csharp/src/lib.rs index 2081a433..a771954f 100644 --- a/crates/csharp/src/lib.rs +++ b/crates/csharp/src/lib.rs @@ -3229,7 +3229,7 @@ fn dotnet_aligned_array(array_size: usize, required_alignment: usize) -> (usize, fn perform_cast(op: &String, cast: &Bitcast) -> String { match cast { - Bitcast::I32ToF32 => format!("BitConverter.Int32BitsToSingle({op})"), + Bitcast::I32ToF32 => format!("BitConverter.Int32BitsToSingle((int){op})"), Bitcast::I64ToF32 => format!("BitConverter.Int32BitsToSingle((int){op})"), Bitcast::F32ToI32 => format!("BitConverter.SingleToInt32Bits({op})"), Bitcast::F32ToI64 => format!("BitConverter.SingleToInt32Bits({op})"), diff --git a/tests/codegen/variants.wit b/tests/codegen/variants.wit index 6d0feef8..4b3023e5 100644 --- a/tests/codegen/variants.wit +++ b/tests/codegen/variants.wit @@ -21,6 +21,7 @@ interface variants { e(empty), f, g(u32), + h(f32), } v1-arg: func(x: v1); From d1387cc70f67c53e31e2668a30a1e4fc8bdcb95a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:12:21 -0800 Subject: [PATCH 10/10] Release wit-bindgen 0.36.0 (#1097) [automatically-tag-and-release-this-commit] Co-authored-by: Auto Release Process --- Cargo.lock | 24 +++++++++--------- Cargo.toml | 20 +++++++-------- crates/guest-rust/Cargo.toml | 4 +-- crates/guest-rust/rt/src/cabi_realloc.c | 4 +-- crates/guest-rust/rt/src/cabi_realloc.o | Bin 261 -> 261 bytes crates/guest-rust/rt/src/cabi_realloc.rs | 2 +- .../rt/src/libwit_bindgen_cabi_realloc.a | Bin 412 -> 412 bytes 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a83cc52e..a68ba8ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2321,7 +2321,7 @@ dependencies = [ [[package]] name = "wit-bindgen" -version = "0.35.0" +version = "0.36.0" dependencies = [ "wit-bindgen-rt", "wit-bindgen-rust-macro", @@ -2329,7 +2329,7 @@ dependencies = [ [[package]] name = "wit-bindgen-c" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2344,7 +2344,7 @@ dependencies = [ [[package]] name = "wit-bindgen-cli" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2368,7 +2368,7 @@ dependencies = [ [[package]] name = "wit-bindgen-core" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "heck 0.5.0", @@ -2377,7 +2377,7 @@ dependencies = [ [[package]] name = "wit-bindgen-csharp" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2394,7 +2394,7 @@ dependencies = [ [[package]] name = "wit-bindgen-go" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2406,7 +2406,7 @@ dependencies = [ [[package]] name = "wit-bindgen-markdown" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2417,7 +2417,7 @@ dependencies = [ [[package]] name = "wit-bindgen-moonbit" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2428,14 +2428,14 @@ dependencies = [ [[package]] name = "wit-bindgen-rt" -version = "0.35.0" +version = "0.36.0" dependencies = [ "bitflags", ] [[package]] name = "wit-bindgen-rust" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", @@ -2454,7 +2454,7 @@ dependencies = [ [[package]] name = "wit-bindgen-rust-macro" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "prettyplease", @@ -2467,7 +2467,7 @@ dependencies = [ [[package]] name = "wit-bindgen-teavm-java" -version = "0.35.0" +version = "0.36.0" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index acd1d3fb..8232acf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ resolver = "2" [workspace.package] edition = "2021" -version = "0.35.0" +version = "0.36.0" license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT" repository = "https://github.com/bytecodealliance/wasi-rs" @@ -38,15 +38,15 @@ wasm-metadata = "0.220.0" wit-parser = "0.220.0" wit-component = "0.220.0" -wit-bindgen-core = { path = 'crates/core', version = '0.35.0' } -wit-bindgen-c = { path = 'crates/c', version = '0.35.0' } -wit-bindgen-rust = { path = "crates/rust", version = "0.35.0" } -wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.35.0' } -wit-bindgen-go = { path = 'crates/go', version = '0.35.0' } -wit-bindgen-csharp = { path = 'crates/csharp', version = '0.35.0' } -wit-bindgen-markdown = { path = 'crates/markdown', version = '0.35.0' } -wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.35.0' } -wit-bindgen = { path = 'crates/guest-rust', version = '0.35.0', default-features = false } +wit-bindgen-core = { path = 'crates/core', version = '0.36.0' } +wit-bindgen-c = { path = 'crates/c', version = '0.36.0' } +wit-bindgen-rust = { path = "crates/rust", version = "0.36.0" } +wit-bindgen-teavm-java = { path = 'crates/teavm-java', version = '0.36.0' } +wit-bindgen-go = { path = 'crates/go', version = '0.36.0' } +wit-bindgen-csharp = { path = 'crates/csharp', version = '0.36.0' } +wit-bindgen-markdown = { path = 'crates/markdown', version = '0.36.0' } +wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.36.0' } +wit-bindgen = { path = 'crates/guest-rust', version = '0.36.0', default-features = false } [[bin]] name = "wit-bindgen" diff --git a/crates/guest-rust/Cargo.toml b/crates/guest-rust/Cargo.toml index 1f666c47..713256ed 100644 --- a/crates/guest-rust/Cargo.toml +++ b/crates/guest-rust/Cargo.toml @@ -12,8 +12,8 @@ Used when compiling Rust programs to the component model. """ [dependencies] -wit-bindgen-rust-macro = { path = "./macro", optional = true, version = "0.35.0" } -wit-bindgen-rt = { path = "./rt", version = "0.35.0", features = ["bitflags"] } +wit-bindgen-rust-macro = { path = "./macro", optional = true, version = "0.36.0" } +wit-bindgen-rt = { path = "./rt", version = "0.36.0", features = ["bitflags"] } [features] default = ["macros", "realloc"] diff --git a/crates/guest-rust/rt/src/cabi_realloc.c b/crates/guest-rust/rt/src/cabi_realloc.c index ac43d593..194be80c 100644 --- a/crates/guest-rust/rt/src/cabi_realloc.c +++ b/crates/guest-rust/rt/src/cabi_realloc.c @@ -2,9 +2,9 @@ #include -extern void *cabi_realloc_wit_bindgen_0_35_0(void *ptr, size_t old_size, size_t align, size_t new_size); +extern void *cabi_realloc_wit_bindgen_0_36_0(void *ptr, size_t old_size, size_t align, size_t new_size); __attribute__((__weak__, __export_name__("cabi_realloc"))) void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) { - return cabi_realloc_wit_bindgen_0_35_0(ptr, old_size, align, new_size); + return cabi_realloc_wit_bindgen_0_36_0(ptr, old_size, align, new_size); } diff --git a/crates/guest-rust/rt/src/cabi_realloc.o b/crates/guest-rust/rt/src/cabi_realloc.o index ec50876e3c06c0235b18cd76d7b3c84488186671..f8b0e106fa04d6d393468f0f1da90f54b152f944 100644 GIT binary patch delta 11 ScmZo=YGs<>$7nXue;WW4I|I4^ delta 11 ScmZo=YGs<>$7njye;WW4Hv_o< diff --git a/crates/guest-rust/rt/src/cabi_realloc.rs b/crates/guest-rust/rt/src/cabi_realloc.rs index a2fa05ac..b6bf8354 100644 --- a/crates/guest-rust/rt/src/cabi_realloc.rs +++ b/crates/guest-rust/rt/src/cabi_realloc.rs @@ -1,7 +1,7 @@ // This file is generated by ./ci/rebuild-libcabi-realloc.sh #[no_mangle] -pub unsafe extern "C" fn cabi_realloc_wit_bindgen_0_35_0( +pub unsafe extern "C" fn cabi_realloc_wit_bindgen_0_36_0( old_ptr: *mut u8, old_len: usize, align: usize, diff --git a/crates/guest-rust/rt/src/libwit_bindgen_cabi_realloc.a b/crates/guest-rust/rt/src/libwit_bindgen_cabi_realloc.a index 539976be9d90dd8feddf59e23fe409dfd28f2019..38e29567b9d7e24f604df7acd01e9778b2ec9707 100644 GIT binary patch delta 11 TcmbQkJcoJ06GpR%PqzaA8p;J1 delta 11 TcmbQkJcoJ06GqdCPqzaA8pZ_{