סיכום מנהלים / תובנות מרכזיות
- LibMake ⧉ הוא כלי CLI בקוד פתוח ל-Rust, המותקן באמצעות
cargo install libmake, ומייצר שלד ספרייה מלא מדגלי CLI או מקובץ תצורה (TOML, YAML, JSON או CSV), כולל Cargo.toml, source, tests, benchmarks, documentation ו-CI בהפעלה אחת.- הפרויקט שנוצר פועל לפי conventions של Rust API Guidelines: הערות תיעוד ברמת מודול וברמת פריט ב-src/lib.rs,
#![deny(missing_docs)]בשורש ה-crate, ו-README המחובר לתיעוד ה-crate באמצעות#![doc = include_str!("../README.md")].- מצב קובץ תצורה (
--config libmake.toml) מאפשר לצוותים לשמור קובץ אחד שמגדיר במלואו את template הספרייה — מחבר, רישיון, קטגוריות, Rust edition, MSRV וכתובת repository — כך שייצור השלד ניתן לשחזור ולהשוואה ב-Git.- ה-workflow של GitHub Actions שנוצר על ידי LibMake מריץ בדיקות על stable, beta ו-nightly Rust toolchains, אוכף
clippy -D warnings, בודקrustfmtומריץcargo-auditעבור CVEs ידועים בעץ התלויות.- Templates של Tera מניעים את ייצור הקוד: LibMake מגיע עם סט templates ברירת מחדל, אך מקבל ספריית templates מותאמת דרך
--template, כך שמבני פרויקט לא סטנדרטיים וקבצים נוספים נתמכים בלי לפצל את הכלי.
LibMake ⧉ הוא CLI וספרייה בקוד פתוח ל-Rust שמייצרים שלד מלא לפרויקט ספרייה בהפעלה אחת. הוא מכוון לפער שבין cargo new --lib, שיוצר רק Cargo.toml ו-src/lib.rs מינימליים, לבין setup מוכן לייצור של ספרייה, שמחייב הוספה ידנית של הערות תיעוד, CI, test harnesses, מבנה benchmarks, CONTRIBUTING.md וקובצי רישוי.
המאמר מתאר מה LibMake מייצר, כיצד עובדים מצבי קובץ התצורה וה-CLI, מהו מבנה ה-CI שנוצר וכיצד פועלת מערכת ה-templating.
התקנה ושימוש בסיסי
LibMake מפורסם ב-crates.io ומותקן באמצעות Cargo:
cargo install libmake
הפעלת CLI מינימלית מייצרת ספרייה בשם שנבחר בתיקייה הנוכחית:
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"
דגלים אופציונליים נוספים כוללים --categories, --keywords, --homepage, --documentation, --readme ו---build.
מצב קובץ תצורה
לשימוש צוותי, ניתן לבטא את כל דגלי ה-CLI בקובץ תצורה TOML:
# 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"]
מפעילים כך:
libmake --config libmake.toml
LibMake מקבל גם תצורות JSON, YAML ו-CSV דרך הדגלים --config-json, --config-yaml ו---config-csv בהתאמה. שמירת libmake.toml בשורש המאגר נותנת לכל תורם baseline שחזורי לשלד, ושינויים בתצורת ה-template נראים ב-diffs של Git.
מבנה הפרויקט שנוצר
הפעלת LibMake יוצרת את המבנה הבא:
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
הקובץ src/lib.rs שנוצר כולל הערת תיעוד ברמת ה-crate, #![deny(missing_docs)], את #![doc = include_str!("../README.md")] כדי למשוך את ה-README לתוך rustdoc, וטיפוס ציבורי stub עם הערת תיעוד משויכת. הבחירות האלה עומדות בדרישה של Rust API Guidelines שכל הפריטים הציבוריים יתועדו.
הקובץ benches/lib_benchmarks.rs שנוצר משתמש ב-Criterion.rs ודורש הוספת criterion כ-dev-dependency, ש-LibMake מכניס אוטומטית ל-Cargo.toml.
Workflow של GitHub Actions CI
הקובץ .github/workflows/release.yml שנוצר מריץ חמישה jobs בכל push ו-pull request:
| Job | Toolchain | מה נבדק |
|---|---|---|
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) |
ל-job של nightly יש continue-on-error: true, כך שרגרסיה ב-nightly לא חוסמת merges, אך עדיין מציפה את הכשל בהרצת ה-workflow.
Templating עם Tera
LibMake משתמש במנוע ה-template Tera — תחביר דמוי Jinja2 ל-Rust — כדי לרנדר את כל הקבצים שנוצרים. כל template מקבל את מבנה התצורה המלא כ-context:
{{ name }} → my_library
{{ author }} → Jane Smith
{{ edition }} → 2021
{{ description }} → A Rust library for doing useful things
ספריות template מותאמות נתמכות דרך הדגל --template:
libmake --config libmake.toml --template ./my_templates/
הספרייה המותאמת חייבת לשקף את מבנה ה-template של ברירת המחדל, עם אותם שמות קבצים. כל קובץ שנמצא בספרייה המותאמת מחליף את ה-template המובנה המקביל; קבצים שאינם קיימים בספרייה המותאמת נופלים חזרה לגרסה המובנית. כך מתאפשרות החלפות חלקיות — למשל החלפת template ה-CI workflow בלבד תוך שמירה על templates ברירת המחדל של src/lib.rs ו-Cargo.toml.
שאלות נפוצות
במה LibMake שונה מ-cargo new --lib?
cargo new --lib יוצר פרויקט מינימלי עם Cargo.toml ו-src/lib.rs בלבד, הכולל בלוק #[cfg(test)] יחיד. LibMake מייצר את המבנה המלא — בדיקות אינטגרציה, benchmarks, CI, CONTRIBUTING.md, קובצי רישוי כפולים ו-src/lib.rs מתועד כראוי — ומגדיר אותו עם המטא-דאטה האמיתי של הפרויקט במקום placeholders.
האם ניתן להשתמש ב-LibMake עם Cargo workspace קיים?
LibMake מייצר תיקיית crate עצמאית. כדי להוסיף את ה-crate שנוצר ל-workspace קיים, הוסף את נתיב הפלט למערך members של ה-workspace ב-Cargo.toml שבשורש. LibMake אינו משנה קובצי workspace קיימים.
האם אפשר לעדכן את templates של השלד אחרי הייצור הראשוני? LibMake מייצר קבצים פעם אחת; הוא אינו עוקב אחרי פרויקטים שנוצרו ואינו מעדכן אותם. כדי לאמץ templates מעודכנים, הגישה המומלצת היא להריץ מחדש את LibMake לתיקייה זמנית ולהשוות את התוצאה מול ה-crate הקיים, תוך יישום סלקטיבי של השינויים הרצויים.
אילו Rust editions וערכי MSRV נתמכים ב-LibMake?
LibMake מקבל כל מחרוזת עבור --edition ו---rustversion וכותב את הערכים ישירות ל-Cargo.toml. הוא אינו מאמת אם ה-edition או ה-MSRV שצוינו הם גרסת Rust אמיתית, ולכן האחריות לספק ערכים נכונים היא על מי שמפעיל את הכלי.
מקורות
- Rousseau, S. LibMake — A code generator to reduce repetitive tasks and build high-quality Rust libraries. GitHub, 2023. https://github.com/sebastienrousseau/libmake
- The Rust Programming Language. Rust API Guidelines. GitHub, 2023. https://rust-lang.github.io/api-guidelines/
- The Cargo Book. Package Layout. The Rust Programming Language, 2023. https://doc.rust-lang.org/cargo/guide/project-layout.html
- Keats, V. et al. Tera — A template engine inspired by Jinja2 and Django templates. GitHub, 2023. https://keats.github.io/tera/
נסקר לאחרונה בתאריך .
נסקר לאחרונה .
פרסם מחדש מאמר זה
העתק בפורמט Medium
# LibMake: Rust Library Scaffold Generator — Sebastien Rousseau > Originally published at [https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/](https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/) 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. Read the full article on sebastienrousseau.com: https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/
העתק בפורמט Mastodon
LibMake: Rust Library Scaffold Generator — Sebastien Rousseau 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. https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/
העתק מעוצב עבור LinkedIn
LibMake: Rust Library Scaffold Generator — Sebastien Rousseau 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. להלן עיקרי הנקודות האסטרטגיות: - התקנה ושימוש בסיסי. LibMake מפורסם ב-crates.io ומותקן באמצעות Cargo:. - מצב קובץ תצורה. לשימוש צוותי, ניתן לבטא את כל דגלי ה-CLI בקובץ תצורה TOML:. - מבנה הפרויקט שנוצר. הפעלת LibMake יוצרת את המבנה הבא:. - Workflow של GitHub Actions CI. הקובץ .github/workflows/release.yml שנוצר מריץ חמישה jobs בכל push ו-pull request:. כיצד מתמודד הארגון שלכם עם האתגרים המתוארים במאמר זה? → https://sebastienrousseau.com/he/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
ציטוט הכתבה
LibMake: Rust Library Scaffold Generator — Sebastien Rousseau
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.
BibTeX
@online{rousseau2023libmake,
author = {Rousseau, Sebastien},
title = {{LibMake: Rust Library Scaffold Generator — Sebastien Rousseau}},
year = {2023},
url = {https://sebastienrousseau.com/he/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: Rust Library Scaffold Generator — Sebastien Rousseau PY - 2023 UR - https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/ ER -
Vancouver
Rousseau S. LibMake: Rust Library Scaffold Generator — Sebastien Rousseau. sebastienrousseau.com. 2023 Oct 26. Available from: https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/
Chicago
Rousseau, Sebastien. "LibMake: Rust Library Scaffold Generator — Sebastien Rousseau." sebastienrousseau.com. October 26, 2023. https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/.
APA
Rousseau, S. (2023, October 26). LibMake: Rust Library Scaffold Generator — Sebastien Rousseau. sebastienrousseau.com. https://sebastienrousseau.com/he/2023-10-26-libmake-a-code-generator-to-reduce-repetitive-tasks-and-build-high-quality-rust-libraries/
פרסום מחדש של הכתבה
LibMake: Rust Library Scaffold Generator — Sebastien Rousseau
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.
כתבה זו מפורסמת ברישיון Creative Commons Attribution 4.0 International. פרסום מחדש מחייב ייחוס לכתובת ה-URL הקאנונית.
LibMake: Rust Library Scaffold Generator — Sebastien Rousseau 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. Originally published at https://sebastienrousseau.com/he/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.
