Sebastien Rousseau

LIBMAKE

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust

Gina production-ready Rust library scaffold tare da CI, tests da docs cikin ƙasa da daƙiƙa 60

4 min read
Banner for: LibMake: Mai Samar da Tsarin Ginin Laburaren Rust

Takaitaccen bayani / mahimman bayanai

  • LibMake ⧉ Rust CLI tool ne na open-source da ake install ta cargo install libmake, yana samar da cikakken library scaffold daga CLI flags ko config file (TOML, YAML, JSON, ko CSV), tare da output da ya ƙunshi Cargo.toml, source, tests, benchmarks, documentation da CI a invocation guda.
  • Generated project yana bin Rust API Guidelines: module-level da item-level doc comments a src/lib.rs, #![deny(missing_docs)] a crate root, da README da aka haɗa da crate documentation ta #![doc = include_str!("../README.md")].
  • Config-file mode (--config libmake.toml) yana ba teams damar commit single file da ke ƙayyade library template gaba ɗaya — author, licence, categories, Rust edition, MSRV, repository URL — yana sa scaffold generation repeatable kuma diffable a Git.
  • GitHub Actions workflow da LibMake ke generate yana test a stable, beta da nightly Rust toolchains, yana enforce clippy -D warnings, yana check rustfmt, kuma yana run cargo-audit don known CVEs a dependency tree.
  • Tera templates ne ke sarrafa code generation: LibMake yana zuwa da default template set amma yana karɓar custom template directory ta --template, don haka non-standard project layouts da ƙarin generated files suna samun support ba tare da forking tool ba.

LibMake ⧉ Rust CLI da library ne na open-source da ke samar da complete library project scaffold daga invocation guda. Yana rufe tazarar da ke tsakanin cargo new --lib (wanda ke ƙirƙirar minimal Cargo.toml da src/lib.rs kawai) da production-ready library setup (wanda ke buƙatar ƙara doc comments, CI, test harnesses, benchmark structure, CONTRIBUTING.md da licence files da hannu).

Wannan labarin yana bayyana abin da LibMake ke generate, yadda config-file da CLI modes ke aiki, generated CI structure, da templating system.

Installation da basic usage

An publish LibMake a crates.io, kuma ana install da Cargo:

cargo install libmake

Minimal CLI invocation yana generate named library a 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"

Ƙarin optional flags sun haɗa da --categories, --keywords, --homepage, --documentation, --readme, da --build.

Config-file mode

Don team use, ana iya bayyana duk CLI flags a cikin TOML config file:

# libmake.toml
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"]

Ana kira da:

libmake --config libmake.toml

LibMake yana kuma karɓar JSON, YAML, da CSV config formats ta --config-json, --config-yaml, da --config-csv flags bi da bi. Commit ɗin libmake.toml zuwa repository root yana ba kowane contributor reproducible scaffold baseline, kuma changes zuwa template configuration suna bayyana a Git diffs.

Generated project structure

LibMake invocation yana ƙirƙirar layout mai zuwa:

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

Generated src/lib.rs yana ƙunshe da crate-level doc comment, #![deny(missing_docs)], #![doc = include_str!("../README.md")] don jawo README zuwa rustdoc, da stub public type tare da associated doc comment. Waɗannan choices suna bin requirement na Rust API Guidelines cewa duk public items su kasance da documentation.

Generated benches/lib_benchmarks.rs yana amfani da Criterion.rs kuma yana buƙatar ƙara criterion a matsayin dev-dependency; LibMake yana saka shi cikin Cargo.toml ta atomatik.

GitHub Actions CI workflow

Generated .github/workflows/release.yml yana run jobs biyar a kowane push da pull request:

Job Toolchain Abin da yake check
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)

Nightly job yana da continue-on-error: true, don haka nightly regression ba ya block merges, amma har yanzu failure yana bayyana a workflow run.

Templating da Tera

LibMake yana amfani da Tera template engine — syntax mai kama da Jinja2 don Rust — don render duk generated files. Kowane template yana karɓar full config struct a matsayin context:

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

Ana support custom template directories ta --template flag:

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

Custom directory dole ya mirror default template structure (filenames iri ɗaya). Duk file da ke cikin custom directory yana override corresponding built-in template; files da ba su cikin custom directory suna fallback zuwa built-in version. Wannan yana ba da partial overrides — misali, maye gurbin CI workflow template kawai yayin da ake barin default src/lib.rs da Cargo.toml templates.

Tambayoyin da ake yawan yi

Yaya LibMake ya bambanta da cargo new --lib? cargo new --lib yana ƙirƙirar minimal project da Cargo.toml da src/lib.rs kaɗai (mai ɗauke da #[cfg(test)] block guda). LibMake yana generate full structure — integration tests, benchmarks, CI, CONTRIBUTING.md, dual-licence files, da src/lib.rs mai documentation mai kyau — configured da actual metadata na project maimakon placeholders.

Za a iya amfani da LibMake da existing Cargo workspace? LibMake yana generate standalone crate directory. Don ƙara generated crate zuwa existing workspace, a ƙara output path zuwa workspace members array a root Cargo.toml. LibMake ba ya modify existing workspace files.

Zan iya update scaffold templates bayan initial generation? LibMake yana generate files sau ɗaya; ba ya track ko update projects da aka generate a baya. Don amfani da updated templates, recommended approach shi ne a sake run LibMake cikin temporary directory sannan a diff result da existing crate, a apply changes da ake so selectively.

Wane Rust editions da MSRV values LibMake yake support? LibMake yana karɓar kowace string don --edition da --rustversion kuma yana rubuta values kai tsaye zuwa Cargo.toml. Ba ya validate ko specified edition ko MSRV real Rust version ne, don haka callers ne ke da alhakin bayar da correct values.

Manazarta

  1. Rousseau, S. LibMake — code generator don rage repetitive tasks da gina 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 — template engine da Jinja2 da Django templates suka yi tasiri a kansa. GitHub, 2023. https://keats.github.io/tera/

An sake dubawa na ƙarshe .

Bita ta ƙarshe .

Sake buga wannan labarin

Kwafa tsarin Medium

# LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

> Originally published at [https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/](https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/)

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold — Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI — daga command guda ko versioned TOML/YAML config file.

Read the full article on sebastienrousseau.com: https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/

Kwafa tsarin Mastodon

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold — Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI — daga command guda ko versioned TOML/YAML config file.

https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/

Kwafa an tsara don LinkedIn

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold - Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI - daga command guda ko versioned TOML/YAML config file.

Ga abubuwan da ya kamata a lura da su na dabarun:

- Installation da basic usage. An publish LibMake a crates.io, kuma ana install da Cargo:.
- Config-file mode. Don team use, ana iya bayyana duk CLI flags a cikin TOML config file:.
- Generated project structure. LibMake invocation yana ƙirƙirar layout mai zuwa:.
- GitHub Actions CI workflow. Generated .github/workflows/release.yml yana run jobs biyar a kowane push da pull request:.

Menene hanyar ƙungiyar ku wajen magance ƙalubalen da aka kawo a wannan rubuce-rubucen?

→ https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/

#Libmake #RustCodeGenerator #CargoScaffold #RustLibraryTemplate #TeraTemplating

Sebastien Rousseau | CC-BY-4.0
Buga wannan labari

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold — Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI — daga command guda ko versioned TOML/YAML config file.

BibTeX

@online{rousseau2023libmake,
  author  = {Rousseau, Sebastien},
  title   = {{LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau}},
  year    = {2023},
  url     = {https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/},
  urldate = {2023}
}

RIS

TY  - GEN
AU  - Rousseau, Sebastien
TI  - LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau
PY  - 2023
UR  - https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/
ER  -

Vancouver

Rousseau S. LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau. sebastienrousseau.com. 2023 Oct 26. Available from: https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/

Chicago

Rousseau, Sebastien. "LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau." sebastienrousseau.com. October 26, 2023. https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/.

APA

Rousseau, S. (2023, October 26). LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau. sebastienrousseau.com. https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/

Sake buga wannan labari

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold — Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI — daga command guda ko versioned TOML/YAML config file.

An lasisin wannan labari a karkashin Creative Commons Attribution 4.0 International. Sake bugawa na bukatar nuna asalin URL na asali.

LibMake: Mai Samar da Tsarin Ginin Laburaren Rust — Sebastien Rousseau

LibMake Rust CLI tool ne da ke samar da cikakken library scaffold — Cargo.toml, src/lib.rs tare da doc templates, test da benchmark harnesses, da GitHub Actions CI — daga command guda ko versioned TOML/YAML config file.

Originally published at https://sebastienrousseau.com/ha/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/ by Sebastien Rousseau.
Licensed under CC-BY-4.0.