Skip to content

Ability to get and load compilation result bytes #1779

@dsherret

Description

@dsherret

Feature

It would be useful to be able to get the bytes from a compilation result and additionally take bytes from a previous compilation and load them into a module.

Benefit

This would allow me to manage my own caching and reduce startup times.

Implementation

Here's how it's done in wasmer.

Compiling:

let compile_result = wasmer_runtime::compile(&wasm_bytes)?;
let artifact = compile_result.cache();
let compiled_module_bytes = artifact.unwrap().serialize().unwrap();

Loading:

let artifact = match wasmer_runtime::cache::Artifact::deserialize(&compiled_module_bytes) {
    Ok(artifact) => artifact,
    Err(err) => { return err!("Error deserializing compiled wasm module: {:?}", err); }
};
let compiler = wasmer_runtime::compiler_for_backend(wasmer_runtime::Backend::default()).expect("Expected to have a compiler");
let module = unsafe { wasmer_runtime_core::load_cache_with(artifact, &*compiler).unwrap() };
let import_object = wasmer_runtime::imports! {};
let instance = module.instantiate(&import_object)?;

Alternatives

Using the Config::cache_config_load_default is not ideal because it's wasmtime managing a cache for me and it seems I need to keep the .wasm file bytes around.

Metadata

Metadata

Assignees

Labels

wasmtime:apiRelated to the API of the `wasmtime` crate itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions