# 1. Build the engine (first time takes 5-10 minutes)
yarn rust:build
# 2. Run with test scene (shows colored materials)
yarn rust:engine --scene MaterialTest
# 3. Run with default scene
yarn rust:engine --scene Default
# 4. Run tests to verify everything works
yarn rust:test| Command | Description | Speed |
|---|---|---|
yarn rust:engine --scene <name> |
Run the engine with a scene | Instant |
yarn rust:build |
Build the engine | 1-5s incremental |
yarn rust:test |
Run all unit tests (24 tests) | ~1s |
yarn rust:export-schemas |
Export TS schemas to Rust | ~1s |
# Basic usage
yarn rust:engine --scene MaterialTest
# Custom window size
yarn rust:engine --scene Default --width 1920 --height 1080
# All options
yarn rust:engine --scene <SceneName> --width <pixels> --height <pixels>Controls:
ESC- Close window- No camera controls yet (coming soon)
# 1. Edit Rust code in rust/engine/src/
# 2. Build (only changed files recompile - usually 1-5 seconds)
yarn rust:build
# 3. Run to test
yarn rust:engine --scene MaterialTest
# 4. Run tests if you changed logic
yarn rust:test# Just check for errors (doesn't produce binary, but much faster)
cd rust/engine && cargo checkClean build times:
- Dev (default): ~2 minutes - Optimized for iteration ⚡
- Dev-debug: ~1 minute - Full debug symbols (for gdb/lldb)
- Release: ~1.6 minutes - Performance optimized
- Dist: ~2+ minutes - Size optimized with LTO
Incremental builds:
- Only changed files recompile
- Usually 1-15 seconds depending on changes
Build profiles:
dev(default) - Fast runtime + small binary (30 MB) - Use this 90% of the timedev-debug- Full debug info (325 MB) - Only when debugging with gdb/lldbrelease- Standard release build (22 MB)dist- Optimized for distribution (smallest size + LTO)
Why is dev optimized?
Following Bevy's recommended setup, the default dev profile uses opt-level = 1 for your code and opt-level = 3 for dependencies. This gives you:
- ✅ Fast compilation (2 min clean, <15s incremental)
- ✅ Good runtime performance (not sluggish like opt-level=0)
- ✅ Small binaries (30 MB vs 325 MB)
- ✅ Fast startup times
Feature presets:
# See all features and presets
cargo run -p xtask -- feature-matrix
# Build with minimal features (renderer only)
cargo build --no-default-features --features renderer
# Build for distribution
cargo build --profile dist
# Full debug build (only when you need gdb/lldb)
cargo build --profile dev-debugBuild metrics:
# Capture detailed build metrics
cargo run -p xtask -- build-metrics --profile dev-fast
# Generate size report
cargo run -p xtask -- size-report
# CI-optimized build with caching
./scripts/ci/rust-build-metrics.sh- Rust uses incremental compilation automatically
Tips to speed up builds:
- Install
moldlinker:sudo apt install mold(2-3x faster linking) - Use
cargo checkfor quick error checking - Use
cargo watchfor auto-rebuild on file save
Scenes are JSON files in rust/game/scenes/:
Default.json- Basic test sceneMaterialTest.json- Shows material colors (red cube, green sphere, blue cube)
Create your own:
{
"metadata": {
"name": "My Scene",
"version": 1,
"timestamp": "2025-10-14T00:00:00.000Z"
},
"entities": [
{
"name": "Red Cube",
"components": {
"Transform": {
"position": [0, 0, 0],
"rotation": [0, 0, 0, 1],
"scale": [1, 1, 1]
},
"MeshRenderer": {
"meshId": "cube",
"materialId": "red-material"
}
}
}
],
"materials": [
{
"id": "red-material",
"color": "#ff0000",
"metallic": 0.5,
"roughness": 0.3
}
]
}✅ Scene loading from JSON ✅ Entity Component System (Transform, MeshRenderer, Camera) ✅ Material system (PBR: color, metallic, roughness) ✅ Camera component parsing from scenes ✅ Basic PBR lighting ✅ Primitive meshes (cube, sphere, plane) ✅ 24 unit tests with full coverage
- Check file exists:
rust/game/scenes/<SceneName>.json - Scene names are case-sensitive
- No
.jsonextension in the command
cd rust/engine
rm -rf target
yarn rust:build- First build is always slow (compiling dependencies)
- If every build is slow, check if
target/directory is being deleted - Incremental builds should be 1-5 seconds
rust/engine/
├── src/
│ ├── main.rs # CLI entrypoint
│ ├── app.rs # Main application loop
│ ├── io/loader.rs # Scene JSON loading
│ ├── ecs/
│ │ ├── scene.rs # SceneData, Entity, Metadata
│ │ └── components/ # Transform, MeshRenderer, Camera
│ ├── render/
│ │ ├── renderer.rs # wgpu initialization
│ │ ├── material.rs # Material, MaterialCache
│ │ ├── camera.rs # Camera view/projection
│ │ ├── shader.wgsl # GPU shader (PBR lighting)
│ │ ├── pipeline.rs # Render pipeline, InstanceRaw
│ │ ├── scene_renderer.rs # Scene → GPU rendering
│ │ └── primitives.rs # Cube, sphere, plane meshes
│ └── util/time.rs # FPS counter
├── Cargo.toml # Dependencies
└── .cargo/config.toml # Build optimizations
rust/game/
├── scenes/ # Scene JSON files
└── schema/ # TypeScript → Rust schema exports
# See detailed logs
RUST_LOG=debug yarn rust:engine --scene Default
# Very verbose logging
RUST_LOG=trace yarn rust:engine --scene Default
# Show stack trace on crash
RUST_BACKTRACE=1 yarn rust:engine --scene Default
# Combine both
RUST_BACKTRACE=1 RUST_LOG=debug yarn rust:engine --scene Default# Run all tests
yarn rust:test
# Run specific test
cd rust/engine
cargo test test_material_cache
# Run tests with output
cargo test -- --nocapture
# Run tests matching pattern
cargo test material# Format code
cd rust/engine && cargo fmt
# Check for issues
cargo clippy
# Fix simple warnings automatically
cargo fix --bin "vibe-engine"Phase 4-5 (Next):
- Entity hierarchy (parent-child transforms)
- GLTF model loading
- Light component rendering
- Physics integration
- More component types
Future:
- Hot reloading
- Camera controls
- Multiple render passes
- Post-processing effects
Current performance:
- 60 FPS target
- ~100-200 entities before optimization needed
- Materials are per-instance (efficient)
- Meshes are cached and shared
Data Flow:
- JSON Scene →
SceneData(via serde) SceneData→SceneRenderer(parse entities/materials)SceneRenderer→ GPU buffers (vertex + instance data)- Render loop → wgpu draw calls → screen
Key Design Decisions:
- Materials passed as per-instance data (not textures yet)
- Camera settings applied at initialization (not runtime updates yet)
- Primitive meshes generated procedurally
- All tests use JSON parsing (ensures schema compatibility)
- Check this README
- Read the code comments
- Run tests:
yarn rust:test - Check
INTEGRATION_AUDIT.mdfor current status - See
docs/PRDs/4-60-rust-engine-basics.mdfor full requirements