kicad monkey v2026.11.30
On This Page (8)

Fabrication & Virtual Layers in Rust (kicad-monkey-fab)

kicad-monkey-fab is the pure-Rust manufacturing and virtual-layer engine for KiCad >= 7 PCBs (MIN_SUPPORTED_PCB_KICAD_MAJOR = 7, #![forbid(unsafe_code)], zero KiCad desktop runtime, zero OpenCASCADE).

Every manufacturing output lowers from a single normalized whole-nanometre board model — FabViewData — ensuring copper Gerbers, Excellon drills, IPC-2581B stackups, analytic SVGs, Micro-STEP solids, and all 17 virtual fab layers agree to the exact nanometre.


FabViewData & KiCadFab Architecture

FabViewData converts a parsed kicad_monkey_core::PcbView into mathematical +Y-up integer nanometres (CoordNm), normalizing board stackup rows (FabStackRow), outer profile + cutouts (FabProfile), per-layer items (FabLayerItems containing lands, strokes, areas), holes/slots (FabHole), drill spans (FabDrillPair), components (FabComponent), and auxiliary origin.

KiCadFab wraps FabViewData with ergonomic single-call and batch exporters:

Entry PointOptions StructOutput
KiCadFab::from_pcb_file(path) / from_pcb_source(src, name) / from_pcb_view(&view, name)—Constructs one normalized FabViewData reused across all outputs
fab.to_gerbers(&GerberOptions)GerberOptions (stem, x2, use_aux_origin, include_profile, include_silk)Vec<FabFile> (.GTL, .GBL, .G1…, .GTS, .GBS, .GTP, .GBP, .GTO, .GBO, .GM1)
fab.to_nc_drill(&DrillOptions)DrillOptions (stem, use_aux_origin)Vec<FabFile> (multi-span PTH/NPTH + G85 routed oval slots)
fab.to_ipc2581()—Schema-valid IPC-2581 Rev B .cvg XML String
fab.to_micro_step() / write_layer_step(&view, &LayerStepOptions)LayerStepOptionsSelf-contained ISO 10303-21 Micro-STEP String / LayerStepResult
fab.to_svg(&SvgOptions) / fab.to_layer_svgs(&SvgOptions)SvgOptions (stem, bottom, padding_mm, include_silk)Analytic composite board SVG String or per-layer Vec<FabFile>
fab.to_pnp(use_aux_origin) / fab.to_bom()boolPick-and-Place centroid CSV and grouped BOM CSV String
fab.virtual_layer(name) / build_virtual_layer(&view, key)Per-layer option structs (Pin1Options, DiodeOptions, CapacitorOptions, InductorOptions)FabLayerItems for any of the 17 canonical virtual layers
fab.write_all(out_dir, &FabAllOptions)FabAllOptionsWrites any combination of Gerbers, drill, IPC-2581B, SVGs, PnP, BOM, Micro-STEP, and virtual-layer Gerbers into out_dir

Calibration & Performance

kicad-monkey-fab is calibrated directly against kicad-cli 10.0.8 + gerbv across all 8 unified pcb_fab synthetic test boards (42/42 P1, 6/6 P2 drills/slots, 5/5 P3 silkscreen — 100.0%) and 22 KiCad >= 7 real-world boards up to 12 copper layers (100% copper parity, 39/39 P2 drills/slots, 189/192 P1 at mean 0.9961 / 0.9996), running 2.4x–7.5x faster than the Python KiCadFabView pipeline.


All 17 Canonical Virtual Fab Layers

ALL_VIRTUAL_LAYERS exposes all 17 canonical virtual layers, and resolve_virtual_layer_key normalizes common aliases (BOARD_CUTOUTS, PIN_1_TOP, PIN_1_BOTTOM, CAPS_TOP, CAPS_BOTTOM, ASSY_OUTLINES_*, ASSY_DESIGNATORS_*):

GroupCanonical KeysRust Customization Helpers
Board CutoutsCUTOUTSbuild_virtual_layer(&view, "CUTOUTS")
Pin 1 / PolarityPIN1_TOP, PIN1_BOTTOMpin1::build_pin1_layer(&view, side, &Pin1Options) (Pin1Override, BGA/grid pad detection)
DiodesDIODES_TOP, DIODES_BOTTOMdiodes::build_diodes_layer(&view, side, &DiodeOptions) (DiodeOverride, DiodeType, DiodeVisibilityMode)
PassivesCAPACITORS_TOP, CAPACITORS_BOTTOM, INDUCTORS_TOP, INDUCTORS_BOTTOM, RESISTORS_TOP, RESISTORS_BOTTOMpassives::build_capacitors_layer_with_options, build_inductors_layer_with_options, build_resistors_layer (CapacitorOptions, InductorOptions)
AssemblyASSEMBLY_OUTLINES_TOP, ASSEMBLY_OUTLINES_BOTTOM, ASSEMBLY_DESIGNATORS_TOP, ASSEMBLY_DESIGNATORS_BOTTOMdesignator_fit::DesignatorFitSession (DEFAULT_OBLIQUE_MIN_ASPECT_RATIO, subtract_cutouts, pad_envelope)
Pad LabelsPAD_LABELS_TOP, PAD_LABELS_BOTTOMbuild_virtual_layer(&view, "PAD_LABELS_TOP")

Any virtual layer's FabLayerItems can be rendered straight to Gerber with render_virtual_gerber(key, &items, shift, x2) or baked back into a KiCad source file via bake / bake_footprint.


Board & Footprint vdoc Baking (bake & bake_footprint)

kicad-monkey-fab implements the same non-destructive vdoc baking workflow exposed by k3 vdoc / kcr vdoc, using lossless byte-range edits so untouched board and footprint syntax is preserved byte-for-byte:

Board Baking (bake.rs)

Standalone Footprint Baking (bake_footprint.rs)

rust
use kicad_monkey_fab::{
    BakeVirtualLayersOptions, DEFAULT_VDOC_PCB_LAYERS, VdocLayerPreset,
    bake_virtual_layers_source, default_kicad_layer_for_virtual_preset,
};

pub fn bake_board_vdoc(pcb_source: &str) -> Result<String, kicad_monkey_fab::FabError> {
    let mut opts = BakeVirtualLayersOptions::default();
    opts.layer_map = DEFAULT_VDOC_PCB_LAYERS
        .iter()
        .filter_map(|&key| {
            default_kicad_layer_for_virtual_preset(key, VdocLayerPreset::FabOutlines)
                .map(|layer| (key.to_owned(), layer.to_owned()))
        })
        .collect();
    let (updated_source, report) = bake_virtual_layers_source(pcb_source, "board", &opts)?;
    println!("Baked {} virtual layer(s)", report.layers.len());
    Ok(updated_source)
}

Honest Parity Notes vs. Python KiCadFabView

kicad-monkey-fab is pure Rust with no Geometer / OpenCASCADE dependency and no Python runtime. Keep these deliberate differences in mind when choosing between the Rust library crate, the native k3 CLI, and Python kicad-monkey:

For the complete side-by-side table, see the Python vs. Native Rust (kicad-monkey-fab) Parity Matrix and the Native Rust CLI (k3) Parity Guide.


kicad-monkey v2026.11.30·Docs updated 2026.12.01 15:43 UTC (fd9b75b)