Skip to content

Commit

Permalink
chore: use extism:user namespace by default for user-defined host fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
zshipko committed Oct 16, 2023
1 parent d472b8a commit bc3afd7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ pub fn plugin_fn(
/// `host_fn` is used to define a host function that will be callable from within a plugin
#[proc_macro_attribute]
pub fn host_fn(
_attr: proc_macro::TokenStream,
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let mut namespace = attr.to_string();
if namespace.is_empty() {
namespace = "extism:user".to_string();
}

let item = parse_macro_input!(item as ItemForeignMod);
if item.abi.name.is_none() || item.abi.name.unwrap().value() != "ExtismHost" {
panic!("Expected `extern \"ExtismHost\"` block");
Expand Down Expand Up @@ -209,7 +214,7 @@ pub fn host_fn(
let link_name = link_name.as_str();

let impl_block = quote! {
#[link(wasm_import_module = "extism:env")]
#[link(wasm_import_module = #namespace)]
extern "C" {
#[link_name = #link_name]
fn #impl_name(#(#converted_inputs),*) -> #converted_output;
Expand Down
Binary file modified test/code.wasm
Binary file not shown.
Binary file modified test/host_function.wasm
Binary file not shown.
Binary file modified test/http.wasm
Binary file not shown.

0 comments on commit bc3afd7

Please sign in to comment.