Add missing import to wasmtime-rust macro (#589)
This commit does two things: 1) it fixes `wasmtime_rust::wasmtime` proc macro by adding the missing import to the `__rt` module, and fixing the scoping inside the macro itself; and 2) it augments the `wasmtime_rust::wasmtime` proc macro with custom error messages in case the implementor forgets the `self` argument in the trait methods.
This commit is contained in:
committed by
Alex Crichton
parent
a2479df329
commit
9182971697
@@ -66,7 +66,7 @@ fn generate_load(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
||||
|
||||
let mut imports: Vec<Extern> = Vec::new();
|
||||
if let Some(module_name) = data.find_wasi_module_name() {
|
||||
let wasi_instance = wasmtime_wasi::create_wasi_instance(&store, &[], &[], &[])
|
||||
let wasi_instance = #root::wasmtime_wasi::create_wasi_instance(&store, &[], &[], &[])
|
||||
.map_err(|e| format_err!("wasm instantiation error: {:?}", e))?;
|
||||
for i in module.borrow().imports().iter() {
|
||||
if i.module().as_str() != module_name {
|
||||
@@ -112,6 +112,14 @@ fn generate_methods(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
||||
if let Some(t) = &method.sig.asyncness {
|
||||
bail!(t, "cannot be `async`");
|
||||
}
|
||||
match &method.sig.inputs.first() {
|
||||
Some(syn::FnArg::Receiver(_)) => {}
|
||||
Some(t) => bail!(t, "first arugment needs to be \"self\""),
|
||||
None => bail!(
|
||||
method.sig,
|
||||
"trait method requires at least one argument which needs to be \"self\""
|
||||
),
|
||||
}
|
||||
|
||||
let mut args = Vec::new();
|
||||
for arg in method.sig.inputs.iter() {
|
||||
|
||||
@@ -7,6 +7,7 @@ pub mod __rt {
|
||||
pub use wasmtime_api;
|
||||
pub use wasmtime_interface_types;
|
||||
pub use wasmtime_jit;
|
||||
pub use wasmtime_wasi;
|
||||
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use wasmtime_interface_types::Value;
|
||||
|
||||
Reference in New Issue
Block a user