On This Page (8)
Crate-by-Crate Reference
The standalone kicad-monkey Rust workspace contains six pure-Rust crates (Edition 2024, MSRV 1.95, #![forbid(unsafe_code)]). Each crate has a tightly scoped responsibility and minimal dependency footprint.
Quick Selection Guide
| If you want to… | Depend on |
|---|---|
Parse, inspect, compile, or losslessly patch .kicad_pcb, .kicad_mod, .kicad_sch, .kicad_sym, .kicad_pro, or .kicad_wks files | kicad-monkey-core |
Emit Gerber X2/X1, Excellon NC Drill, IPC-2581B, Micro-STEP, PnP/BOM CSV, analytic board SVGs, 17 virtual layers, or vdoc baking | kicad-monkey-fab |
| Render typed Plotter IR documents (board, footprint, symbol, schematic page) directly to deterministic SVG | kicad-monkey-svg (+ kicad-monkey-core) |
Deserialize, serialize, or validate the 30 TypeSpec wire contracts (Plotter IR, CompiledSchematicGraph, SourceBundleManifest, font/text DTOs) | kicad-monkey-contracts |
| Realize KiCad Newstroke vector text or HarfBuzz/Skrifa OpenType glyph outlines standalone | cad-text-realization |
| Regenerate Rust contract modules from Draft 2020-12 JSON Schemas during development | kicad-monkey-codegen (dev/build tool) |
1. kicad-monkey-core
Role: The foundational KiCad source parsing, round-trip patching, hierarchical schematic compilation, Plotter IR projection, and authoring library.
- Key modules & public entry points:
- S-expression foundation (
sexpr,sexpr_mutation,sexpr_projection):sexpr::lex,sexpr::parse,sexpr::parse_bytes,sexpr::build,sexpr::format,sexpr::Patch,sexpr::apply_patches,sexpr_projection::scan_form_spans,prettify_kicad_source. - PCB & Footprint models (
pcb,footprint,pcb_authoring):PcbView::parse,PcbView::parse_selected,PcbDocument,PcbLimits,PcbEdit,FootprintView::parse,FootprintDocument,FootprintEdit,AuthoredPcb,AuthoredStandaloneFootprint,KiCadModelResolver. - Schematics, Symbols, Projects & Worksheets (
schematic_bundle,schematic_compilation,compiled_schematic_graph,kicad_netlist,design_json,symbol_library,project,worksheet):SchematicBundleIndex,build_compiled_schematic_graph,build_kicad_netlist,build_kicad_design_json,ProjectView,ProjectDocument. - Plotter IR builders & contract projectors (
board_plotter_ir,plotter_ir,symbol_plotter_ir,schematic_plotter_ir,board_plot_contract,footprint_plot_contract,symbol_plot_contract,schematic_plot_contract):board_plot_document,project_board_plot_artifact_a0,footprint_plot_document,project_footprint_plot_document_a0,symbol_plot_document,project_symbol_plot_document_a0,schematic_plot_document,project_schematic_plot_document_a0.
- S-expression foundation (
- Dependencies:
cad-text-realization,kicad-monkey-contracts,serde,serde_json,sha2,unicode-casefold,harfrust,read-fonts,skrifa,ttf-parser, and optional default featureembedded-resource-zstd(zstd, for KiCad 9/10 zstd-compressed embedded files). - When to choose it: Whenever you need structured KiCad file reading, span-accurate lossless patching, hierarchical netlist compilation, or Plotter IR generation without pulling in fabrication geometry (
geo) or SVG serialization.
2. kicad-monkey-fab
Role: Pure-Rust fabrication and virtual-layer geometry engine over kicad_monkey_core::PcbView.
- Key modules & public entry points:
- Core view & facade (
view, rootlib.rs):FabViewData::from_pcb_source,FabViewData::from_pcb_view,KiCadFab::from_pcb_file,KiCadFab::from_pcb_source,KiCadFab::from_pcb_view,KiCadFab::write_all,FabAllOptions,FabFile,FabOutput,FabError. - Manufacturing writers (
gerber,drill,ipc2581,micro_step,svg,tabular):write_gerbers(GerberOptions),render_virtual_gerber,write_nc_drill(DrillOptions),write_ipc2581,write_micro_step,write_layer_step(LayerStepOptions),write_composite_svg/write_layer_svgs(SvgOptions),write_pnp_csv,write_bom_csv. - Virtual layers &
vdocbaking (virtual_layers,pin1,diodes,passives,designator_fit,bake,bake_footprint):ALL_VIRTUAL_LAYERS,resolve_virtual_layer_key,build_virtual_layer,Pin1Options,DiodeOptions,CapacitorOptions,InductorOptions,DesignatorFitSession,bake_virtual_layers_source,bake_virtual_layers_with_view,bake_virtual_layers_to_footprint_source,build_footprint_fab_view,clean_pcb_doc_layers_source,VdocLayerPreset,BakeVirtualLayersOptions,BakeFootprintVirtualLayersOptions.
- Core view & facade (
- Dependencies:
kicad-monkey-core,cad-text-realization,geo,serde,serde_json,sha2. - When to choose it: For manufacturing output generation, virtual fab layer synthesis, analytic Micro-STEP export, or board/footprint
vdocbaking. See Fabrication & Virtual Layers in Rust.
3. kicad-monkey-svg
Role: Bounded, deterministic direct SVG serializer for frozen KiCad Plotter IR documents (kicad.plotter_ir.a0).
- Key modules & public entry points:
- Direct renderers:
render_board_svg,render_board_document_svg,render_footprint_svg,render_symbol_svg,render_schematic_svg,render_schematic_page_svg. - Context, styling & viewports:
SvgRenderContextA1,SvgRenderContextBuilder,ValidatedSvgRenderContextA1::defaults(),ViewportPolicy(Explicit(SvgViewport)/Fit(SvgFitOptions)),LayerSelection,SvgProfile,SvgIdentityMode,SvgBackground,SvgStyleOverride. - Artifacts & telemetry:
SvgArtifact(svg,viewport,visible_bounds,warnings,repeated_ids,metrics),SvgMetrics,SvgError,SvgErrorKind.
- Direct renderers:
- Dependencies:
kicad-monkey-contracts,kicad-monkey-core— zero third-party XML or raster crates. - When to choose it: When you want direct typed SVG output from
kicad-monkey-corePlotter IR (boards, footprints, symbols, schematic sheets) with zero JSON round-trips, exact nanometre bounds, and validated styling/resource budgets.
4. kicad-monkey-contracts
Role: TypeSpec-generated wire contract structs, validated scalar newtypes, and cross-field semantic validators for all 30 core schemas.
- Key modules & public entry points:
- Generated modules (
generated::*): 30 modules matchingcontracts/generated/schema/*.json(board_plot_document,footprint_plot_document,symbol_plot_document,schematic_plot_document,compiled_schematic_graph,source_bundle_manifest,font_bundle_manifest,shaping_record,outline_vector,build_request,scan_request, etc.). - Validated newtypes:
JavaScriptSafeInteger,SchematicDefaultLineWidthNm,NonNegativeFiniteFloat,FiniteFloat,PositiveU32,StableTextId. - Semantic validators & decoders:
validate_build_request,validate_board_plot_document,validate_footprint_plot_document,validate_symbol_plot_document,validate_schematic_plot_document,decode_compiled_schematic_graph_a0,validate_compiled_schematic_graph_contract,decode_source_bundle_manifest_a0,validate_source_bundle_manifest_contract,validate_font_bundle_contract,resolve_font_selection_contract,validate_shaping_record_contract,validate_outline_vector_contract.
- Generated modules (
- Dependencies:
cad-text-realization,serde,serde_json,sha2. - Important architectural invariant:
kicad-monkey-contractshas zeroschemarsruntime dependency (schemarsandtypifystay quarantined inside build-timekicad-monkey-codegen). - When to choose it: When building lightweight wire consumers, WASM modules, or validators that speak KiCad Monkey's TypeSpec contracts without needing S-expression parsing or CAD geometry.
5. cad-text-realization
Role: Shared bounded, deterministic CAD text realization engine for both KiCad's built-in Newstroke vector stroke font and OpenType / TrueType font shaping and outline extraction.
- Key modules & public entry points:
- Stroke text:
realize_stroke_text_a0,realize_stroke_text_profile_a0,realize_stroke_text_plot_a0,realize_stroke_text_multiline_a0,wrap_stroke_text_box,StrokeTextRequest,StrokeTextProfile::kicad(),StrokeTextOutput. Supports KiCad markup (~{overbar},_{subscript},^{superscript}), column tab stops, and KiCad 10.0.8 glyph-baseline italic slant. - OpenType / TrueType:
shape_text_a0(harfrust),extract_font_outline_a0(skrifa/ttf-parser),shape_text_contours_a0,layout_single_line_text_a0,fracture_text_contours_a0,group_text_contours_a0,realize_opentype,font_container(wuffWOFF/WOFF2 decompression). - Shared text contract types (
contract):ShapingInput,ShapedGlyph,OutlineCommand,Sha256Hex,OpenTypeTag,SafeInteger,FiniteFloat,StableTextId,ValidationError.
- Stroke text:
- Dependencies:
harfrust,read-fonts,serde,sha2,skrifa,ttf-parser,wuff. - When to choose it: Whenever a CAD or CAM renderer needs deterministic stroke-font polylines or OpenType glyph contours with zero OS font-engine drift.
6. kicad-monkey-codegen
Role: Standalone build/development binary that projects TypeSpec-emitted Draft 2020-12 JSON Schemas into deterministic Rust modules.
- Modes:
- Workspace catalog mode:
cargo run --package kicad-monkey-codegen --locked [-- --check]regenerates all 30 modules insrc/rs/kicad-monkey-contracts/src/generated/. - Standalone config mode:
--standalone <schema.json> <output.rs> [--check]regenerateskicad-cruncher-cli'sPcbSvgConfigwith tri-stateField<T>override wrappers.
- Workspace catalog mode:
- Dependencies:
anyhow,prettyplease,schemars,serde_json,syn,typify. - When to choose it: Only when modifying TypeSpec schemas in the development workspace; runtime applications never depend on
kicad-monkey-codegen. See The Multi-Language Codegen Pipeline.
Related
- Rust Workspace Overview — dependency DAG, safety policy, and Cargo usage.
- Fabrication & Virtual Layers (
kicad-monkey-fab) — deep dive intoFabViewDataandKiCadFab. - Practical Rust Cookbook — runnable code recipes for all major crates.