Skip to main content

arcbox_boot/
manifest.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Returns the schema version for a given asset version.
6///
7/// Schema version equals the major component of the asset version
8/// (e.g. "0.2.3" → 0, "1.0.0" → 1).
9pub fn schema_version_for(asset_version: &str) -> u32 {
10    asset_version
11        .split('.')
12        .next()
13        .and_then(|s| s.parse().ok())
14        .unwrap_or(0)
15}
16
17/// Top-level boot asset manifest.
18///
19/// Supports multiple target architectures and host-side binaries.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Manifest {
22    pub schema_version: u32,
23    pub asset_version: String,
24    pub built_at: String,
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub source_repo: Option<String>,
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub source_ref: Option<String>,
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub source_sha: Option<String>,
31    /// Per-architecture boot targets (e.g. "arm64", "x86_64").
32    pub targets: BTreeMap<String, Target>,
33    /// Host-side binaries downloaded to ~/.arcbox/bin/.
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub binaries: Vec<Binary>,
36}
37
38/// Boot target for a single architecture.
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct Target {
41    pub kernel: FileEntry,
42    pub rootfs: FileEntry,
43    pub kernel_cmdline: String,
44}
45
46/// A file entry with path and checksum.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct FileEntry {
49    pub path: String,
50    pub sha256: String,
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    pub version: Option<String>,
53}
54
55/// Host-side binary with per-architecture variants.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct Binary {
58    pub name: String,
59    pub version: String,
60    /// Per-architecture file entries (e.g. "arm64" -> { path, sha256 }).
61    pub targets: BTreeMap<String, BinaryTarget>,
62    /// Subdirectory under the VirtioFS share root (e.g. "kernel" → /arcbox/kernel/).
63    /// Defaults to "bin" when absent.
64    #[serde(default, skip_serializing_if = "Option::is_none")]
65    pub install_dir: Option<String>,
66}
67
68/// A single architecture variant of a binary.
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct BinaryTarget {
71    pub path: String,
72    pub sha256: String,
73}