tensor_wasm_snapshot/lib.rs
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright 2026 Craton Software Company
3
4//! Wasm + GPU memory snapshot and restore for fast cold-start.
5//!
6//! Craton TensorWasm captures combined Wasm linear memory, GPU device-side memory,
7//! and register-file state into a single zstd-compressed bincode blob that can
8//! be persisted, shipped between nodes, and reloaded on demand. The [`writer`]
9//! module produces blobs from a live [`writer::InstanceState`], while the
10//! [`reader`] module restores them with strict magic + version checking so
11//! malformed inputs are surfaced as errors rather than panics.
12//!
13//! See `FORMAT.md` in the crate root for the on-disk wire layout, version
14//! history, and the size caps that bound restore-time memory pressure.
15#![deny(missing_docs)]
16#![cfg_attr(docsrs, feature(doc_cfg))]
17
18// tensor-wasm-snapshot stores `usize` lengths in caps that exceed 2^31. Building on a
19// 32-bit target would silently truncate them and defeat the size-bounding
20// guarantees the reader makes. Fail the build instead.
21const _: () = assert!(
22 usize::BITS >= 64,
23 "tensor-wasm-snapshot requires a 64-bit target",
24);
25
26#[cfg(feature = "aead-at-rest")]
27#[cfg_attr(docsrs, doc(cfg(feature = "aead-at-rest")))]
28pub mod aead;
29pub mod format;
30pub mod reader;
31pub mod writer;
32
33pub use crate::format::{
34 SignatureKind, ED25519_SIG_LEN, ED25519_TRAILER_LEN, HMAC_SHA256_SIG_LEN,
35 SIGNATURE_KIND_ED25519, SIGNATURE_KIND_HMAC_SHA256, SIGNATURE_TRAILER_LEN, SNAPSHOT_VERSION_V2,
36 SNAPSHOT_VERSION_V3, V3_TRAILER_MAGIC, V3_TRAILER_MAGIC_LEN,
37};
38pub use crate::writer::{limits, payload_crc32, Snapshot, SnapshotMetadata};