Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Feb 22, 2024
1 parent 0a2d05d commit 6918e3e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
31 changes: 25 additions & 6 deletions wasm-rpc-stubgen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> {
if interface.global {
None
} else {
Some(&interface.name)
match &interface.owner_interface {
Some(owner) => Some(format!("{owner}/{}", &interface.name)),
None => Some(interface.name.clone()),
}
},
if interface.is_resource() {
FunctionMode::Method
Expand All @@ -102,7 +105,10 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> {
if interface.global {
None
} else {
Some(&interface.name)
match &interface.owner_interface {
Some(owner) => Some(format!("{owner}/{}", &interface.name)),
None => Some(interface.name.clone()),
}
},
FunctionMode::Static,
)?);
Expand All @@ -123,7 +129,11 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> {
generate_function_stub_source(
def,
&constructor_stub,
Some(&interface.name),
Some(format!(
"{}/{}",
interface.owner_interface.clone().unwrap_or_default(),
&interface.name
)),
FunctionMode::Constructor,
)?
} else {
Expand All @@ -146,7 +156,15 @@ pub fn generate_stub_source(def: &StubDefinition) -> anyhow::Result<()> {
});

if interface.is_resource() {
let remote_function_name = get_remote_function_name(def, "drop", Some(&interface.name));
let remote_function_name = get_remote_function_name(
def,
"drop",
Some(&format!(
"{}/{}",
interface.owner_interface.clone().unwrap_or_default(),
&interface.name
)),
);
interface_impls.push(quote! {
impl Drop for #interface_name {
fn drop(&mut self) {
Expand Down Expand Up @@ -198,7 +216,7 @@ enum FunctionMode {
fn generate_function_stub_source(
def: &StubDefinition,
function: &FunctionStub,
interface_name: Option<&String>,
interface_name: Option<String>,
mode: FunctionMode,
) -> anyhow::Result<TokenStream> {
let function_name = Ident::new(&to_rust_ident(&function.name), Span::call_site());
Expand Down Expand Up @@ -301,7 +319,8 @@ fn generate_function_stub_source(
}
}

let remote_function_name = get_remote_function_name(def, &function.name, interface_name);
let remote_function_name =
get_remote_function_name(def, &function.name, interface_name.as_ref());

let rpc = match mode {
FunctionMode::Static => {
Expand Down
6 changes: 5 additions & 1 deletion wasm-rpc-stubgen/src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub struct InterfaceStub {
pub static_functions: Vec<FunctionStub>,
pub imports: Vec<InterfaceStubImport>,
pub global: bool,
pub owner_interface: Option<String>,
}

impl InterfaceStub {
Expand Down Expand Up @@ -302,6 +303,7 @@ fn collect_stub_interfaces(resolve: &Resolve, world: &World) -> anyhow::Result<V
global: false,
constructor_params: None,
static_functions: vec![],
owner_interface: None,
});

interfaces.extend(resource_interfaces);
Expand All @@ -320,6 +322,7 @@ fn collect_stub_interfaces(resolve: &Resolve, world: &World) -> anyhow::Result<V
global: true,
constructor_params: None,
static_functions: vec![],
owner_interface: None,
});
}

Expand Down Expand Up @@ -432,12 +435,13 @@ fn collect_stub_resources<'a>(
.clone();

interfaces.push(InterfaceStub {
name: format!("{owner_interface}/{resource_name}"),
name: resource_name,
functions,
imports,
global: false,
constructor_params,
static_functions,
owner_interface: Some(owner_interface.to_string()),
});
}
TypeOwner::None => {}
Expand Down
2 changes: 1 addition & 1 deletion wasm-rpc/src/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub fn encode_output(
Ok(Value::Flags(encoded_value))
}
Val::Resource(resource) => {
let id = resource_store.add(resource.clone());
let id = resource_store.add(*resource);
Ok(Value::Handle {
uri: resource_store.self_uri(),
resource_id: id,
Expand Down

0 comments on commit 6918e3e

Please sign in to comment.