Skip to content

Contributing

Development Setup

# Install Rust (nightly recommended for WASM SIMD)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Clone and build
git clone <repo-url>
cd wgpu-triangle
make build

Code Quality

Pre-commit Hooks

The project has pre-commit hooks that run cargo fmt and cargo clippy before each commit. Make sure your code passes both:

make fmt    # Auto-format
make lint   # Run clippy

Testing

# Run all tests (~289 tests)
make test

# Run a specific test
cargo test test_interpolate_linear

# Run tests with output
cargo test -- --nocapture

Test conventions:

  • Tests are embedded in source files via #[cfg(test)] modules
  • Mock external dependencies (HTTP, GPU)
  • Test edge cases: empty inputs, invalid data, boundary values
  • One assertion per test when practical

Benchmarks

Criterion.rs benchmarks cover the CPU-hot paths:

Benchmark Module
mvt_decode Protobuf parsing
tessellation Polygon triangulation
collision Label placement
expressions Style expression evaluation
extraction Geometry extraction pipeline
make bench          # Run all benchmarks
make bench-report   # Open HTML report in browser

Coverage

# Generate LCOV coverage report
make coverage

# Run SonarQube analysis (requires local SonarQube instance)
make sonar

Target: ≥80% coverage, zero bugs, zero vulnerabilities, zero code smells.

Architecture Guidelines

  • Extract-Prepare-Render: all new rendering features should follow this pattern
  • Free functions for geometry emission to avoid borrow conflicts
  • Tile-relative Mercator encoding for all vertex positions
  • Storage buffers for per-label/per-tile data (not per-vertex attributes)
  • [profile.dev.package."*"] opt-level = 2: dependencies are optimized even in debug builds

Module Ownership

Area Key files
Rendering pipeline src/renderer/
Tile management src/tile_loader/, src/tile_coords.rs
Style evaluation src/style_eval/, src/style.rs, src/expressions/
Text/icons src/glyph_atlas.rs, src/text_shaper.rs, src/sprite.rs, src/collision.rs
Platform bridges src/ffi.rs (iOS), src/web.rs (WASM)
Shaders shaders/*.wgsl