Expand description
Pre-built runtime assets for supermachine, packaged as a Rust
crate so embedders can cargo add supermachine-kernel instead
of fetching binaries out-of-band.
Two assets are bundled:
- Linux kernel image (
KERNEL_BYTES) — ~29 MiB aarch64Imageformat with the AF_TSI patch series applied. init-ocishim (INIT_OCI_BYTES) — ~1.6 MiB statically linked aarch64-musl binary. PID 1 inside each microVM. Sets up overlayfs, mounts /proc + /dev, exec’s the customer’s image entrypoint. Only needed if you bake images at runtime (i.e. via the futureImage::from_oci(...)API); restoring a snapshot doesn’t need it.
Versioned in lockstep with the supermachine library — pin
both to the same version.
§Use cases
§From a build.rs (recommended for .app bundles)
Pre-stage the assets into your bundle’s Resources at build time
so the resulting .app is self-contained:
// build.rs
fn main() {
let resources = std::path::PathBuf::from(
std::env::var("OUT_DIR").unwrap()
).join("../../../bundle-resources");
std::fs::create_dir_all(&resources).unwrap();
supermachine_kernel::extract_kernel_to(&resources.join("kernel")).unwrap();
supermachine_kernel::extract_init_oci_to(&resources.join("init-oci")).unwrap();
}§From runtime code
Extract once on first start to a writable scratch dir:
use std::path::PathBuf;
fn ensure_assets() -> std::io::Result<PathBuf> {
let dir = std::env::temp_dir().join("supermachine-assets");
std::fs::create_dir_all(&dir)?;
supermachine_kernel::extract_kernel_to(&dir.join("kernel"))?;
supermachine_kernel::extract_init_oci_to(&dir.join("init-oci"))?;
Ok(dir)
}Then point supermachine::AssetPaths::from_dir at the result.
Constants§
- INIT_
OCI_ BYTES - Raw bytes of the in-VM init shim (statically-linked aarch64-musl ELF executable, ~1.6 MiB). The CLI’s bake step copies this into the guest’s initramfs as PID 1; it sets up overlayfs, mounts /proc + /dev, then exec’s the OCI image’s entrypoint.
- INIT_
OCI_ LEN - Length of the init-oci binary in bytes.
- KERNEL_
BYTES - Raw bytes of the kernel image — an aarch64 Linux
Imageformat binary (raw kernel, no ELF wrapper). About 29 MiB. - KERNEL_
LEN - Length of the kernel image in bytes — equivalent to
KERNEL_BYTES.len()but evaluable inconstcontexts.
Functions§
- extract_
init_ oci_ to - Write the bundled init-oci binary to
dest. Sets it executable (mode 0o755) on Unix. - extract_
init_ oci_ to_ with_ parents - Like
extract_init_oci_tobutmkdir -p’s the parent dir first. - extract_
kernel_ to - Write the bundled kernel image to
dest. Overwrites any existing file. Caller is responsible for the parent dir existing — useextract_kernel_to_with_parentsif you’d rather mkdir -p. - extract_
kernel_ to_ with_ parents - Like
extract_kernel_tobutmkdir -p’s the parent dir first. - extract_
to Deprecated - Deprecated alias for
extract_kernel_to. Will be removed in 0.2. - extract_
to_ with_ parents Deprecated - Deprecated alias for
extract_kernel_to_with_parents.