pub trait Compiler: Sync + Send {
// Required methods
fn cache_key(&self) -> impl Hash + Send;
fn compile(
&self,
_layers: &[WasmLayer],
) -> impl Future<Output = Result<Vec<Option<Vec<u8>>>>> + Send;
}Required Methods§
Sourcefn cache_key(&self) -> impl Hash + Send
fn cache_key(&self) -> impl Hash + Send
cache_key returns a hasable type that will be used as a cache key for the precompiled module.
the return value should at least include the version of the shim running but could include other information such as a hash of the version and cpu type and other important information in the validation of being able to use precompiled module. If the hash doesn’t match then the module will be recompiled and cached with the new cache_key.
This hash will be used in the following way: “runwasi.io/precompiled/Shim::name()/<cache_key>”
Sourcefn compile(
&self,
_layers: &[WasmLayer],
) -> impl Future<Output = Result<Vec<Option<Vec<u8>>>>> + Send
fn compile( &self, _layers: &[WasmLayer], ) -> impl Future<Output = Result<Vec<Option<Vec<u8>>>>> + Send
compile passes supported OCI layers to engine for compilation.
This is used to precompile the layers before they are run.
It is called only the first time a module is run and the resulting bytes will be cached in the containerd content store.
The cached, precompiled layers will be reloaded on subsequent runs.
The runtime is expected to return the same number of layers passed in, if the layer cannot be precompiled it should return None for that layer.
In some edge cases it is possible that the layers may already be precompiled and None should be returned in this case.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.