On This Page (5)
Rust Workspace Overview
Alongside its Python library, kicad-monkey ships a standalone, pure-Rust workspace built for deterministic speed, zero-copy source indexing, and embeddable tooling — with no KiCad desktop installation, no Python interpreter, and no OpenCASCADE (OCCT) runtime required.
Why Pure Rust Alongside Python?
Python (kicad-monkey + kcr) excels at interactive hardware scripting, spreadsheet generation, and rapid prototyping. When you need tight memory ceilings, deterministic multi-board CI throughput, or a native library you can embed directly into a Rust service, desktop app, or WASM target, the Rust workspace gives you first-class native access to the exact same KiCad formats:
#![forbid(unsafe_code)]workspace-wide: Every crate in the workspace enforcesunsafe_code = "forbid"(via[workspace.lints.rust]or crate-local[lints.rust]) — zerounsafeblocks across S-expression parsing, font shaping, fabrication geometry, SVG emission, and STEP export.- Rust Edition 2024, MSRV 1.95: Pinned via
rust-toolchain.tomland tested with--lockedbuilds and strict Clippy lints (cognitive_complexity,too_many_arguments,too_many_lines,allow_attributes_without_reason). - Deterministic zero-copy span indexing:
PcbViewandFootprintViewindex S-expression byte spans over&strwithout allocating an entire mutable AST up front, and targeted edits apply byte-rangePatchreplacements that leave untouched KiCad 10/11 syntax byte-for-byte intact. - Zero KiCad / OCCT runtime: Gerber X2/X1, Excellon NC Drill (
G85routed slots & blind/buried spans), IPC-2581 Rev B, analytic PCB/Schematic/Symbol/Footprint SVGs, all 17 virtual fab layers, and ISO 10303-21 Micro-STEP run completely standalone.
Rust Library Crates vs. Native k3 CLI Binary: This section (and the auto-generated rustdoc Crate API) documents the six pure-Rust library and codegen crates built directly from the public wavenumber-eng/kicad_monkey Cargo workspace. The standalone native k3 CLI executable (kicad-cruncher-cli, which additionally embeds the Geometer 3D client for STEP HLR) is documented in the Native Rust CLI (k3) Parity Guide.
Workspace Crate Dependency DAG
Each crate owns a clean, acyclic slice of the stack so downstream Rust tools compile only what they need (for example, a contract consumer or text shaper never pulls in fabrication geometry or SVG serialization):
cad-text-realization (Newstroke vector fonts + HarfBuzz/Skrifa OpenType shaping & outlines)
│
├──▶ kicad-monkey-contracts (TypeSpec-generated strict serde DTOs; ZERO schemars runtime)
│ │
▼ ▼
kicad-monkey-core (S-expr lexer/parser/patcher, PCB/Footprint/Sch/Sym/Project views,
│ hierarchical compilation, Plotter IR, authoring)
│
├──▶ kicad-monkey-fab (whole-nm FabViewData, 17 virtual layers, Gerber/Drill/IPC-2581/
│ SVG/PnP/BOM/Micro-STEP, board & footprint vdoc baking)
│
└──▶ kicad-monkey-svg (direct typed SVG rendering for boards, footprints, symbols,
and schematic pages — consumes contracts + core)
kicad-monkey-codegen (standalone dev/build binary: Draft 2020-12 JSON Schema -> Rust via
schemars + typify + syn + prettyplease; no runtime link into apps)Adding Crates to Your Project
All six workspace crates currently set publish = false while crates.io publication is prepared separately. Consume them via a Cargo git dependency pinned to a tag/commit or a local path checkout:
[dependencies]
# Option 1: Git dependency (pin to a release tag or commit rev)
kicad-monkey-core = { git = "https://github.com/wavenumber-eng/kicad_monkey", tag = "v2026.11.30" }
kicad-monkey-fab = { git = "https://github.com/wavenumber-eng/kicad_monkey", tag = "v2026.11.30" }
kicad-monkey-svg = { git = "https://github.com/wavenumber-eng/kicad_monkey", tag = "v2026.11.30" }
# Option 2: Local workspace / vendor checkout
# kicad-monkey-core = { path = "../kicad_monkey/src/rs/kicad-monkey-core" }
# kicad-monkey-fab = { path = "../kicad_monkey/src/rs/kicad-monkey-fab" }Building, Testing & Local rustdoc
# Format, lint, and test every crate in the workspace
cargo fmt --all -- --check
cargo clippy --workspace --all-targets --locked
cargo test --workspace --locked
# Generate and open full rustdoc API documentation
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --openExplore the Rust Docs
- Crate-by-Crate Reference — responsibilities, verified public entry points, exact dependencies, and selection guidance for all 6 crates.
- Fabrication & Virtual Layers (
kicad-monkey-fab) —FabViewData,KiCadFab, all 17 virtual layers, Gerber/Drill/IPC-2581B/Micro-STEP/SVG writers,vdocbaking, and honest Python parity notes. - Practical Rust Cookbook — four copy-pasteable, API-verified recipes covering
PcbView::parse, lossless byte-rangePatchediting, fabrication exports, and direct typed SVG rendering. - Native Rust CLI (
k3) Parity Guide — command-by-command comparison between Pythonkcrand the standalone native Rustk3executable. - Format Contracts & TypeSpec — how
kicad-monkey-contractsandkicad-monkey-codegenkeep Rust, Python, and TypeScript wire types in lockstep.