mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 06:01:33 +00:00
do backend caching with a directory
This commit is contained in:
@ -37,31 +37,17 @@ impl From<io::Error> for Error {
|
||||
pub struct WasmHash([u8; 32], [u8; 32]);
|
||||
|
||||
impl WasmHash {
|
||||
/// Hash a wasm module for the default compiler backend.
|
||||
///
|
||||
/// See also: `WasmHash::generate_for_backend`.
|
||||
/// Hash a wasm module.
|
||||
///
|
||||
/// # Note:
|
||||
/// This does no verification that the supplied data
|
||||
/// is, in fact, a wasm module.
|
||||
pub fn generate(wasm: &[u8]) -> Self {
|
||||
WasmHash::generate_for_backend(wasm, Backend::default())
|
||||
}
|
||||
|
||||
/// Hash a wasm module for a specific compiler backend.
|
||||
/// This allows multiple cache entries containing the same compiled
|
||||
/// module with different compiler backends.
|
||||
///
|
||||
/// # Note:
|
||||
/// This function also does no verification that the supplied data
|
||||
/// is a wasm module
|
||||
pub fn generate_for_backend(wasm: &[u8], backend: Backend) -> Self {
|
||||
let mut first_part = [0u8; 32];
|
||||
let mut second_part = [0u8; 32];
|
||||
|
||||
let mut state = blake2bp::State::new();
|
||||
state.update(wasm);
|
||||
state.update(backend.to_string().as_bytes());
|
||||
|
||||
let hasher = state.finalize();
|
||||
let generic_array = hasher.as_bytes();
|
||||
@ -243,7 +229,11 @@ pub trait Cache {
|
||||
type LoadError: fmt::Debug;
|
||||
type StoreError: fmt::Debug;
|
||||
|
||||
/// loads a module using the default `Backend`
|
||||
fn load(&self, key: WasmHash) -> Result<Module, Self::LoadError>;
|
||||
/// loads a cached module using a specific `Backend`
|
||||
fn load_with_backend(&self, key: WasmHash, backend: Backend)
|
||||
-> Result<Module, Self::LoadError>;
|
||||
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::StoreError>;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user