Skip to main content

zccache_core/
lib.rs

1//! Core types and traits for zccache.
2//!
3//! This crate contains shared types, error definitions, path utilities,
4//! and configuration structures used across all zccache crates.
5
6pub mod config;
7pub mod error;
8pub mod path;
9pub mod version;
10
11pub use error::{Error, Result};
12pub use path::{normalize, normalize_for_key, normalize_msys_path, NormalizedPath};
13
14/// The version string from Cargo.toml (workspace version).
15///
16/// This is the single source of truth for the version that `zccache --version`
17/// prints (via clap's `#[command(version)]`). The test below ensures it stays
18/// in sync with `pyproject.toml`.
19pub const VERSION: &str = env!("CARGO_PKG_VERSION");
20
21#[cfg(test)]
22mod tests {
23    /// Ensures the root pyproject.toml declares version as dynamic (derived
24    /// from Cargo.toml at build time via setup.py). A hardcoded version would
25    /// drift from the workspace version and cause release mismatches.
26    #[test]
27    fn pyproject_version_is_dynamic() {
28        let workspace_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
29            .parent()
30            .expect("crates/ dir")
31            .parent()
32            .expect("workspace root");
33
34        let pyproject = std::fs::read_to_string(workspace_root.join("pyproject.toml"))
35            .expect("failed to read pyproject.toml");
36
37        assert!(
38            pyproject
39                .lines()
40                .any(|line| line.trim().contains("dynamic") && line.contains("version")),
41            "pyproject.toml must use dynamic = [\"version\"] (derived from Cargo.toml)"
42        );
43        assert!(
44            !pyproject.lines().any(|line| {
45                let t = line.trim();
46                t.starts_with("version")
47                    && t.contains('=')
48                    && t.contains('"')
49                    && !t.contains("dynamic")
50            }),
51            "pyproject.toml must not have a hardcoded version field"
52        );
53    }
54}