hybrid_version/lib.rs
1//! # hybrid-version
2//!
3//! Hybrid Cargo.toml + Git version generation for Rust `build.rs`.
4//!
5//! Generates comprehensive version constants and build fingerprints at compile time
6//! by merging **Cargo.toml** version metadata with **Git repository** state.
7//!
8//! # Features
9//!
10//! - **Hybrid version source** — Reads `major.minor.patch` from `Cargo.toml`,
11//! combines with git branch, commit, and timestamp
12//! - **Auto-patch from commit count** — When `patch = 0`, automatically counts
13//! commits since the version line was last changed (via `git blame`)
14//! - **Modified lines detection** — Tracks both staged and unstaged changes,
15//! appends `-D`, `-M{N}` suffix
16//! - **Release safety** — `modified_cannot_build_release()` panics in release
17//! mode if uncommitted changes exist
18//! - **Rich fingerprint output** — Generates `SOURCES_FINGERPRINT` and
19//! `BUILD_FINGERPRINT` constants
20//! - **Build log** — Writes timestamped build logs for `cargo:rerun-if-changed`
21//! - **Fluent API** — Method chaining for `build.rs`
22//!
23//! # Quick Start
24//!
25//! ```rust,no_run
26//! use hybrid_version::error::VResult;
27//! use hybrid_version::version::Version;
28//! use std::path::PathBuf;
29//!
30//! fn main() -> VResult<()> {
31//! let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
32//! let out_dir = std::env::var("OUT_DIR").unwrap();
33//!
34//! Version::new(&manifest_dir)?
35//! .modified_cannot_build_release()
36//! .write_version(PathBuf::from(&out_dir).join("version.rs"))?;
37//! Ok(())
38//! }
39//! ```
40//!
41//! # Generated Constants
42//!
43//! The generated `version.rs` file provides these compile-time constants:
44//!
45//! | Constant | Example | Description |
46//! |----------|---------|-------------|
47//! | `VERSION` | `"0.5.3.beta1-D/M12"` | Full version string |
48//! | `VERSION_MAJOR` | `0` | Major from Cargo.toml |
49//! | `VERSION_MINOR` | `5` | Minor from Cargo.toml |
50//! | `VERSION_PATCH` | `3` | Patch (auto if `0` in Cargo.toml) |
51//! | `BUILD_ID` | `"beta1"` | Optional build identifier |
52//! | `SOURCES_FINGERPRINT` | `"v0.5.3-D/M dev-57181d0 2023-08-02T14:05:08+08:00"` | Source fingerprint |
53//! | `BUILD_FINGERPRINT` | `"2023-08-02T14:10:09+08:00 debug [...]"` | Build fingerprint |
54
55mod compiler;
56mod git;
57mod ts;
58
59pub mod error;
60pub mod version;