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 {
    //! Time how fast `image.acquire()` returns when the hidden pool
    //! is warm. Compare first-acquire (cold pool init) vs subsequent
    //! acquires (snapshot restore only).

    use std::time::Instant;
    use supermachine::Image;

    pub(super) fn main() -> Result<(), Box<dyn std::error::Error>> {
        let snap = format!(
            "{}/.local/supermachine-snapshots/nginx_1_27-alpine",
            std::env::var("HOME").unwrap()
        );
        let image = Image::from_snapshot(&snap)?;

        let n = 10;
        let mut elapsed = Vec::with_capacity(n);
        for i in 0..n {
            let t0 = Instant::now();
            {
                let vm = image.acquire()?;
                // Confirm the VM is actually live by running a tiny exec.
                let out = vm.exec_builder().argv(["true"]).output()?;
                assert!(out.success(), "true exited with {:?}", out.status.code());
            }
            let dt = t0.elapsed();
            elapsed.push(dt);
            println!("acquire {i:2}: {dt:?}");
        }

        let cold = elapsed[0];
        let warm: std::time::Duration =
            elapsed[1..].iter().sum::<std::time::Duration>() / (n as u32 - 1);
        println!("\ncold-pool first acquire:  {cold:?}");
        println!("warm-pool subsequent (avg): {warm:?}");

        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(())
}