Sebastien Rousseau

LibMake: Rust Library Scaffold Generator

LibMake: a Rust code generator that enforces best practices from day one.

5 min read
Banner for: LibMake: Rust Library Scaffold Generator

Executive Summary / Key Takeaways

  • LibMake ⧉ is an open-source Rust CLI tool installed via cargo install libmake that generates a complete library scaffold from CLI flags or a config file (TOML, YAML, JSON, or CSV), with output covering Cargo.toml, source, tests, benchmarks, documentation, and CI in one invocation.
  • The generated project follows Rust API Guidelines conventions: module-level and item-level doc comments in src/lib.rs, #![deny(missing_docs)] in the crate root, and a README wired to the crate documentation via #![doc = include_str!("../README.md")].
  • Config-file mode (--config libmake.toml) allows teams to commit a single file that fully specifies their library template — author, licence, categories, Rust edition, MSRV, repository URL — making scaffold generation repeatable and diffable in Git.
  • The GitHub Actions workflow generated by LibMake tests on stable, beta, and nightly Rust toolchains, enforces clippy -D warnings, checks rustfmt, and runs cargo-audit for known CVEs in the dependency tree.
  • Tera templates power the code generation: LibMake ships with a default template set but accepts a custom template directory via --template, so non-standard project layouts and additional generated files are supported without forking the tool.

LibMake ⧉ is an open-source Rust CLI and library that generates a complete library project scaffold from a single invocation. It targets the gap between cargo new --lib (which creates only a minimal Cargo.toml and src/lib.rs) and a production-ready library setup (which requires manually adding doc comments, CI, test harnesses, benchmark structure, CONTRIBUTING.md, and licence files).

This article describes what LibMake generates, how the config-file and CLI modes work, the generated CI structure, and the templating system.

Installation and Basic Usage #

LibMake is published on crates.io and installed via Cargo:

cargo install libmake

The minimal CLI invocation generates a named library in the current directory:

libmake \
  --author "Jane Smith" \
  --email "jane@example.com" \
  --name "my_library" \
  --description "A Rust library for doing useful things" \
  --version "0.1.0" \
  --licence "MIT OR Apache-2.0" \
  --repository "https://github.com/example/my_library" \
  --rustversion "1.70.0" \
  --edition "2021" \
  --output "my_library"

Additional optional flags include --categories, --keywords, --homepage, --documentation, --readme, and --build.

Config-File Mode #

For team use, all CLI flags can be expressed in a TOML config file:

# libmake.toml



















<!-- lead-start -->
<aside class="post-lead" aria-label="Article summary">
<p class="post-lead-tldr"><strong>TL;DR.</strong> LibMake is a Rust CLI tool that generates a complete library scaffold — Cargo.toml, src/lib.rs with doc templates, test and benchmark harnesses, and GitHub Actions CI — from a single command or a versioned TOML/YAML config file.</p>
<p class="post-lead-heading"><strong>Key takeaways</strong></p>
<ul class="post-lead-takeaways">
  <li><strong>Installation and Basic Usage.</strong> LibMake is published on crates.io and installed via Cargo:.</li>
  <li><strong>Config-File Mode.</strong> For team use, all CLI flags can be expressed in a TOML config file:.</li>
  <li><strong>Generated Project Structure.</strong> A LibMake invocation creates the following layout:.</li>
  <li><strong>GitHub Actions CI Workflow.</strong> The generated .github/workflows/release.yml runs five jobs on every push and pull request:.</li>
</ul>
</aside>
<!-- lead-end -->

author      = "Jane Smith"
email       = "jane@example.com"
name        = "my_library"
description = "A Rust library for doing useful things"
version     = "0.1.0"
licence     = "MIT OR Apache-2.0"
repository  = "https://github.com/example/my_library"
rustversion = "1.70.0"
edition     = "2021"
output      = "my_library"
categories  = ["algorithms", "data-structures"]
keywords    = ["rust", "library"]

Invoked as:

libmake --config libmake.toml

LibMake also accepts JSON, YAML, and CSV config formats via --config-json, --config-yaml, and --config-csv flags respectively. Committing libmake.toml to the repository root gives every contributor a reproducible scaffold baseline, and changes to the template configuration are visible in Git diffs.

Generated Project Structure #

A LibMake invocation creates the following layout:

my_library/
├── .github/
│   └── workflows/
│       └── release.yml     # full CI matrix
├── benches/
│   └── lib_benchmarks.rs   # Criterion benchmark stub
├── src/
│   └── lib.rs              # doc-commented, deny(missing_docs)
├── tests/
│   └── lib_tests.rs        # integration test stub
├── CONTRIBUTING.md
├── Cargo.toml              # complete metadata
├── LICENSE-APACHE
├── LICENSE-MIT
└── README.md

The generated src/lib.rs includes a crate-level doc comment, #![deny(missing_docs)], #![doc = include_str!("../README.md")] to pull the README into rustdoc, and a stub public type with an associated doc comment. These choices follow the Rust API Guidelines requirement that all public items have documentation.

The generated benches/lib_benchmarks.rs uses Criterion.rs and requires adding criterion as a dev-dependency, which LibMake inserts into Cargo.toml automatically.

GitHub Actions CI Workflow #

The generated .github/workflows/release.yml runs five jobs on every push and pull request:

Job Toolchain What it checks
test stable, beta, nightly (matrix) cargo test --all-features
clippy stable cargo clippy -- -D warnings
fmt stable cargo fmt --check
audit stable cargo audit (cargo-audit installed in job)
doc stable cargo doc --no-deps (fails on missing docs)

The nightly job has continue-on-error: true so a nightly regression does not block merges, while still surfacing the failure in the workflow run.

Templating with Tera #

LibMake uses the Tera template engine — a Jinja2-like syntax for Rust — to render all generated files. Each template receives the full config struct as context:

{{ name }}            → my_library
{{ author }}          → Jane Smith
{{ edition }}         → 2021
{{ description }}     → A Rust library for doing useful things

Custom template directories are supported via the --template flag:

libmake --config libmake.toml --template ./my_templates/

The custom directory must mirror the default template structure (the same filenames). Any file present in the custom directory overrides the corresponding built-in template; files not present in the custom directory fall back to the built-in version. This allows partial overrides — for example, replacing only the CI workflow template while keeping the default src/lib.rs and Cargo.toml templates.

Frequently Asked Questions #

How does LibMake differ from cargo new --lib? cargo new --lib creates a minimal project with only Cargo.toml and src/lib.rs (containing a single #[cfg(test)] block). LibMake generates the full structure — integration tests, benchmarks, CI, CONTRIBUTING.md, dual-licence files, and a properly documented src/lib.rs — configured with the project's actual metadata rather than placeholders.

Can LibMake be used with an existing Cargo workspace? LibMake generates a standalone crate directory. To add the generated crate to an existing workspace, add the output path to the workspace members array in the root Cargo.toml. LibMake does not modify existing workspace files.

Can I update the scaffold templates after initial generation? LibMake generates files once; it does not track or update previously generated projects. To adopt updated templates, the recommended approach is to re-run LibMake into a temporary directory and diff the result against the existing crate, applying desired changes selectively.

What Rust editions and MSRV values does LibMake support? LibMake accepts any string for --edition and --rustversion and writes the values directly to Cargo.toml. It does not validate whether the specified edition or MSRV is a real Rust version, so callers are responsible for supplying correct values.

References #

  1. Rousseau, S. LibMake — A code generator to reduce repetitive tasks and build high-quality Rust libraries. GitHub, 2023. https://github.com/sebastienrousseau/libmake
  2. The Rust Programming Language. Rust API Guidelines. GitHub, 2023. https://rust-lang.github.io/api-guidelines/
  3. The Cargo Book. Package Layout. The Rust Programming Language, 2023. https://doc.rust-lang.org/cargo/guide/project-layout.html
  4. Keats, V. et al. Tera — A template engine inspired by Jinja2 and Django templates. GitHub, 2023. https://keats.github.io/tera/

Last reviewed .