This commit fixes the `wasmtime::Instance` instantiation API when imports have the same name but might be imported under different types. This is handled in the API by listing imports as a list instead of as a name map, but they were interpreted as a name map under the hood causing collisions. This commit now keeps track of the index used to define each import, and the index is passed through in the `Resolver`. Existing implementaitons of `Resolver` all ignore this, but the API now uses it exclusivley to match up `Extern` definitions to imports.
27 lines
929 B
Rust
27 lines
929 B
Rust
//! Define the `Resolver` trait, allowing custom resolution for external
|
|
//! references.
|
|
|
|
use wasmtime_runtime::Export;
|
|
|
|
/// Import resolver connects imports with available exported values.
|
|
pub trait Resolver {
|
|
/// Resolves an import a WebAssembly module to an export it's hooked up to.
|
|
///
|
|
/// The `index` provided is the index of the import in the wasm module
|
|
/// that's being resolved. For example 1 means that it's the second import
|
|
/// listed in the wasm module.
|
|
///
|
|
/// The `module` and `field` arguments provided are the module/field names
|
|
/// listed on the import itself.
|
|
fn resolve(&mut self, index: u32, module: &str, field: &str) -> Option<Export>;
|
|
}
|
|
|
|
/// `Resolver` implementation that always resolves to `None`.
|
|
pub struct NullResolver {}
|
|
|
|
impl Resolver for NullResolver {
|
|
fn resolve(&mut self, _idx: u32, _module: &str, _field: &str) -> Option<Export> {
|
|
None
|
|
}
|
|
}
|