Skip to main content

smolvm_pack/
lib.rs

1//! `.smolmachine` packaging for smolvm.
2//!
3//! This crate provides functionality to package an OCI image and all runtime assets
4//! into a portable `.smolmachine` artifact that can be pushed to a registry,
5//! distributed, and run without smolvm installed.
6//!
7//! See [`format`] for the full binary format specification.
8
9#![deny(missing_docs)]
10
11pub mod assets;
12pub mod detect;
13pub mod extract;
14pub mod format;
15#[cfg(target_os = "macos")]
16pub mod macho;
17pub mod packer;
18pub mod signing;
19
20pub use detect::{detect_packed_mode, PackedMode};
21pub use format::{
22    PackFooter, PackManifest, PackMode, SectionHeader, FOOTER_SIZE, MAGIC, SECTION_HEADER_SIZE,
23    SECTION_MAGIC, SIDECAR_EXTENSION,
24};
25pub use packer::{
26    read_footer, read_footer_from_sidecar, read_manifest, read_manifest_from_sidecar,
27    sidecar_path_for, verify_sidecar_checksum, Packer,
28};
29
30use thiserror::Error;
31
32/// Errors that can occur during pack operations.
33#[derive(Debug, Error)]
34pub enum PackError {
35    /// I/O error.
36    #[error("I/O error: {0}")]
37    Io(#[from] std::io::Error),
38
39    /// JSON serialization error.
40    #[error("JSON error: {0}")]
41    Json(#[from] serde_json::Error),
42
43    /// Invalid magic bytes in footer.
44    #[error("invalid magic: expected SMOLPACK")]
45    InvalidMagic,
46
47    /// Unsupported format version.
48    #[error("unsupported version: {0}")]
49    UnsupportedVersion(u32),
50
51    /// Checksum mismatch.
52    #[error("checksum mismatch: expected {expected:08x}, got {actual:08x}")]
53    ChecksumMismatch {
54        /// Expected checksum.
55        expected: u32,
56        /// Actual checksum.
57        actual: u32,
58    },
59
60    /// Asset not found.
61    #[error("asset not found: {0}")]
62    AssetNotFound(String),
63
64    /// Compression error.
65    #[error("compression error: {0}")]
66    Compression(String),
67
68    /// Signing error.
69    #[error("signing error: {0}")]
70    Signing(String),
71
72    /// Tar archive error.
73    #[error("tar error: {0}")]
74    Tar(String),
75}
76
77/// Result type for pack operations.
78pub type Result<T> = std::result::Result<T, PackError>;