Skip to content

Commit

Permalink
add some compatibility casts, meshless res import fully functional
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Jul 26, 2024
1 parent a3128b7 commit 1dbfd83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
35 changes: 17 additions & 18 deletions crates/cpp/tests/meshless_resources/rust_comp_a/src/a.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated by `wit-bindgen` 0.27.0. DO NOT EDIT!
// Generated by `wit-bindgen` 0.28.0. DO NOT EDIT!
// Options used:
// * with "foo:foo/resources" = generate
#[allow(dead_code)]
pub mod foo {
#[allow(dead_code)]
Expand Down Expand Up @@ -28,12 +27,12 @@ pub mod foo {
}

#[doc(hidden)]
pub fn take_handle(&self) -> usize {
pub fn take_handle(&self) -> usize{
_rt::Resource::take_handle(&self.handle)
}

#[doc(hidden)]
pub fn handle(&self) -> usize {
pub fn handle(&self) -> usize{
_rt::Resource::handle(&self.handle)
}
}
Expand Down Expand Up @@ -62,24 +61,24 @@ pub mod foo {
#[link(wasm_import_module = "foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[constructor]r")]
fn fooX3AfooX2FresourcesX00X5BconstructorX5Dr(_: i32, ) -> usize;
fn fooX3AfooX2FresourcesX00X5BconstructorX5Dr(_: i32, ) -> *mut u8;
}
let ret = fooX3AfooX2FresourcesX00X5BconstructorX5Dr(_rt::as_i32(&a));
R::from_handle(ret)
R::from_handle(ret as usize)
}
}
}
impl R {
#[allow(unused_unsafe, clippy::all)]
pub fn add(&self,b: u32,){
pub fn add(&self,b: u32,) -> (){
unsafe {

#[link(wasm_import_module = "foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "[method]r.add")]
fn fooX3AfooX2FresourcesX00X5BmethodX5DrX2Eadd(_: usize, _: i32, );
fn fooX3AfooX2FresourcesX00X5BmethodX5DrX2Eadd(_: *mut u8, _: i32, );
}
fooX3AfooX2FresourcesX00X5BmethodX5DrX2Eadd((self).handle(), _rt::as_i32(&b));
fooX3AfooX2FresourcesX00X5BmethodX5DrX2Eadd((self).handle() as *mut u8, _rt::as_i32(&b));
}
}
}
Expand All @@ -90,23 +89,23 @@ pub mod foo {
#[link(wasm_import_module = "foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "create")]
fn fooX3AfooX2FresourcesX00create() -> usize;
fn fooX3AfooX2FresourcesX00create() -> *mut u8;
}
let ret = fooX3AfooX2FresourcesX00create();
R::from_handle(ret)
R::from_handle(ret as usize)
}
}
#[allow(unused_unsafe, clippy::all)]
/// borrows: func(o: borrow<r>);
pub fn consume(o: R,){
pub fn consume(o: R,) -> (){
unsafe {

#[link(wasm_import_module = "foo:foo/resources")]
extern "C" {
#[cfg_attr(target_arch = "wasm32", link_name = "consume")]
fn fooX3AfooX2FresourcesX00consume(_: usize, );
fn fooX3AfooX2FresourcesX00consume(_: *mut u8, );
}
fooX3AfooX2FresourcesX00consume((&o).take_handle());
fooX3AfooX2FresourcesX00consume((&o).take_handle() as *mut u8);
}
}

Expand Down Expand Up @@ -135,12 +134,12 @@ mod _rt {
/// resources.
#[repr(transparent)]
pub struct Resource<T: WasmResource> {
// NB: This would ideally be `u32` but it is not. The fact that this has
// NB: This would ideally be `usize` but it is not. The fact that this has
// interior mutability is not exposed in the API of this type except for the
// `take_handle` method which is supposed to in theory be private.
//
// This represents, almost all the time, a valid handle value. When it's
// invalid it's stored as `u32::MAX`.
// invalid it's stored as `0`.
handle: AtomicUsize,
_marker: marker::PhantomData<T>,
}
Expand Down Expand Up @@ -284,7 +283,7 @@ mod _rt {
}

#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.27.0:a:encoded world"]
#[link_section = "component-type:wit-bindgen:0.28.0:a:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 272] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x98\x01\x01A\x02\x01\
Expand All @@ -293,7 +292,7 @@ tor]r\x01\x02\x01h\0\x01@\x02\x04self\x03\x01by\x01\0\x04\0\x0d[method]r.add\x01
\x04\x01@\0\0\x01\x04\0\x06create\x01\x05\x01@\x01\x01o\x01\x01\0\x04\0\x07consu\
me\x01\x06\x03\x01\x11foo:foo/resources\x05\0\x04\x01\x09foo:foo/a\x04\0\x0b\x07\
\x01\0\x01a\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x07\
0.212.0\x10wit-bindgen-rust\x060.27.0";
0.214.0\x10wit-bindgen-rust\x060.28.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
6 changes: 3 additions & 3 deletions crates/rust/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
let result = format!(
"({op}).take_handle(){cast}",
cast = if self.gen.gen.opts.symmetric {
""
" as *mut u8"
} else {
" as i32"
}
Expand All @@ -439,7 +439,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
results.push(format!(
"({op}).handle(){cast}",
cast = if self.gen.gen.opts.symmetric {
""
" as *mut u8"
} else {
" as i32"
}
Expand All @@ -461,7 +461,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
format!(
"{name}::from_handle({op}{cast})",
cast = if self.gen.gen.opts.symmetric {
""
" as usize"
} else {
" as u32"
}
Expand Down

0 comments on commit 1dbfd83

Please sign in to comment.