use std::sync::LazyLock;
use serde::Deserialize;
pub const EMBEDDED_MANIFEST_SCHEMA_VERSION: u32 = 1;
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ZcashdReleaseManifest {
pub schema_version: u32,
pub release_tag: String,
pub artifacts: Vec<ZcashdReleaseArtifact>,
}
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ZcashdReleaseArtifact {
pub target_triple: String,
pub runtime_archive_url: String,
pub runtime_archive_sha256: String,
pub runtime_archive_member_binary_path: String,
}
pub static EMBEDDED_ZCASHD_RELEASE_MANIFEST: LazyLock<ZcashdReleaseManifest> =
LazyLock::new(|| {
let manifest: ZcashdReleaseManifest =
serde_json::from_str(include_str!("../../../zcashd-compat-manifest.json"))
.expect("committed zcashd-compat-manifest.json is validated by unit tests and CI");
assert_eq!(
manifest.schema_version, EMBEDDED_MANIFEST_SCHEMA_VERSION,
"unsupported zcashd-compat-manifest.json schema version"
);
manifest
});
impl ZcashdReleaseManifest {
pub fn artifact_for_target(&self, target_triple: &str) -> Option<&ZcashdReleaseArtifact> {
self.artifacts
.iter()
.find(|artifact| artifact.target_triple == target_triple)
}
}
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use super::EMBEDDED_ZCASHD_RELEASE_MANIFEST;
#[test]
fn embedded_manifest_targets_are_unique() {
let mut targets = HashSet::new();
for artifact in &EMBEDDED_ZCASHD_RELEASE_MANIFEST.artifacts {
assert!(
targets.insert(artifact.target_triple.as_str()),
"duplicate manifest target found: {}",
artifact.target_triple
);
}
}
#[test]
fn embedded_manifest_entries_are_well_formed() {
for artifact in &EMBEDDED_ZCASHD_RELEASE_MANIFEST.artifacts {
assert!(
artifact.runtime_archive_url.starts_with("https://"),
"managed zcashd artifact URL must be https: {}",
artifact.runtime_archive_url
);
assert_eq!(
artifact.runtime_archive_sha256.len(),
64,
"artifact SHA256 must be 64 hex chars for target {}",
artifact.target_triple
);
assert!(
artifact
.runtime_archive_sha256
.chars()
.all(|c| c.is_ascii_hexdigit()),
"artifact SHA256 contains non-hex characters for target {}",
artifact.target_triple
);
}
}
}