Skip to main content

Crate supermachine_kernel

Crate supermachine_kernel 

Source
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:

  1. Linux kernel image (KERNEL_BYTES) — ~29 MiB aarch64 Image format with the AF_TSI patch series applied.
  2. init-oci shim (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 future Image::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

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 Image format 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 in const contexts.
SUPERMACHINE_AGENT_BYTES
Raw bytes of the in-VM supermachine-agent binary (statically-linked aarch64-musl ELF, ~430 KiB). The CLI’s bake step copies this into the delta layer at /supermachine-agent; init-oci forks + exec’s it post-pivot to provide docker-style exec and other in-guest control RPCs over vsock.
SUPERMACHINE_AGENT_LEN
Length of the supermachine-agent binary in bytes.

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_to but mkdir -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 — use extract_kernel_to_with_parents if you’d rather mkdir -p.
extract_kernel_to_with_parents
Like extract_kernel_to but mkdir -p’s the parent dir first.
extract_supermachine_agent_to
Write the bundled supermachine-agent binary to dest. Sets it executable (mode 0o755) on Unix.
extract_supermachine_agent_to_with_parents
Like extract_supermachine_agent_to but mkdir -p’s the parent dir first.
extract_toDeprecated
Deprecated alias for extract_kernel_to. Will be removed in 0.2.
extract_to_with_parentsDeprecated
Deprecated alias for extract_kernel_to_with_parents.