From 3ec527655a7e855df02751607dbddd32dc4f7a5a Mon Sep 17 00:00:00 2001 From: Lucy Menon <168595099+syntactically@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:44:49 +0000 Subject: [PATCH] Stop using cargo-component to build examples Previously, we built the component examples using `cargo component`, which is a useful easy entry tool for building components. Unfortunately, `cargo component` has not had a release for some time, and the version of wit-bindgen that it depends on and uses for bindings generation is quite old. That wit-bindgen is no longer compatible with modern `wit-bindgen-rt` when generating bindings using p3 future/stream/async types. This commit replaces `cargo component build` with an explicit `wit_bindgen::generate` macro invocation (which, as a dependency of the example crates, is now in sync with the relevant `wit-bingen-rt` version) and `RUSTFLAGS="-C linker=wasm-component-ld" cargo build --target=wasm32-unknown-unknown`, which seems to work well enough. Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com> --- Cargo.lock | 1 + Justfile | 13 +- .../component_sample/.cargo/config.toml | 5 + .../rust_guests/component_sample/Cargo.lock | 315 +++++++++++++++++- .../rust_guests/component_sample/Cargo.toml | 10 +- .../component_sample/src/bindings.rs | 306 ----------------- .../rust_guests/component_sample/src/lib.rs | 6 +- .../greeter_sample/.cargo/config.toml | 5 + .../rust_guests/greeter_sample/Cargo.lock | 315 +++++++++++++++++- .../rust_guests/greeter_sample/Cargo.toml | 10 +- .../greeter_sample/src/bindings.rs | 222 ------------ .../rust_guests/greeter_sample/src/lib.rs | 7 +- 12 files changed, 654 insertions(+), 561 deletions(-) create mode 100644 src/tests/rust_guests/component_sample/.cargo/config.toml delete mode 100644 src/tests/rust_guests/component_sample/src/bindings.rs create mode 100644 src/tests/rust_guests/greeter_sample/.cargo/config.toml delete mode 100644 src/tests/rust_guests/greeter_sample/src/bindings.rs diff --git a/Cargo.lock b/Cargo.lock index 5434f2ab..e5023f7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2085,6 +2085,7 @@ dependencies = [ "cargo_metadata", "clap", "object 0.39.1", + "rustc_version", "wasmtime 36.0.18", "wasmtime 47.0.4", ] diff --git a/Justfile b/Justfile index 7a04ccae..dbf31c97 100644 --- a/Justfile +++ b/Justfile @@ -17,7 +17,6 @@ make-vendor-tar: -C ./src wasm_runtime hyperlight_wasm_macro wasm-tools-version := "1.235.0" -cargo-component-version := "0.21.1" wit-bindgen-version := "0.58.0" cargo-hyperlight-version := "0.1.14" @@ -26,7 +25,7 @@ cargo-hyperlight-version := "0.1.14" ensure-tool crate version command: {{ if os() == "windows" { "if (-not ($(try { " + command + " --version 2>$null } catch {}) -like '*" + version + "*')) { cargo install --locked --force --version " + version + " " + crate + " }" } else { command + " --version 2>/dev/null | grep -qF '" + version + "' || cargo install --locked --force --version " + version + " " + crate } }} -ensure-tools: (ensure-tool "wasm-tools" wasm-tools-version "wasm-tools") (ensure-tool "cargo-component" cargo-component-version "cargo component") (ensure-tool "wit-bindgen-cli" wit-bindgen-version "wit-bindgen") ensure-cargo-hyperlight +ensure-tools: (ensure-tool "wasm-tools" wasm-tools-version "wasm-tools") (ensure-tool "wit-bindgen-cli" wit-bindgen-version "wit-bindgen") ensure-cargo-hyperlight ensure-cargo-hyperlight: (ensure-tool "cargo-hyperlight" cargo-hyperlight-version "cargo hyperlight") @@ -56,19 +55,15 @@ build-pulley-rust-wasm-examples target=default-target features="": (mkdir-redist cargo run -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_latest" {"--wasmtime-version latest"} else {""} }} ./src/tests/rust_guests/rust_wasm_samples/target/wasm32-unknown-unknown/{{ target }}/rust_wasm_samples.wasm ./build/{{ target }}/rust_wasm_samples.aot build-rust-component-examples target=default-target features="": (compile-wit) - # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 - # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 rustup target add wasm32-unknown-unknown - cd ./src/tests/rust_guests/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + cd ./src/tests/rust_guests/component_sample && cargo build --profile={{ if target == "debug" {"dev"} else { target } }} cargo run -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_latest" {"--wasmtime-version latest"} else {""} }} --component ./src/tests/rust_guests/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./build/{{ target }}/component_sample.aot - cd ./src/tests/rust_guests/greeter_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + cd ./src/tests/rust_guests/greeter_sample && cargo build --profile={{ if target == "debug" {"dev"} else { target } }} cargo run -p hyperlight-wasm-aot compile {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_latest" {"--wasmtime-version latest"} else {""} }} --component ./src/tests/rust_guests/greeter_sample/target/wasm32-unknown-unknown/{{ target }}/greeter_sample.wasm ./build/{{ target }}/greeter_sample.aot build-pulley-rust-component-examples target=default-target features="": (compile-wit) - # use cargo component so we don't get all the wasi imports https://github.com/bytecodealliance/cargo-component?tab=readme-ov-file#relationship-with-wasm32-wasip2 - # we also explicitly target wasm32-unknown-unknown since cargo component might try to pull in wasi imports https://github.com/bytecodealliance/cargo-component/issues/290 rustup target add wasm32-unknown-unknown - cd ./src/tests/rust_guests/component_sample && cargo component build --target wasm32-unknown-unknown --profile={{ if target == "debug" {"dev"} else { target } }} + cd ./src/tests/rust_guests/component_sample && cargo build --profile={{ if target == "debug" {"dev"} else { target } }} cargo run -p hyperlight-wasm-aot compile --pulley {{ if features =~ "gdb" {"--debug"} else {""} }} {{ if features =~ "wasmtime_latest" {"--wasmtime-version latest"} else {""} }} --component ./src/tests/rust_guests/component_sample/target/wasm32-unknown-unknown/{{ target }}/component_sample.wasm ./build/{{ target }}/component_sample.aot check target=default-target: diff --git a/src/tests/rust_guests/component_sample/.cargo/config.toml b/src/tests/rust_guests/component_sample/.cargo/config.toml new file mode 100644 index 00000000..b28e6a90 --- /dev/null +++ b/src/tests/rust_guests/component_sample/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "wasm32-unknown-unknown" + +[target.wasm32-unknown-unknown] +linker = "wasm-component-ld" \ No newline at end of file diff --git a/src/tests/rust_guests/component_sample/Cargo.lock b/src/tests/rust_guests/component_sample/Cargo.lock index 739546d0..28ae6476 100644 --- a/src/tests/rust_guests/component_sample/Cargo.lock +++ b/src/tests/rust_guests/component_sample/Cargo.lock @@ -2,19 +2,254 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + [[package]] name = "bitflags" -version = "2.9.1" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "component_sample" version = "0.1.0" dependencies = [ + "wit-bindgen", "wit-bindgen-rt", ] +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "macro-string" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7b3a5bbb2f63aaa223a671ea1bd0e7bc16bd30ce387324cf63995deaddbbd2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "prettyplease" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "wasm-encoder" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4495a6f85dd94c411c749303efcbc5defade0b0cbdbc0541495241ab917a9b5a" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86ff6668190d9fb70372b306b4f9fe8930f0e2f57ce72e4922bf2f117900949" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "974d643b125b272607e2fff8012ea14a8328acd7621e4bafa7afb32500052b1b" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85a987ab61d365382d25c7d47e26edd48941b3bf6e3fbf76eff918bc71dab06" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e122e390603abfacd548027016cd0113a6e2bf2f8ce6bdd3658b013456ea8" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + [[package]] name = "wit-bindgen-rt" version = "0.44.0" @@ -23,3 +258,79 @@ checksum = "653c85dd7aee6fe6f4bded0d242406deadae9819029ce6f7d258c920c384358a" dependencies = [ "bitflags", ] + +[[package]] +name = "wit-bindgen-rust" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e26e13b9d972026778d2ffb7985736de116026fdc8d9464f966e12df2eb240" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a008a0d6b4840677326beb4edbeb210a2f1b7d0183fb7cc33f466b90fd7fb6" +dependencies = [ + "anyhow", + "macro-string", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078def49fdb49cab405c3006e05793b3fdaf7069126ba6b9c97d01ec8c98fe4c" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f0dc051466ffe46787721fca3d088536f158ae400be044f1b1c386ba9397ad" +dependencies = [ + "anyhow", + "hashbrown", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-ident", + "wasmparser", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/src/tests/rust_guests/component_sample/Cargo.toml b/src/tests/rust_guests/component_sample/Cargo.toml index 8f305af4..b3986a56 100644 --- a/src/tests/rust_guests/component_sample/Cargo.toml +++ b/src/tests/rust_guests/component_sample/Cargo.toml @@ -5,17 +5,9 @@ edition = "2024" [dependencies] wit-bindgen-rt = { version = "0.44.0", features = ["bitflags"] } +wit-bindgen = { version = "0.63.0" } [lib] crate-type = ["cdylib"] -[package.metadata.component] -package = "component-sample:example" - -[package.metadata.component.target] -path = "wit/example.wit" -world = "example" - -[package.metadata.component.target.dependencies] - [workspace] # indicate that this crate is not part of any workspace diff --git a/src/tests/rust_guests/component_sample/src/bindings.rs b/src/tests/rust_guests/component_sample/src/bindings.rs deleted file mode 100644 index de018616..00000000 --- a/src/tests/rust_guests/component_sample/src/bindings.rs +++ /dev/null @@ -1,306 +0,0 @@ -// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! -// Options used: -// * runtime_path: "wit_bindgen_rt" -#[rustfmt::skip] -#[allow(dead_code, clippy::all)] -pub mod component_sample { - pub mod example { - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod host { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - #[allow(unused_unsafe, clippy::all)] - pub fn print(message: &str) -> () { - unsafe { - let vec0 = message; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component-sample:example/host")] - unsafe extern "C" { - #[link_name = "print"] - fn wit_import1(_: *mut u8, _: usize); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: *mut u8, _: usize) { - unreachable!() - } - unsafe { wit_import1(ptr0.cast_mut(), len0) }; - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn host_function(input: &str) -> _rt::String { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - let vec0 = input; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component-sample:example/host")] - unsafe extern "C" { - #[link_name = "host-function"] - fn wit_import2(_: *mut u8, _: usize, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2(_: *mut u8, _: usize, _: *mut u8) { - unreachable!() - } - unsafe { wit_import2(ptr0.cast_mut(), len0, ptr1) }; - let l3 = *ptr1.add(0).cast::<*mut u8>(); - let l4 = *ptr1 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5); - let result6 = _rt::string_lift(bytes5); - result6 - } - } - } - } -} -#[rustfmt::skip] -#[allow(dead_code, clippy::all)] -pub mod exports { - pub mod component_sample { - pub mod example { - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod adder { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports; - use super::super::super::super::_rt; - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn _export_add_cabi(arg0: i32, arg1: i32) -> i32 { - #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); - let result0 = T::add(arg0 as u32, arg1 as u32); - _rt::as_i32(result0) - } - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn _export_call_host_cabi( - arg0: *mut u8, - arg1: usize, - ) -> *mut u8 { - #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); - let len0 = arg1; - let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0); - let result1 = T::call_host(_rt::string_lift(bytes0)); - let ptr2 = (&raw mut _RET_AREA.0).cast::(); - let vec3 = (result1.into_bytes()).into_boxed_slice(); - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - ::core::mem::forget(vec3); - *ptr2.add(::core::mem::size_of::<*const u8>()).cast::() = len3; - *ptr2.add(0).cast::<*mut u8>() = ptr3.cast_mut(); - ptr2 - } - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn __post_return_call_host(arg0: *mut u8) { - let l0 = *arg0.add(0).cast::<*mut u8>(); - let l1 = *arg0 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - _rt::cabi_dealloc(l0, l1, 1); - } - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn _export_do_something_cabi(arg0: i32) { - #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); - T::do_something(arg0 as u32); - } - pub trait Guest { - fn add(left: u32, right: u32) -> u32; - fn call_host(input: _rt::String) -> _rt::String; - fn do_something(number: u32) -> (); - } - #[doc(hidden)] - macro_rules! __export_component_sample_example_adder_cabi { - ($ty:ident with_types_in $($path_to_types:tt)*) => { - const _ : () = { #[unsafe (export_name = - "component-sample:example/adder#add")] unsafe extern "C" fn - export_add(arg0 : i32, arg1 : i32,) -> i32 { unsafe { - $($path_to_types)*:: _export_add_cabi::<$ty > (arg0, arg1) } } - #[unsafe (export_name = - "component-sample:example/adder#call-host")] unsafe extern "C" fn - export_call_host(arg0 : * mut u8, arg1 : usize,) -> * mut u8 { - unsafe { $($path_to_types)*:: _export_call_host_cabi::<$ty > - (arg0, arg1) } } #[unsafe (export_name = - "cabi_post_component-sample:example/adder#call-host")] unsafe - extern "C" fn _post_return_call_host(arg0 : * mut u8,) { unsafe { - $($path_to_types)*:: __post_return_call_host::<$ty > (arg0) } } - #[unsafe (export_name = - "component-sample:example/adder#do-something")] unsafe extern "C" - fn export_do_something(arg0 : i32,) { unsafe { - $($path_to_types)*:: _export_do_something_cabi::<$ty > (arg0) } } - }; - }; - } - #[doc(hidden)] - pub(crate) use __export_component_sample_example_adder_cabi; - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct _RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - static mut _RET_AREA: _RetArea = _RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - } - } - } -} -#[rustfmt::skip] -mod _rt { - #![allow(dead_code, clippy::all)] - pub use alloc_crate::string::String; - pub use alloc_crate::vec::Vec; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - String::from_utf8_unchecked(bytes) - } - } - #[cfg(target_arch = "wasm32")] - pub fn run_ctors_once() { - wit_bindgen_rt::run_ctors_once(); - } - pub fn as_i32(t: T) -> i32 { - t.as_i32() - } - pub trait AsI32 { - fn as_i32(self) -> i32; - } - impl<'a, T: Copy + AsI32> AsI32 for &'a T { - fn as_i32(self) -> i32 { - (*self).as_i32() - } - } - impl AsI32 for i32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for u32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for i16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for u16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for i8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for u8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for char { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - impl AsI32 for usize { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { - if size == 0 { - return; - } - let layout = alloc::Layout::from_size_align_unchecked(size, align); - alloc::dealloc(ptr, layout); - } - extern crate alloc as alloc_crate; - pub use alloc_crate::alloc; -} -/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as -/// the root implementation of all generated traits. -/// -/// For more information see the documentation of `wit_bindgen::generate!`. -/// -/// ```rust -/// # macro_rules! export{ ($($t:tt)*) => (); } -/// # trait Guest {} -/// struct MyType; -/// -/// impl Guest for MyType { -/// // ... -/// } -/// -/// export!(MyType); -/// ``` -#[allow(unused_macros)] -#[doc(hidden)] -macro_rules! __export_example_impl { - ($ty:ident) => { - self::export!($ty with_types_in self); - }; - ($ty:ident with_types_in $($path_to_types_root:tt)*) => { - $($path_to_types_root)*:: - exports::component_sample::example::adder::__export_component_sample_example_adder_cabi!($ty - with_types_in $($path_to_types_root)*:: - exports::component_sample::example::adder); - }; -} -#[doc(inline)] -pub(crate) use __export_example_impl as export; -#[cfg(target_arch = "wasm32")] -#[unsafe( - link_section = "component-type:wit-bindgen:0.41.0:component-sample:example:example:encoded world" -)] -#[doc(hidden)] -#[allow(clippy::octal_escapes)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 380] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xfe\x01\x01A\x02\x01\ -A\x04\x01B\x04\x01@\x01\x07messages\x01\0\x04\0\x05print\x01\0\x01@\x01\x05input\ -s\0s\x04\0\x0dhost-function\x01\x01\x03\0\x1dcomponent-sample:example/host\x05\0\ -\x01B\x06\x01@\x02\x04lefty\x05righty\0y\x04\0\x03add\x01\0\x01@\x01\x05inputs\0\ -s\x04\0\x09call-host\x01\x01\x01@\x01\x06numbery\x01\0\x04\0\x0cdo-something\x01\ -\x02\x04\0\x1ecomponent-sample:example/adder\x05\x01\x04\0\x20component-sample:e\ -xample/example\x04\0\x0b\x0d\x01\0\x07example\x03\0\0\0G\x09producers\x01\x0cpro\ -cessed-by\x02\x0dwit-component\x070.227.1\x10wit-bindgen-rust\x060.41.0"; -#[inline(never)] -#[doc(hidden)] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -} diff --git a/src/tests/rust_guests/component_sample/src/lib.rs b/src/tests/rust_guests/component_sample/src/lib.rs index 6d2a5079..d75d1c62 100644 --- a/src/tests/rust_guests/component_sample/src/lib.rs +++ b/src/tests/rust_guests/component_sample/src/lib.rs @@ -1,6 +1,10 @@ #[allow(warnings)] #[rustfmt::skip] -mod bindings; +mod bindings { + wit_bindgen::generate!({ + world: "example", + }); +} use bindings::component_sample::example::host::{host_function, print}; use bindings::exports::component_sample::example::adder::Guest; diff --git a/src/tests/rust_guests/greeter_sample/.cargo/config.toml b/src/tests/rust_guests/greeter_sample/.cargo/config.toml new file mode 100644 index 00000000..2aa7b03e --- /dev/null +++ b/src/tests/rust_guests/greeter_sample/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "wasm32-unknown-unknown" + +[target.wasm32-unknown-unknown] +linker = "wasm-component-ld" diff --git a/src/tests/rust_guests/greeter_sample/Cargo.lock b/src/tests/rust_guests/greeter_sample/Cargo.lock index cbc7a4af..95689274 100644 --- a/src/tests/rust_guests/greeter_sample/Cargo.lock +++ b/src/tests/rust_guests/greeter_sample/Cargo.lock @@ -2,19 +2,254 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + [[package]] name = "bitflags" -version = "2.11.0" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "foldhash" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "greeter_sample" version = "0.1.0" dependencies = [ + "wit-bindgen", "wit-bindgen-rt", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "macro-string" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7b3a5bbb2f63aaa223a671ea1bd0e7bc16bd30ce387324cf63995deaddbbd2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "prettyplease" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "wasm-encoder" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4495a6f85dd94c411c749303efcbc5defade0b0cbdbc0541495241ab917a9b5a" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c86ff6668190d9fb70372b306b4f9fe8930f0e2f57ce72e4922bf2f117900949" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "974d643b125b272607e2fff8012ea14a8328acd7621e4bafa7afb32500052b1b" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b85a987ab61d365382d25c7d47e26edd48941b3bf6e3fbf76eff918bc71dab06" +dependencies = [ + "bitflags", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e122e390603abfacd548027016cd0113a6e2bf2f8ce6bdd3658b013456ea8" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + [[package]] name = "wit-bindgen-rt" version = "0.44.0" @@ -23,3 +258,79 @@ checksum = "653c85dd7aee6fe6f4bded0d242406deadae9819029ce6f7d258c920c384358a" dependencies = [ "bitflags", ] + +[[package]] +name = "wit-bindgen-rust" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e26e13b9d972026778d2ffb7985736de116026fdc8d9464f966e12df2eb240" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a008a0d6b4840677326beb4edbeb210a2f1b7d0183fb7cc33f466b90fd7fb6" +dependencies = [ + "anyhow", + "macro-string", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078def49fdb49cab405c3006e05793b3fdaf7069126ba6b9c97d01ec8c98fe4c" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.262.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f0dc051466ffe46787721fca3d088536f158ae400be044f1b1c386ba9397ad" +dependencies = [ + "anyhow", + "hashbrown", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-ident", + "wasmparser", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/src/tests/rust_guests/greeter_sample/Cargo.toml b/src/tests/rust_guests/greeter_sample/Cargo.toml index 705ed01e..a2aa0b88 100644 --- a/src/tests/rust_guests/greeter_sample/Cargo.toml +++ b/src/tests/rust_guests/greeter_sample/Cargo.toml @@ -5,17 +5,9 @@ edition = "2024" [dependencies] wit-bindgen-rt = { version = "0.44.0", features = ["bitflags"] } +wit-bindgen = { version = "0.63.0" } [lib] crate-type = ["cdylib"] -[package.metadata.component] -package = "component-sample:example" - -[package.metadata.component.target] -path = "../component_sample/wit/example.wit" -world = "greeter-world" - -[package.metadata.component.target.dependencies] - [workspace] diff --git a/src/tests/rust_guests/greeter_sample/src/bindings.rs b/src/tests/rust_guests/greeter_sample/src/bindings.rs deleted file mode 100644 index 132963b1..00000000 --- a/src/tests/rust_guests/greeter_sample/src/bindings.rs +++ /dev/null @@ -1,222 +0,0 @@ -// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT! -// Options used: -// * runtime_path: "wit_bindgen_rt" -#[rustfmt::skip] -#[allow(dead_code, clippy::all)] -pub mod component_sample { - pub mod example { - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod host { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - #[allow(unused_unsafe, clippy::all)] - pub fn print(message: &str) -> () { - unsafe { - let vec0 = message; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component-sample:example/host")] - unsafe extern "C" { - #[link_name = "print"] - fn wit_import1(_: *mut u8, _: usize); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: *mut u8, _: usize) { - unreachable!() - } - unsafe { wit_import1(ptr0.cast_mut(), len0) }; - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn host_function(input: &str) -> _rt::String { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - let vec0 = input; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component-sample:example/host")] - unsafe extern "C" { - #[link_name = "host-function"] - fn wit_import2(_: *mut u8, _: usize, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2(_: *mut u8, _: usize, _: *mut u8) { - unreachable!() - } - unsafe { wit_import2(ptr0.cast_mut(), len0, ptr1) }; - let l3 = *ptr1.add(0).cast::<*mut u8>(); - let l4 = *ptr1 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5); - let result6 = _rt::string_lift(bytes5); - result6 - } - } - } - } -} -#[rustfmt::skip] -#[allow(dead_code, clippy::all)] -pub mod exports { - pub mod component_sample { - pub mod example { - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod greeter { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports; - use super::super::super::super::_rt; - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn _export_greet_cabi( - arg0: *mut u8, - arg1: usize, - ) -> *mut u8 { - #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); - let len0 = arg1; - let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0); - let result1 = T::greet(_rt::string_lift(bytes0)); - let ptr2 = (&raw mut _RET_AREA.0).cast::(); - let vec3 = (result1.into_bytes()).into_boxed_slice(); - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - ::core::mem::forget(vec3); - *ptr2.add(::core::mem::size_of::<*const u8>()).cast::() = len3; - *ptr2.add(0).cast::<*mut u8>() = ptr3.cast_mut(); - ptr2 - } - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn __post_return_greet(arg0: *mut u8) { - let l0 = *arg0.add(0).cast::<*mut u8>(); - let l1 = *arg0 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - _rt::cabi_dealloc(l0, l1, 1); - } - pub trait Guest { - fn greet(name: _rt::String) -> _rt::String; - } - #[doc(hidden)] - macro_rules! __export_component_sample_example_greeter_cabi { - ($ty:ident with_types_in $($path_to_types:tt)*) => { - const _ : () = { #[unsafe (export_name = - "component-sample:example/greeter#greet")] unsafe extern "C" fn - export_greet(arg0 : * mut u8, arg1 : usize,) -> * mut u8 { unsafe - { $($path_to_types)*:: _export_greet_cabi::<$ty > (arg0, arg1) } - } #[unsafe (export_name = - "cabi_post_component-sample:example/greeter#greet")] unsafe - extern "C" fn _post_return_greet(arg0 : * mut u8,) { unsafe { - $($path_to_types)*:: __post_return_greet::<$ty > (arg0) } } }; - }; - } - #[doc(hidden)] - pub(crate) use __export_component_sample_example_greeter_cabi; - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct _RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - static mut _RET_AREA: _RetArea = _RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - } - } - } -} -#[rustfmt::skip] -mod _rt { - #![allow(dead_code, clippy::all)] - pub use alloc_crate::string::String; - pub use alloc_crate::vec::Vec; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - String::from_utf8_unchecked(bytes) - } - } - #[cfg(target_arch = "wasm32")] - pub fn run_ctors_once() { - wit_bindgen_rt::run_ctors_once(); - } - pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { - if size == 0 { - return; - } - let layout = alloc::Layout::from_size_align_unchecked(size, align); - alloc::dealloc(ptr, layout); - } - extern crate alloc as alloc_crate; - pub use alloc_crate::alloc; -} -/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as -/// the root implementation of all generated traits. -/// -/// For more information see the documentation of `wit_bindgen::generate!`. -/// -/// ```rust -/// # macro_rules! export{ ($($t:tt)*) => (); } -/// # trait Guest {} -/// struct MyType; -/// -/// impl Guest for MyType { -/// // ... -/// } -/// -/// export!(MyType); -/// ``` -#[allow(unused_macros)] -#[doc(hidden)] -macro_rules! __export_greeter_world_impl { - ($ty:ident) => { - self::export!($ty with_types_in self); - }; - ($ty:ident with_types_in $($path_to_types_root:tt)*) => { - $($path_to_types_root)*:: - exports::component_sample::example::greeter::__export_component_sample_example_greeter_cabi!($ty - with_types_in $($path_to_types_root)*:: - exports::component_sample::example::greeter); - }; -} -#[doc(inline)] -pub(crate) use __export_greeter_world_impl as export; -#[cfg(target_arch = "wasm32")] -#[unsafe( - link_section = "component-type:wit-bindgen:0.41.0:component-sample:example:greeter-world:encoded world" -)] -#[doc(hidden)] -#[allow(clippy::octal_escapes)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 333] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc9\x01\x01A\x02\x01\ -A\x04\x01B\x04\x01@\x01\x07messages\x01\0\x04\0\x05print\x01\0\x01@\x01\x05input\ -s\0s\x04\0\x0dhost-function\x01\x01\x03\0\x1dcomponent-sample:example/host\x05\0\ -\x01B\x02\x01@\x01\x04names\0s\x04\0\x05greet\x01\0\x04\0\x20component-sample:ex\ -ample/greeter\x05\x01\x04\0&component-sample:example/greeter-world\x04\0\x0b\x13\ -\x01\0\x0dgreeter-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-c\ -omponent\x070.227.1\x10wit-bindgen-rust\x060.41.0"; -#[inline(never)] -#[doc(hidden)] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -} diff --git a/src/tests/rust_guests/greeter_sample/src/lib.rs b/src/tests/rust_guests/greeter_sample/src/lib.rs index b568e059..47a8b6e5 100644 --- a/src/tests/rust_guests/greeter_sample/src/lib.rs +++ b/src/tests/rust_guests/greeter_sample/src/lib.rs @@ -1,6 +1,11 @@ #[allow(warnings)] #[rustfmt::skip] -mod bindings; +mod bindings { + wit_bindgen::generate!({ + path: "../component_sample/wit/example.wit", + world: "greeter-world", + }); +} use bindings::component_sample::example::host::{host_function, print}; use bindings::exports::component_sample::example::greeter::Guest;