supermachine 0.7.108

Run any OCI/Docker image as a hardware-isolated microVM on macOS HVF (Linux KVM and Windows WHP in progress). Single library API, zero flags for the common case, sub-100 ms cold-restore from snapshot.
Documentation
#[cfg(any(
    all(target_os = "linux", target_arch = "x86_64"),
    all(target_os = "macos", target_arch = "aarch64")
))]
mod supported {
    //! Smoke-test that smpark.ko loads on boot.
    //!
    //! Bakes a fresh `rust:1-slim` image with smpark.ko staged at
    //! `/supermachine-smpark.ko`. init-oci `finit_module`s it before
    //! starting the user workload. After acquire, we read
    //! `/proc/modules` from inside the guest to verify the module is
    //! loaded.
    //!
    //! Smoke level only — proves the load path works on a 1-vCPU
    //! guest (where the module no-ops). Doesn't drive park/unpark or
    //! validate multi-vCPU snapshots — those are the next steps.

    use std::time::Duration;
    use supermachine::Image;

    pub(super) fn main() -> Result<(), Box<dyn std::error::Error>> {
        let park_ko = std::path::PathBuf::from("docs/design/extras/smpark/smpark.ko");
        if !park_ko.is_file() {
            eprintln!("smpark.ko not found at {}", park_ko.display());
            std::process::exit(1);
        }

        eprintln!("[smpark-smoke] baking with smpark.ko staged...");
        let image = Image::builder("rust:1-slim")
            .with_name("rust_1_slim_smpark")
            .with_memory_mib(512)
            .with_extra_file(&park_ko, "/supermachine-smpark.ko")
            .build()?;

        eprintln!("[smpark-smoke] acquiring + checking /proc/modules...");
        let pool = image.pool().min(1).max(1).build()?;
        let vm = pool.acquire()?;
        let out = vm
            .exec_builder()
            .argv(["sh", "-c", "cat /proc/modules || true"])
            .timeout(Duration::from_secs(5))
            .output()?;
        let stdout = String::from_utf8_lossy(&out.stdout);
        eprintln!("[smpark-smoke] /proc/modules output:\n{stdout}");

        if stdout.contains("smpark") {
            eprintln!("[smpark-smoke] SUCCESS: smpark loaded");
        } else {
            eprintln!("[smpark-smoke] FAIL: smpark not in /proc/modules");
            std::process::exit(2);
        }
        Ok(())
    }
}

#[cfg(any(
    all(target_os = "linux", target_arch = "x86_64"),
    all(target_os = "macos", target_arch = "aarch64")
))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    supported::main()
}

#[cfg(not(any(
    all(target_os = "linux", target_arch = "x86_64"),
    all(target_os = "macos", target_arch = "aarch64")
)))]
fn main() -> Result<(), Box<dyn std::error::Error>> {
    eprintln!("this example requires a linux-x86_64 (KVM) or macos-aarch64 (HVF) host; unsupported on this platform");
    Ok(())
}