Skip to content

Commit 9dca7a9

Browse files
RoyLinRoyLin
authored andcommitted
docs: add CLAUDE.md with project guidance for Claude Code
Add project-specific instructions and architecture documentation.
1 parent 4f9b231 commit 9dca7a9

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
libkrun is a dynamic library for running processes in a partially isolated environment using hardware virtualization (KVM on Linux, HVF on macOS ARM64, WHPX on Windows, Nitro Enclaves on AWS).
8+
9+
It exposes a stable C API defined in `include/libkrun.h` and integrates a VMM with minimal emulated devices for lightweight VMs.
10+
11+
**Version**: 1.17.5
12+
13+
## Build Commands
14+
15+
```bash
16+
# Build with default features
17+
make
18+
19+
# Build with specific features
20+
make BLK=1 NET=1 # virtio-block and virtio-net
21+
make GPU=1 # virtio-gpu (requires virglrenderer)
22+
make EFI=1 # EFI variant (macOS only)
23+
24+
# Build with TEE support
25+
make SEV=1 # AMD SEV
26+
make TDX=1 # Intel TDX
27+
make NITRO=1 # AWS Nitro Enclaves
28+
29+
# Install
30+
sudo make install
31+
32+
# Unit tests
33+
cargo test
34+
35+
# Integration tests
36+
make test
37+
cd tests && ./run.sh test
38+
```
39+
40+
## Architecture
41+
42+
### Multi-crate Workspace
43+
44+
The main crates in `src/` are:
45+
46+
| Crate | Purpose |
47+
|-------|---------|
48+
| `libkrun` | Public C API layer |
49+
| `vmm` | Core VMM: VM/vCPU lifecycle, memory, IRQ chip, platform backends |
50+
| `devices` | Virtio devices (block, net, console, fs, gpu, balloon, rng, snd, vsock) |
51+
| `arch` | Boot protocols and memory layout for x86_64, aarch64, riscv64 |
52+
| `kernel` | Kernel image loader (ELF, raw, PeGz, bz2, gz, zstd) |
53+
| `cpuid` | x86_64 CPUID leaf emulation |
54+
| `polly` | Epoll/event-manager abstraction for non-blocking IO |
55+
| `hvf` | Rust bindings to Apple Hypervisor.framework |
56+
| `nitro` | AWS Nitro Enclave support |
57+
| `rutabaga_gfx` | GPU virtualization (Venus Vulkan-over-virtio) |
58+
59+
### Key Entry Points
60+
61+
- **C API**: `src/libkrun/lib.rs` - exports functions from `include/libkrun.h`
62+
- **VM creation flow**: `krun_create_ctx()``krun_set_vm_config()``krun_start_enter()`
63+
- **Platform backends**: `src/vmm/src/platform/` - KVM, HVF, WHPX, Nitro implementations
64+
- **Guest init**: `init/` directory - C code that runs inside the VM
65+
66+
### Guest VM Lifecycle
67+
68+
1. Host creates VM context via C API
69+
2. Host configures kernel, rootfs, devices
70+
3. `krun_start_enter()` starts the VM and transitions execution to guest
71+
4. Guest runs `init/init.c` which launches the specified program
72+
73+
## Testing
74+
75+
Tests use a custom framework in `tests/test_cases/src/` where each test implements `start_vm()` (host-side) and `in_guest()` (guest-side) functions using `#[host]` and `#[guest]` macros. Register new tests in `test_cases()` function in `lib.rs`.
76+
77+
## Platform-Specific Notes
78+
79+
- **Linux**: Requires KVM kernel module; patchelf needed for install
80+
- **macOS**: Requires macOS 14+; HVF backend for ARM64
81+
- **Windows**: Requires WHPX and x86_64-pc-windows-msvc Rust target
82+
- **Build dependencies**: Rust toolchain, libkrunfw companion library

0 commit comments

Comments
 (0)