Skip to content

Commit

Permalink
Add ability to pre-compile modules in wasmtime
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant committed Dec 1, 2023
1 parent df454fd commit 4c01e11
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 42 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/containerd-shim-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ttrpc = { workspace = true }
wat = { workspace = true }
tokio = { version = "1.34.0", features = [ "full" ] }
futures = { version = "0.3.29" }
tokio-stream = { version = "0.1" }
prost-types = "0.11" # should match version in containerd-shim
sha256 = "1.4.0"

[target.'cfg(unix)'.dependencies]
caps = "0.5"
Expand Down
4 changes: 4 additions & 0 deletions crates/containerd-shim-wasm/src/container/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum Source<'a> {
// and they will be included in this array, e.g., a `toml` file with the
// runtime configuration.
Oci(&'a [WasmLayer]),
Precompiled(&'a WasmLayer),
}

/// The entrypoint for a WASI module / component.
Expand Down Expand Up @@ -79,6 +80,8 @@ impl RuntimeContext for WasiContext<'_> {

let source = if self.wasm_layers.is_empty() {
Source::File(PathBuf::from(path))
} else if self.wasm_layers.len() == 1 && self.wasm_layers[0].precompiled {
Source::Precompiled(&self.wasm_layers[0])
} else {
Source::Oci(self.wasm_layers)
};
Expand Down Expand Up @@ -337,6 +340,7 @@ mod tests {
wasm_layers: &[WasmLayer {
layer: vec![],
config: Descriptor::new(oci_spec::image::MediaType::Other("".to_string()), 10, ""),
precompiled: false,
}],
platform: &Platform::default(),
};
Expand Down
13 changes: 12 additions & 1 deletion crates/containerd-shim-wasm/src/container/engine.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::Read;

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};

use super::Source;
use crate::container::{PathResolve, RuntimeContext};
Expand All @@ -26,6 +26,7 @@ pub trait Engine: Clone + Send + Sync + 'static {
let path = match source {
Source::File(path) => path,
Source::Oci(_) => return Ok(()),
Source::Precompiled(_) => return Ok(()),
};

path.resolve_in_path_or_cwd()
Expand All @@ -52,4 +53,14 @@ pub trait Engine: Clone + Send + Sync + 'static {
fn supported_layers_types() -> &'static [&'static str] {
&["application/vnd.bytecodealliance.wasm.component.layer.v0+wasm"]
}

/// Precomiple a module
fn precompile(&self, _layers: &[Vec<u8>]) -> Result<Vec<u8>> {
bail!("precompilation not supported for this runtime")
}

/// Precomiple a module
fn can_precompile() -> bool {
false
}
}
Loading

0 comments on commit 4c01e11

Please sign in to comment.