Skip to main content

treeboot_core/
metadata.rs

1//! treeboot metadata.
2
3use serde::Serialize;
4use std::sync::OnceLock;
5
6/// treeboot spec version implemented by this crate.
7pub const SPEC_VERSION: &str = include_str!(concat!(
8    env!("CARGO_MANIFEST_DIR"),
9    "/assets/spec-version.txt"
10));
11
12/// treeboot package name used for product-level version reporting.
13pub const TREEBOOT_PACKAGE: &str = "treeboot";
14
15/// treeboot package version.
16///
17/// `treeboot` and `treeboot-core` package versions are intentionally released
18/// in lockstep.
19pub const TREEBOOT_VERSION: &str = env!("CARGO_PKG_VERSION");
20
21/// Bundled treeboot config JSON Schema.
22pub const CONFIG_SCHEMA_JSON: &str = include_str!(concat!(
23    env!("CARGO_MANIFEST_DIR"),
24    "/assets/config.schema.json"
25));
26
27/// Returns the bundled treeboot config JSON Schema.
28#[must_use]
29pub const fn config_schema_json() -> &'static str {
30    CONFIG_SCHEMA_JSON
31}
32
33/// treeboot version metadata.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
35pub struct VersionInfo {
36    /// Package name.
37    pub package: &'static str,
38    /// Package version.
39    pub version: &'static str,
40    /// Implemented treeboot spec version.
41    pub spec_version: &'static str,
42}
43
44/// Returns version metadata for a package implementing treeboot.
45#[must_use]
46pub const fn version_info(package: &'static str, version: &'static str) -> VersionInfo {
47    VersionInfo {
48        package,
49        version,
50        spec_version: SPEC_VERSION,
51    }
52}
53
54/// Returns product-level treeboot version metadata.
55#[must_use]
56pub const fn treeboot_version_info() -> VersionInfo {
57    version_info(TREEBOOT_PACKAGE, TREEBOOT_VERSION)
58}
59
60/// Returns the treeboot version summary used by CLI version flags.
61#[must_use]
62pub fn treeboot_version_summary() -> &'static str {
63    static SUMMARY: OnceLock<String> = OnceLock::new();
64
65    SUMMARY.get_or_init(|| format!("{TREEBOOT_VERSION} (spec {SPEC_VERSION})"))
66}