use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
const COMPATIBILITY_TOML: &str = include_str!("../compatibility.toml");
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Pin {
pub version: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub note: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Compatibility {
#[serde(rename = "tested-against", default)]
pub tested_against: BTreeMap<String, Pin>,
#[serde(default)]
pub runtime: BTreeMap<String, Pin>,
}
#[must_use]
pub fn compatibility() -> &'static Compatibility {
use std::sync::OnceLock;
static CACHE: OnceLock<Compatibility> = OnceLock::new();
CACHE.get_or_init(|| {
toml::from_str(COMPATIBILITY_TOML)
.expect("compatibility.toml is malformed — this is a build-time bug")
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn embedded_compatibility_parses() {
let c = compatibility();
assert!(
!c.tested_against.is_empty(),
"tested-against section must have at least one pin"
);
assert!(
c.tested_against.contains_key("surfpool"),
"surfpool pin is mandatory"
);
assert!(c.tested_against.contains_key("rust"));
}
#[test]
fn every_pin_has_a_version() {
let c = compatibility();
for (name, pin) in &c.tested_against {
assert!(
!pin.version.is_empty(),
"pin {name} has empty version string"
);
}
}
}