Skip to content

feat: generate C headers from layouts#85

Open
tomrford wants to merge 3 commits into
mainfrom
feat/header-generator
Open

feat: generate C headers from layouts#85
tomrford wants to merge 3 commits into
mainfrom
feat/header-generator

Conversation

@tomrford

@tomrford tomrford commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • add mint_core::header::generate and the mint header FILE[#BLOCK]... -o FILE command
  • render naturally aligned nested C structs with scalar/fixed-point mappings, reusable array extents, and bitmap shift/mask macros
  • validate C identifiers, keywords, field-tree conflicts, ref targets, and generated-name collisions before writing output
  • replace the hand-written example header with generated output and update the README, CLI/layout docs, and bundled skill
  • cover deterministic rendering, every storage mapping, collisions, full-width bitmaps, and the corrected ABI with a warnings-as-errors C11 compile test

Validation

  • nix develop -c cargo fmt --all -- --check
  • nix develop -c cargo clippy --workspace --all-targets -- -D warnings
  • nix develop -c cargo test --workspace --locked
  • nix develop -c uv run --directory crates/mint-python --group dev maturin develop --manifest-path Cargo.toml
  • nix develop -c uv run --directory crates/mint-python --group dev pytest tests

Closes #70


Note

Medium Risk
New public API and CLI surface with substantial header-generation logic; risk is moderate because failures are validated before write and coverage includes C ABI checks, but firmware could still diverge if target alignment differs from Mint’s contract.

Overview
Adds C header generation from the same TOML layout selectors used for flash builds, so the layout can own struct shape for firmware without a data source.

mint_core::header::generate resolves blocks via shared resolve_blocks, builds nested typedef struct trees from dotted paths, maps scalars/fixed-point to <stdint.h> types, and emits array _LEN / _ROWS / _COLS macros plus named bitmap _SHIFT / _MASK macros. It validates C identifiers, keywords, ref targets, field-tree collisions, and upper-snake macro/typedef collisions before returning the full header string; MintError::InHeaderBlock wraps per-block failures.

The CLI gains mint header FILE[#BLOCK]... -o FILE, wired through shared write_text file output. Docs, README, skill text, and doc/examples/blocks.h are updated to the generated format (include guard, extent macros). Tests cover deterministic output, validation errors, unchanged output on failure, and a warnings-as-errors C11 compile of the example header against layout offsets/sizes.

Reviewed by Cursor Bugbot for commit f2f79f9. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add C header generation from mint layouts

1 participant