Skip to content

Commit

Permalink
fix native Rust code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Apr 5, 2024
1 parent 60fb4f8 commit c1fc7e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 79 deletions.
56 changes: 27 additions & 29 deletions crates/cpp/tests/native_resources/rust/Cargo.lock

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

38 changes: 17 additions & 21 deletions crates/cpp/tests/native_resources/rust/src/the_world.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by `wit-bindgen` 0.23.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT!
// Options used:
#[allow(dead_code)]
pub mod foo {
Expand Down Expand Up @@ -294,7 +294,7 @@ pub mod exports {
}
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn _export_borrows_cabi<T: Guest>(arg0: *mut u8,) {#[cfg(target_arch="wasm32")]
pub unsafe fn _export_borrows_cabi<T: Guest>(arg0: *const u8,) {#[cfg(target_arch="wasm32")]
_rt::run_ctors_once();T::borrows(RBorrow::lift(arg0 as usize));
}
#[doc(hidden)]
Expand All @@ -314,29 +314,25 @@ pub trait GuestR: 'static {
unsafe fn _resource_new(val: *mut u8) -> u32
where Self: Sized
{
{
#[link(wasm_import_module = "[export]foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-new]r")]
fn X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_newX5Dr(_: *mut u8) -> u32;
}
X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_newX5Dr(val)
#[link(wasm_import_module = "[export]foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-new]r")]
fn X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_newX5Dr(_: *mut u8) -> u32;
}
X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_newX5Dr(val)
}

#[doc(hidden)]
fn _resource_rep(handle: u32) -> *mut u8
where Self: Sized
{
{
#[link(wasm_import_module = "[export]foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-rep]r")]
fn X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_repX5Dr(_: u32) -> *mut u8;
}
unsafe {
X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_repX5Dr(handle)
}
#[link(wasm_import_module = "[export]foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-rep]r")]
fn X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_repX5Dr(_: u32) -> *mut u8;
}
unsafe {
X5BexportX5DfooX3AfooX2FresourcesX00X5Bresource_repX5Dr(handle)
}
}

Expand Down Expand Up @@ -366,7 +362,7 @@ macro_rules! __export_foo_foo_resources_cabi{
}
#[cfg_attr(target_arch = "wasm32", export_name = "foo:foo/resources#borrows")]
#[cfg_attr(not(target_arch = "wasm32"), no_mangle)]
unsafe extern "C" fn fooX3AfooX2FresourcesX23borrows(arg0: *mut u8,) {
unsafe extern "C" fn fooX3AfooX2FresourcesX23borrows(arg0: *const u8,) {
$($path_to_types)*::_export_borrows_cabi::<$ty>(arg0)
}
#[cfg_attr(target_arch = "wasm32", export_name = "foo:foo/resources#consume")]
Expand Down Expand Up @@ -601,7 +597,7 @@ macro_rules! __export_the_world_impl {
pub(crate) use __export_the_world_impl as export;

#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.23.0:the-world:encoded world"]
#[link_section = "component-type:wit-bindgen:0.24.0:the-world:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 460] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xcc\x02\x01A\x02\x01\
Expand All @@ -615,7 +611,7 @@ r.add\x01\x04\x01@\0\0\x01\x04\0\x06create\x01\x05\x01@\x01\x01o\x03\x01\0\x04\0
\x07borrows\x01\x06\x01@\x01\x01o\x01\x01\0\x04\0\x07consume\x01\x07\x04\x01\x11\
foo:foo/resources\x05\x01\x04\x01\x11foo:foo/the-world\x04\0\x0b\x0f\x01\0\x09th\
e-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.20\
2.0\x10wit-bindgen-rust\x060.23.0";
2.0\x10wit-bindgen-rust\x060.24.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
40 changes: 11 additions & 29 deletions crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,43 +218,25 @@ impl InterfaceGenerator<'_> {
unsafe fn _resource_new(val: *mut u8) -> u32
where Self: Sized
{{
#[cfg(not(target_arch = "wasm32"))]
{{
let _ = val;
unreachable!();
}}
#[cfg(target_arch = "wasm32")]
{{
#[link(wasm_import_module = "[export]{module}")]
extern "C" {{
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-new]{resource_name}")]
fn {external_new}(_: *mut u8) -> u32;
}}
{external_new}(val)
#[link(wasm_import_module = "[export]{module}")]
extern "C" {{
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-new]{resource_name}")]
fn {external_new}(_: *mut u8) -> u32;
}}
{external_new}(val)
}}
#[doc(hidden)]
fn _resource_rep(handle: u32) -> *mut u8
where Self: Sized
{{
#[cfg(not(target_arch = "wasm32"))]
{{
let _ = handle;
unreachable!();
#[link(wasm_import_module = "[export]{module}")]
extern "C" {{
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-rep]{resource_name}")]
fn {external_rep}(_: u32) -> *mut u8;
}}
#[cfg(target_arch = "wasm32")]
{{
#[link(wasm_import_module = "[export]{module}")]
extern "C" {{
#[cfg_attr(target_arch = "wasm32", link_name = "[resource-rep]{resource_name}")]
fn {external_rep}(_: u32) -> *mut u8;
}}
unsafe {{
{external_rep}(handle)
}}
unsafe {{
{external_rep}(handle)
}}
}}
Expand Down

0 comments on commit c1fc7e2

Please sign in to comment.