Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
a3s-libkrun-sys
FFI bindings to libkrun with Windows WHPX backend support.
Features
- ✅ Cross-platform: Linux (KVM), macOS (Hypervisor.framework), Windows (WHPX)
- ✅ Windows WHPX Backend: Full Windows Hypervisor Platform support
- ✅ virtiofs: Passthrough filesystem on all platforms
- ✅ virtio-net: Network device with TCP backend on Windows
- ✅ virtio-blk: Block device support
- ✅ virtio-console: Serial console
- ✅ TSI: Transparent Socket Impersonation for vsock
Platform Support
| Platform | Backend | Status |
|---|---|---|
| Linux x86_64 | KVM | ✅ Supported |
| Linux aarch64 | KVM | ✅ Supported |
| macOS arm64 | Hypervisor.framework | ✅ Supported |
| Windows x86_64 | WHPX | ✅ Supported |
Installation
Add to your Cargo.toml:
[]
= "3"
Windows Requirements
On Windows, you need to enable the Windows Hypervisor Platform:
# Run as Administrator
Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
# Reboot required
Restart-Computer
Verify it's enabled:
Get-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
Usage
use *;
use CString;
unsafe
Windows-Specific APIs
Network Device (TCP Backend)
unsafe
Block Device
unsafe
VSock with Named Pipes
unsafe
Examples
See the examples directory:
windows_vm_test.rs- Basic Windows VM testnginx_test.rs- Full nginx container test
Run examples:
# Windows
cargo run --example windows_vm_test --target x86_64-pc-windows-msvc
cargo run --example nginx_test --target x86_64-pc-windows-msvc
Building from Source
Linux and macOS
The build script compiles libkrun automatically when a compatible system or
cached library is unavailable. A recursive repository checkout uses the
vendor/libkrun submodule directly. Because Cargo does not package submodule
contents, the crates.io archive instead carries a deterministic,
checksum-verified vendor/libkrun-source.tar and extracts it under OUT_DIR.
Regenerate and verify that archive after changing the submodule with:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/package-libkrun-source.ps1
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/package-libkrun-source.ps1 -Check
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/package-libkrun-windows.ps1
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/package-libkrun-windows.ps1 -Check
Because libkrun invokes Cargo from inside the outer Cargo build, the nested process uses a target-local Cargo home next to the build outputs. That location is deliberately not configurable: reusing the outer package-cache lock can deadlock the nested build.
Windows
# Clone with submodules
git clone --recursive https://github.com/A3S-Lab/Box.git
cd Box/src/deps/libkrun-sys
# Build libkrun
cd vendor/libkrun
winget install --id zig.zig --exact --version 0.16.0
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/build-windows.ps1 -Packages libkrun
# Copy the runtime DLL and MSVC import library
Copy-Item target\x86_64-pc-windows-msvc\release\krun.dll ..\..\prebuilt\x86_64-pc-windows-msvc\
Copy-Item target\x86_64-pc-windows-msvc\release\krun.dll.lib ..\..\prebuilt\x86_64-pc-windows-msvc\krun.lib
# Run tests
cd ..\..
cargo test --target x86_64-pc-windows-msvc --lib -- --test-threads=1
The Windows runtime bundle is complete only when the prebuilt directory also
contains libkrunfw.dll. That companion DLL supplies the Linux guest kernel;
building krun.dll does not build a kernel. Repository and GitHub release
bundles contain all three files. The crates.io package carries the exact tested
trio in a checksum-pinned, deterministic vendor/krun-windows-x64.tar.xz.
That archive plus the reduced Unix source archive keeps the universal crate
below crates.io's 10 MiB limit without mixing runtime versions or requiring a
Windows build-time download.
The native files have additional license and source-delivery obligations; see
THIRD_PARTY_NOTICES.md and
SOURCE-PROVENANCE.md. The crate's MIT metadata covers
the A3S Rust wrapper and does not relicense the bundled native components.
The Windows build script always creates a real stripped Linux init/init
payload first and remaps host source/profile paths out of the Rust release
artifacts; the generated payload remains ignored by Git.
Windows virtiofs retains guest-created and guest-updated POSIX mode, UID, and GID values for the VM lifetime. A runtime that needs cross-generation persistence must capture these values before shutdown and replay them after boot; A3S Box performs that handoff with its rootfs metadata manifests.
Architecture
The Windows WHPX backend includes:
- WHPX VM/vCPU Management (
src/vmm/src/windows/vstate.rs,whpx_vcpu.rs) - virtio Devices:
virtio-fs- virtiofs passthrough (src/devices/src/virtio/fs/windows/)virtio-net- TCP backend (src/devices/src/virtio/net_windows.rs)virtio-blk- File-backed block device (src/devices/src/virtio/block_windows.rs)virtio-console- Serial console (src/devices/src/virtio/console_windows.rs)virtio-vsock- TSI implementation (src/devices/src/virtio/vsock/tsi/windows/)
- EventFd - Windows event wrapper (
src/utils/src/windows/eventfd.rs)
Testing
# All tests (Windows)
cargo test --target x86_64-pc-windows-msvc --lib -- --test-threads=1
# Specific test
cargo test --target x86_64-pc-windows-msvc --lib test_krun_create_ctx -- --test-threads=1
Note: Use --test-threads=1 on Windows due to WHPX partition limits.
Documentation
License
The A3S Rust wrapper is MIT licensed; see LICENSE. Bundled native components retain their own licenses and notices as documented in THIRD_PARTY_NOTICES.md.
Contributing
Contributions welcome! Please see CONTRIBUTING.md.
Credits
- Based on libkrun by Red Hat
- Windows WHPX backend by A3S Lab Team