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    use super::*;
24
25    /// Ensures the workspace Cargo.toml version and pyproject.toml version
26    /// are always in sync. A mismatch means `zccache --version` (from Cargo)
27    /// would disagree with the PyPI package version — which is a release bug.
28    #[test]
29    fn cargo_and_pyproject_versions_match() {
30        // Navigate from this crate's manifest dir to the workspace root.
31        let workspace_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
32            .parent()
33            .expect("crates/ dir")
34            .parent()
35            .expect("workspace root");
36
37        let pyproject = std::fs::read_to_string(workspace_root.join("pyproject.toml"))
38            .expect("failed to read pyproject.toml");
39
40        let pyproject_version = pyproject
41            .lines()
42            .find_map(|line| {
43                let line = line.trim();
44                if line.starts_with("version") {
45                    // Parse: version = "1.0.4"
46                    let (_, val) = line.split_once('=')?;
47                    Some(val.trim().trim_matches('"').to_string())
48                } else {
49                    None
50                }
51            })
52            .expect("pyproject.toml missing `version` field");
53
54        assert_eq!(
55            VERSION, pyproject_version,
56            "\n\nVersion mismatch!\n\
57             \n  Cargo.toml (workspace): {VERSION}\
58             \n  pyproject.toml:         {pyproject_version}\
59             \n\nThese must match. The Cargo workspace version is what `zccache --version`\n\
60             prints, and the pyproject.toml version is what gets published to PyPI.\n\
61             Update both files to the same version.\n"
62        );
63    }
64}