Skip to main content

cargo_version_info/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// Command implementations and argument types.
4///
5/// # Example: Using in `build.rs` to set `CARGO_PKG_VERSION`
6///
7/// Add `cargo-version-info` as a build dependency in your `Cargo.toml`:
8///
9/// ```toml
10/// [build-dependencies]
11/// cargo-version-info = { version = "0.0.1", default-features = false }
12/// ```
13///
14/// Then in your `build.rs`:
15///
16/// ```no_run
17/// use cargo_version_info::commands::compute_version_string;
18///
19/// fn main() {
20///     if let Ok(version) = compute_version_string(".") {
21///         println!("cargo:rustc-env=CARGO_PKG_VERSION={}", version);
22///         println!("cargo:rerun-if-changed=.git/HEAD");
23///         println!("cargo:rerun-if-changed=.git/refs");
24///     }
25/// }
26/// ```
27///
28/// This will override `CARGO_PKG_VERSION` with the computed version based on:
29/// 1. `BUILD_VERSION` env var (highest priority, set by CI)
30/// 2. GitHub API (in GitHub Actions)
31/// 3. Cargo.toml version + git SHA
32/// 4. Git SHA fallback (`0.0.0-dev-<sha>`)
33pub mod commands;
34/// GitHub helpers.
35pub mod github;
36/// Version helpers.
37pub mod version;