From 332430a7be643a5e6b72d5cb59358cb5b093f03a Mon Sep 17 00:00:00 2001 From: sehnryr Date: Wed, 17 Apr 2024 19:26:53 +0200 Subject: [PATCH] feat: add support for every other settings from wit-bindgen https://github.com/bytecodealliance/wit-bindgen/blob/90a1e547e1a4515a5769f5d157ffc519c5d851a3/crates/rust/src/lib.rs#L87-L189 --- src/bindings.rs | 16 +++++++++++++++- src/metadata.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/bindings.rs b/src/bindings.rs index 63448d0b..c12d19e4 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -161,7 +161,21 @@ impl<'a> BindingsGenerator<'a> { std_feature: settings.std_feature, runtime_path: Some("wit_bindgen_rt".to_string()), bitflags_path: Some("wit_bindgen_rt::bitflags".to_string()), - ..Default::default() + raw_strings: settings.raw_strings, + skip: settings.skip.clone(), + stubs: settings.stubs, + export_prefix: settings.export_prefix.clone(), + with: settings + .with + .iter() + .map(|(key, value)| (key.clone(), value.clone())) + .collect(), + type_section_suffix: settings.type_section_suffix.clone(), + disable_run_ctors_once_workaround: settings.disable_run_ctors_once_workaround, + default_bindings_module: settings.default_bindings_module.clone(), + export_macro_name: settings.export_macro_name.clone(), + pub_export_macro: settings.pub_export_macro, + generate_unused_types: settings.generate_unused_types, }; let mut files = Files::default(); diff --git a/src/metadata.rs b/src/metadata.rs index 851ef7b2..486279bd 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -69,6 +69,38 @@ pub struct Bindings { /// If true, code generation should qualify any features that depend on /// `std` with `cfg(feature = "std")`. pub std_feature: bool, + /// If true, code generation should pass borrowed string arguments as + /// `&[u8]` instead of `&str`. Strings are still required to be valid + /// UTF-8, but this avoids the need for Rust code to do its own UTF-8 + /// validation if it doesn't already have a `&str` + pub raw_strings: bool, + /// Names of functions to skip generating bindings for. + pub skip: Vec, + /// If true, generate stub implementations for any exported functions, + /// interfaces, and/or resources. + pub stubs: bool, + /// Optionally prefix any export names with the specified value. + /// + /// This is useful to avoid name conflicts when testing. + pub export_prefix: Option, + /// Remapping of interface names to rust module names. + pub with: HashMap, + /// Add the specified suffix to the name of the custome section containing + /// the component type. + pub type_section_suffix: Option, + /// Disable a workaround used to prevent libc ctors/dtors from being invoked + /// too much. + pub disable_run_ctors_once_workaround: bool, + /// Changes the default module used in the generated `export!` macro to + /// something other than `self`. + pub default_bindings_module: Option, + /// Alternative name to use for the `export!` macro if one is generated. + pub export_macro_name: Option, + /// Ensures that the `export!` macro will be defined as `pub` so it is a + /// candidate for being exported outside of the crate. + pub pub_export_macro: bool, + /// Whether to generate unused structures, not generated by default (false) + pub generate_unused_types: bool, } impl Default for Bindings { @@ -78,6 +110,17 @@ impl Default for Bindings { ownership: Default::default(), derives: Default::default(), std_feature: false, + raw_strings: Default::default(), + skip: Default::default(), + stubs: Default::default(), + export_prefix: Default::default(), + with: Default::default(), + type_section_suffix: Default::default(), + disable_run_ctors_once_workaround: Default::default(), + default_bindings_module: Default::default(), + export_macro_name: Default::default(), + pub_export_macro: Default::default(), + generate_unused_types: Default::default(), } } }