From 315e9838ad419e1041ab3f72524e8c067bf714b4 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sat, 4 May 2024 12:01:17 +0200 Subject: [PATCH 01/24] improve error message in build.rs --- wasm3-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index c4ead44..500de65 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -65,7 +65,7 @@ fn gen_bindings() { )) .arg("-Dd_m3LogOutput=0") .arg("-Iwasm3/source"); - let status = bindgen.status().expect("Unable to generate bindings"); + let status = bindgen.status().unwrap_or_else(|error| panic!("Unable to generate bindings: {}", error.to_string())); if !status.success() { panic!("Failed to run bindgen: {:?}", status); } From 61a2272cb92462485034a103d2a9ec8b9ac04adc Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sat, 4 May 2024 12:15:01 +0200 Subject: [PATCH 02/24] update bindgen to 0.64 --- wasm3-sys/Cargo.toml | 2 +- wasm3-sys/build.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index 2b9adc5..47746a2 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -25,7 +25,7 @@ cc = "1" shlex = "0.1.1" [build-dependencies.bindgen] -version = "0.59" +version = "0.64" optional = true [package.metadata.docs.rs] diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 500de65..d7bfef9 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -40,15 +40,15 @@ fn gen_bindings() { .arg("--no-layout-tests") .arg("--default-enum-style=moduleconsts") .arg("--no-doc-comments") - .arg("--whitelist-function") + .arg("--allowlist-function") .arg(WHITELIST_REGEX_FUNCTION) - .arg("--whitelist-type") + .arg("--allowlist-type") .arg(WHITELIST_REGEX_TYPE) - .arg("--whitelist-var") + .arg("--allowlist-var") .arg(WHITELIST_REGEX_VAR) .arg("--no-derive-debug"); for &ty in PRIMITIVES.iter() { - bindgen.arg("--blacklist-type").arg(ty); + bindgen.arg("--blocklist-type").arg(ty); } bindgen .arg("-o") From 913b6ba7652153948f69b5fe181169a125db9004 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sun, 5 May 2024 09:44:51 +0200 Subject: [PATCH 03/24] add ParsedModule::compile method --- src/module.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/module.rs b/src/module.rs index 43f36b9..d1c8a6e 100644 --- a/src/module.rs +++ b/src/module.rs @@ -59,6 +59,11 @@ impl ParsedModule { data } + /// Compile all functions in the module. + pub fn compile(&mut self) { + unsafe { ffi::m3_FreeModule(self.raw.0.as_ptr()) }; + } + /// The environment this module was parsed in. pub fn environment(&self) -> &Environment { &self.env From 708f8d6c4ef29694c79a89f926528a990a13d372 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sun, 5 May 2024 09:48:32 +0200 Subject: [PATCH 04/24] remove ParsedModule::compile, add Module::compile --- src/module.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/module.rs b/src/module.rs index d1c8a6e..c2fdee7 100644 --- a/src/module.rs +++ b/src/module.rs @@ -59,11 +59,6 @@ impl ParsedModule { data } - /// Compile all functions in the module. - pub fn compile(&mut self) { - unsafe { ffi::m3_FreeModule(self.raw.0.as_ptr()) }; - } - /// The environment this module was parsed in. pub fn environment(&self) -> &Environment { &self.env @@ -226,6 +221,11 @@ impl<'rt> Module<'rt> { unsafe { cstr_to_str(ffi::m3_GetModuleName(self.raw)) } } + /// Compile all functions in the module. + pub fn compile(&mut self) { + unsafe { ffi::m3_FreeModule(self.raw) }; + } + /// Links wasi to this module. #[cfg(feature = "wasi")] pub fn link_wasi(&mut self) -> Result<()> { From a7ba82fcaa6638f14edfc2d56df5a289e9e9bd5d Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sun, 5 May 2024 10:06:34 +0200 Subject: [PATCH 05/24] properly implement Module::compile ... --- src/module.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module.rs b/src/module.rs index c2fdee7..1819371 100644 --- a/src/module.rs +++ b/src/module.rs @@ -222,8 +222,8 @@ impl<'rt> Module<'rt> { } /// Compile all functions in the module. - pub fn compile(&mut self) { - unsafe { ffi::m3_FreeModule(self.raw) }; + pub fn compile(&mut self) -> Result<()> { + unsafe { Error::from_ffi_res(ffi::m3_CompileModule(self.raw)) } } /// Links wasi to this module. From 96299e429da1ee0a36bed19a0a8bc1183e687ed3 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Sun, 5 May 2024 11:00:57 +0200 Subject: [PATCH 06/24] update wasm3 submodule to main --- wasm3-sys/wasm3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/wasm3 b/wasm3-sys/wasm3 index 6b8bcb1..139076a 160000 --- a/wasm3-sys/wasm3 +++ b/wasm3-sys/wasm3 @@ -1 +1 @@ -Subproject commit 6b8bcb1e07bf26ebef09a7211b0a37a446eafd52 +Subproject commit 139076a98b8321b67f850a844f558b5e91b5ac83 From 603bdea32718cd4195a2af0f74d4bb47e441476a Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:21:36 +0100 Subject: [PATCH 07/24] remove unused macro export --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4f97f8e..95f8057 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,6 @@ pub use self::environment::Environment; mod function; pub use self::function::{CallContext, Function, RawCall}; mod macros; -pub use self::macros::*; mod module; pub use self::module::{Module, ParsedModule}; mod runtime; From 471bbc754a5a51d028062f0cac6cfaed5535467b Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:21:43 +0100 Subject: [PATCH 08/24] fix broken doc link --- src/module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/module.rs b/src/module.rs index 1819371..3deac90 100644 --- a/src/module.rs +++ b/src/module.rs @@ -84,7 +84,7 @@ impl<'rt> Module<'rt> { /// Links the given function to the corresponding module and function name. /// This allows linking a more verbose function, as it gets access to the unsafe - /// runtime parts. For easier use the [`make_func_wrapper`] should be used to create + /// runtime parts. For easier use the [`crate::make_func_wrapper`] should be used to create /// the unsafe facade for your function that then can be passed to this. /// /// For a simple API see [`link_closure`] which takes a closure instead. From ef307285a938ae759b6d60a85105b5a28faaa869 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:21:50 +0100 Subject: [PATCH 09/24] update bindgen version --- wasm3-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index 47746a2..1324600 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -25,7 +25,7 @@ cc = "1" shlex = "0.1.1" [build-dependencies.bindgen] -version = "0.64" +version = "0.71.1" optional = true [package.metadata.docs.rs] From c05a2ee2443fcf4232b23b66ca8496c530e8e4ae Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:22:09 +0100 Subject: [PATCH 10/24] update shlex version --- wasm3-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index 1324600..e004ea4 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -22,7 +22,7 @@ cty = "0.2" [build-dependencies] cc = "1" -shlex = "0.1.1" +shlex = "1.3.0" [build-dependencies.bindgen] version = "0.71.1" From edabd117e03c58ccbc06f791d9c26031d0ac074f Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:22:48 +0100 Subject: [PATCH 11/24] update Rust edition: 2018 -> 2021 --- wasm3-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/Cargo.toml b/wasm3-sys/Cargo.toml index e004ea4..5e404c1 100644 --- a/wasm3-sys/Cargo.toml +++ b/wasm3-sys/Cargo.toml @@ -2,7 +2,7 @@ name = "wasm3-sys" version = "0.5.0" authors = ["Lukas Tobias Wirth "] -edition = "2018" +edition = "2021" description = "Raw ffi bindings for wasm3" homepage = "https://github.com/wasm3/wasm3-rs" repository = "https://github.com/wasm3/wasm3-rs" From 4f82ec59d4b5f9c48561f0d041beae10c83daca6 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:23:04 +0100 Subject: [PATCH 12/24] apply rustfmt --- wasm3-sys/build.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index d7bfef9..e9c0bec 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -65,7 +65,9 @@ fn gen_bindings() { )) .arg("-Dd_m3LogOutput=0") .arg("-Iwasm3/source"); - let status = bindgen.status().unwrap_or_else(|error| panic!("Unable to generate bindings: {}", error.to_string())); + let status = bindgen + .status() + .unwrap_or_else(|error| panic!("Unable to generate bindings: {}", error.to_string())); if !status.success() { panic!("Failed to run bindgen: {:?}", status); } From 710981369cefa2043600c1ae29856e0cfb5f2927 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:27:24 +0100 Subject: [PATCH 13/24] apply clippy suggestions --- src/environment.rs | 2 +- src/function.rs | 10 +++++----- src/ty.rs | 2 +- src/utils.rs | 2 +- wasm3-sys/build.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index e3e060b..643e224 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -57,7 +57,7 @@ impl Environment { impl core::cmp::Eq for Environment {} impl core::cmp::PartialEq for Environment { - fn eq(&self, &Environment(ref other): &Environment) -> bool { + fn eq(&self, Environment(other): &Environment) -> bool { alloc::rc::Rc::ptr_eq(&self.0, other) } } diff --git a/src/function.rs b/src/function.rs index c5534a3..a128879 100644 --- a/src/function.rs +++ b/src/function.rs @@ -67,14 +67,14 @@ pub struct Function<'rt, Args, Ret> { _pd: PhantomData<*const (Args, Ret)>, } -impl<'rt, Args, Ret> Eq for Function<'rt, Args, Ret> {} -impl<'rt, Args, Ret> PartialEq for Function<'rt, Args, Ret> { +impl Eq for Function<'_, Args, Ret> {} +impl PartialEq for Function<'_, Args, Ret> { fn eq(&self, other: &Self) -> bool { self.raw == other.raw } } -impl<'rt, Args, Ret> Hash for Function<'rt, Args, Ret> { +impl Hash for Function<'_, Args, Ret> { fn hash(&self, state: &mut H) { self.raw.hash(state); } @@ -173,7 +173,7 @@ macro_rules! func_call_impl { } func_call_impl!(A, B, C, D, E, F, G, H, J, K, L, M, N, O, P, Q); -impl<'rt, ARG, Ret> Function<'rt, ARG, Ret> +impl Function<'_, ARG, Ret> where Ret: WasmType, ARG: WasmArg, @@ -188,7 +188,7 @@ where } } -impl<'rt, Ret> Function<'rt, (), Ret> +impl Function<'_, (), Ret> where Ret: WasmType, { diff --git a/src/ty.rs b/src/ty.rs index 86a3b64..afe602c 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -242,7 +242,7 @@ macro_rules! args_impl { }; (@do_impl) => {/* catch the () case, since its implementation differs slightly */}; (@do_impl $($types:ident,)*) => { - #[allow(clippy::eval_order_dependence)] + #[allow(clippy::mixed_read_write_in_expression)] #[allow(unused_assignments)] impl<$($types,)*> WasmArgs for ($($types,)*) where $($types: WasmArg,)* { diff --git a/src/utils.rs b/src/utils.rs index f923a39..a7d0c4b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,7 +19,7 @@ pub unsafe fn cstr_to_str<'a>(ptr: *const cty::c_char) -> &'a str { } pub fn str_to_cstr_owned(str: &str) -> Vec { - let mut cstr = Vec::with_capacity(str.as_bytes().len() + 1); + let mut cstr = Vec::with_capacity(str.len() + 1); cstr.extend(str.bytes().map(|c| c as cty::c_char)); cstr.push(0 as cty::c_char); cstr diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index e9c0bec..c9e2c3f 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -67,7 +67,7 @@ fn gen_bindings() { .arg("-Iwasm3/source"); let status = bindgen .status() - .unwrap_or_else(|error| panic!("Unable to generate bindings: {}", error.to_string())); + .unwrap_or_else(|error| panic!("Unable to generate bindings: {error}")); if !status.success() { panic!("Failed to run bindgen: {:?}", status); } From 9c765891d51a51a0653a664ee7ae5c82dab1bf1b Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:28:00 +0100 Subject: [PATCH 14/24] bump Rust edition: 2018 -> 2021 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fbfb507..cb9906d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "wasm3" version = "0.5.0" authors = ["Lukas Tobias Wirth "] -edition = "2018" +edition = "2021" description = "Rust bindings for wasm3" homepage = "https://github.com/wasm3/wasm3-rs" repository = "https://github.com/wasm3/wasm3-rs" From 414d7ad1b1dc07aa9b6d700e3e8ad71d43c6b600 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:55:10 +0100 Subject: [PATCH 15/24] clean up build script --- wasm3-sys/build.rs | 61 ++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index c9e2c3f..946295b 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -27,27 +27,27 @@ fn gen_wrapper(out_path: &Path) -> PathBuf { #[cfg(not(feature = "build-bindgen"))] fn gen_bindings() { + use std::process::Command; let out_path = PathBuf::from(&env::var("OUT_DIR").unwrap()); - let wrapper_file = gen_wrapper(&out_path); - - let mut bindgen = std::process::Command::new("bindgen"); - bindgen - .arg(wrapper_file) - .arg("--use-core") - .arg("--ctypes-prefix") - .arg("cty") - .arg("--no-layout-tests") - .arg("--default-enum-style=moduleconsts") - .arg("--no-doc-comments") - .arg("--allowlist-function") - .arg(WHITELIST_REGEX_FUNCTION) - .arg("--allowlist-type") - .arg(WHITELIST_REGEX_TYPE) - .arg("--allowlist-var") - .arg(WHITELIST_REGEX_VAR) - .arg("--no-derive-debug"); - for &ty in PRIMITIVES.iter() { + let mut bindgen = Command::new("bindgen"); + bindgen.arg(wrapper_file); + bindgen.args([ + "--use-core", + "--ctypes-prefix", + "cty", + "--no-layout-tests", + "--default-enum-style=moduleconsts", + "--no-doc-comments", + "--allowlist-function", + WHITELIST_REGEX_FUNCTION, + "--allowlist-type", + WHITELIST_REGEX_TYPE, + "--allowlist-var", + WHITELIST_REGEX_VAR, + "--no-derive-debug", + ]); + for &ty in PRIMITIVES { bindgen.arg("--blocklist-type").arg(ty); } bindgen @@ -57,28 +57,23 @@ fn gen_bindings() { .arg("--") .arg(format!( "-Dd_m3Use32BitSlots={}", - if cfg!(feature = "use-32bit-slots") { - 1 - } else { - 0 - } + cfg!(feature = "use-32bit-slots") as u8, )) .arg("-Dd_m3LogOutput=0") .arg("-Iwasm3/source"); - let status = bindgen - .status() - .unwrap_or_else(|error| panic!("Unable to generate bindings: {error}")); + let status = match bindgen.status() { + Ok(status) => status, + Err(error) => panic!("wasm3: unable to generate bindings: {error}"), + }; if !status.success() { - panic!("Failed to run bindgen: {:?}", status); + panic!("wasm3: failed to run bindgen: {:?}", status); } } #[cfg(feature = "build-bindgen")] fn gen_bindings() { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - let wrapper_file = gen_wrapper(&out_path); - let mut bindgen = bindgen::builder() .header(wrapper_file.to_str().unwrap()) .use_core() @@ -98,11 +93,7 @@ fn gen_bindings() { [ &format!( "-Dd_m3Use32BitSlots={}", - if cfg!(feature = "use-32bit-slots") { - 1 - } else { - 0 - } + cfg!(feature = "use-32bit-slots") as u8, ), "-Dd_m3LogOutput=0", "-Iwasm3/source", From ec8077fe1bd4605afd70e10fda3a79608a4770df Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 15:58:36 +0100 Subject: [PATCH 16/24] separate mod from use --- src/lib.rs | 12 ++++++------ src/utils.rs | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95f8057..d2a06fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,17 +5,17 @@ extern crate alloc; pub mod error; - mod environment; -pub use self::environment::Environment; mod function; -pub use self::function::{CallContext, Function, RawCall}; mod macros; mod module; -pub use self::module::{Module, ParsedModule}; mod runtime; -pub use self::runtime::Runtime; mod ty; -pub use self::ty::{WasmArg, WasmArgs, WasmType}; mod utils; + +pub use self::environment::Environment; +pub use self::function::{CallContext, Function, RawCall}; +pub use self::module::{Module, ParsedModule}; +pub use self::runtime::Runtime; +pub use self::ty::{WasmArg, WasmArgs, WasmType}; pub use ffi as wasm3_sys; diff --git a/src/utils.rs b/src/utils.rs index a7d0c4b..c1889b8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,4 @@ +use core::{slice, str}; use alloc::vec::Vec; pub unsafe fn bytes_till_null<'a>(ptr: *const cty::c_char) -> &'a [u8] { @@ -11,11 +12,11 @@ pub unsafe fn bytes_till_null<'a>(ptr: *const cty::c_char) -> &'a [u8] { ptr = ptr.add(1); len += 1; } - core::slice::from_raw_parts(start, len) + slice::from_raw_parts(start, len) } pub unsafe fn cstr_to_str<'a>(ptr: *const cty::c_char) -> &'a str { - core::str::from_utf8_unchecked(bytes_till_null(ptr)) + str::from_utf8_unchecked(bytes_till_null(ptr)) } pub fn str_to_cstr_owned(str: &str) -> Vec { From cfa5edb54dda0d86f0cf04bc02850bd657052de8 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:00:41 +0100 Subject: [PATCH 17/24] impl Error for core::error::Error stable since Rust 1.81. --- src/error.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/error.rs b/src/error.rs index 7c08cfa..91822f2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -60,8 +60,7 @@ impl cmp::PartialEq for Trap { } } -#[cfg(feature = "std")] -impl std::error::Error for Trap {} +impl core::error::Error for Trap {} impl fmt::Display for Trap { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(unsafe { cstr_to_str(self.as_ptr()) }, f) @@ -85,8 +84,7 @@ impl cmp::PartialEq for Wasm3Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Wasm3Error {} +impl core::error::Error for Wasm3Error {} impl fmt::Debug for Wasm3Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(unsafe { cstr_to_str(self.0) }, f) @@ -129,8 +127,7 @@ impl Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { From fc048fc61cffcd3dfb6f4b71ee631e804ccf472f Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:02:29 +0100 Subject: [PATCH 18/24] apply some formatting --- Cargo.toml | 5 +---- src/lib.rs | 2 +- src/utils.rs | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb9906d..aac43f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,9 @@ exclude = ["examples/*", "tests/*"] members = ["wasm3-sys"] [features] -default = ["wasi", "std", "use-32bit-slots"] - +default = ["wasi", "use-32bit-slots"] wasi = ["ffi/wasi"] -std = [] use-32bit-slots = ["ffi/use-32bit-slots"] - build-bindgen = ["ffi/build-bindgen"] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index d2a06fe..7c07003 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ extern crate alloc; -pub mod error; mod environment; +pub mod error; mod function; mod macros; mod module; diff --git a/src/utils.rs b/src/utils.rs index c1889b8..d899a0c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ -use core::{slice, str}; use alloc::vec::Vec; +use core::{slice, str}; pub unsafe fn bytes_till_null<'a>(ptr: *const cty::c_char) -> &'a [u8] { if ptr.is_null() { From 186a3f96bb20ba966d18dab392ae2919bb4a56de Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:02:39 +0100 Subject: [PATCH 19/24] always enable no_std --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7c07003..41c5196 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] #![warn(missing_docs)] //! A rust wrapper for [WASM3](https://github.com/wasm3/wasm3). From 2d984a67af09e460cf8e543ae89704c60798ae63 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:19:18 +0100 Subject: [PATCH 20/24] improve errors generated by bindgen --- wasm3-sys/build.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 946295b..179a720 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -88,22 +88,22 @@ fn gen_bindings() { bindgen = PRIMITIVES .iter() .fold(bindgen, |bindgen, ty| bindgen.blocklist_type(ty)); + let bindgen = bindgen.clang_args( + [ + &format!( + "-Dd_m3Use32BitSlots={}", + cfg!(feature = "use-32bit-slots") as u8, + ), + "-Dd_m3LogOutput=0", + "-Iwasm3/source", + ] + .iter(), + ); bindgen - .clang_args( - [ - &format!( - "-Dd_m3Use32BitSlots={}", - cfg!(feature = "use-32bit-slots") as u8, - ), - "-Dd_m3LogOutput=0", - "-Iwasm3/source", - ] - .iter(), - ) .generate() - .expect("Failed to generate bindings") + .unwrap_or_else(|error| panic!("bindgen: failed to generate bindings: {error}")) .write_to_file(out_path.join("bindings.rs").to_str().unwrap()) - .expect("Failed to write bindings"); + .unwrap_or_else(|error| panic!("bindgen: failed to write bindings: {error}")); } fn main() { From 2912f3b5e9b009378261357e14a59758b41f3081 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:19:28 +0100 Subject: [PATCH 21/24] make bindgen generate Rust bindings for Rust edition 2021 --- wasm3-sys/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 179a720..1fcb5b1 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -76,6 +76,7 @@ fn gen_bindings() { let wrapper_file = gen_wrapper(&out_path); let mut bindgen = bindgen::builder() .header(wrapper_file.to_str().unwrap()) + .rust_edition(bindgen::RustEdition::Edition2021) .use_core() .ctypes_prefix("cty") .layout_tests(false) From 2c372f73a8e4144e2140e4828720b6ccae12246b Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:29:44 +0100 Subject: [PATCH 22/24] remove .rust_edition call Better to leave out since the default is using the latest edition available. --- wasm3-sys/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 1fcb5b1..179a720 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -76,7 +76,6 @@ fn gen_bindings() { let wrapper_file = gen_wrapper(&out_path); let mut bindgen = bindgen::builder() .header(wrapper_file.to_str().unwrap()) - .rust_edition(bindgen::RustEdition::Edition2021) .use_core() .ctypes_prefix("cty") .layout_tests(false) From b3b2e15a83bd4d99cb81d3553e06d0be58472a61 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:36:37 +0100 Subject: [PATCH 23/24] improve error output of buildscript --- wasm3-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 179a720..65dd6b2 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -113,7 +113,7 @@ fn main() { cfg.files( fs::read_dir(WASM3_SOURCE) - .unwrap_or_else(|_| panic!("failed to read {} directory", WASM3_SOURCE)) + .unwrap_or_else(|error| panic!("failed to read {WASM3_SOURCE} directory: {error}")) .filter_map(Result::ok) .map(|entry| entry.path()) .filter(|p| p.extension().and_then(OsStr::to_str) == Some("c")), From 434d90cb476b08fa85329b978500f44a77024218 Mon Sep 17 00:00:00 2001 From: Robin Freyler Date: Fri, 21 Mar 2025 16:36:45 +0100 Subject: [PATCH 24/24] cleanup buildscript code --- wasm3-sys/build.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wasm3-sys/build.rs b/wasm3-sys/build.rs index 65dd6b2..d19ca00 100644 --- a/wasm3-sys/build.rs +++ b/wasm3-sys/build.rs @@ -143,11 +143,10 @@ fn main() { cfg.define( "d_m3Use32BitSlots", - if cfg!(feature = "use-32bit-slots") { - Some("1") - } else { - Some("0") - }, + match cfg!(feature = "use-32bit-slots") { + true => Some("1"), + false => Some("0"), + } ); cfg.compile("wasm3"); }