//! Compile-time build information.
//!
//! Provides a `BuildStamp` struct populated by `env!` variables supplied by Cargo.
//! This is useful for embedding metadata into kernel images for diagnostics.
//!
//! No external dependencies are used; values may be empty if not provided.

/// Build metadata captured at compile time.
#[derive(Copy, Clone)]
pub struct BuildStamp {
    /// Package name.
    pub name: &'static str,
    /// Package version.
    pub version: &'static str,
    /// Optional git commit SHA (if set in the environment).
    pub git_sha: Option<&'static str>,
    /// Rust channel (if known).
    pub rust_channel: Option<&'static str>,
}

impl BuildStamp {
    /// Returns a `BuildStamp` with fields sourced from Cargo-provided environment.
    ///
    /// Available keys:
    /// - `CARGO_PKG_NAME`
    /// - `CARGO_PKG_VERSION`
    /// - `GIT_SHA` (user-defined; set via your build scripts or CI)
    /// - `RUST_CHANNEL` (user-defined; set via your CI tooling)
    pub const fn capture() -> Self {
        let name = env!("CARGO_PKG_NAME");
        let version = env!("CARGO_PKG_VERSION");
        // Optional environment variables cannot be read with `option_env!` in const,
        // so we construct lazily through helper associated consts.
        Self {
            name,
            version,
            git_sha: option_env!("GIT_SHA"),
            rust_channel: option_env!("RUST_CHANNEL"),
        }
    }
}

