Files
jyviko d063e81eff Format machinery and design container in a shared crate: solidcraft-format (#14997)
* Format machinery in a shared crate: solidcraft-format, designs and drawings registered with it

What every versioned file format needs moves out of crates/doc into the new shared crate
`solidcraft-format` (crates/format, serde_json only): a family's format tag and its legacy tag,
the version registry (the hand-written steps, then one `v<N>/` folder per format with a file per
change, then the pending changes that make the next number), reading a file's format and its
`format_pending`, telling a file a newer build wrote, the upgrade that runs each step once, and,
for a build script, the generated lists of the change files (`build::lists`). Steps are
JSON-level and return the app's own error; the crate's refusals are `FormatError`, which
`DocError` takes as `Invalid` with the same text.

crates/doc keeps everything that is SolidCraft's: its 22 hand-written steps and their history,
every v*/ and pending/ change file unchanged, the DESIGN and DRAWING families (now values of the
shared type, with the app's name for messages), the one alias a format-29 design may carry for
the engineering material cards (now data on the family instead of a rule in the machinery),
`read`, `decode` and every check, and newer_file. `format::Family`, `Newer`, `FORMAT`,
`format_string`, `version_of` and `pending_names` keep their names, so no caller changes; the
number range check of a family's file is doc's own (`CheckNumbers`). build.rs lists the change
files through the shared crate and keeps its FAMILIES for the release script.

Nothing about reading or writing a file changes: the same steps run in the same order, with the
same messages and the same generated lists. The format tests that built a `Formats` and called
its upgrade now build the family around it (`Family { formats, ..DESIGN }`) and call the
family's, with the same expectations. The crate has its own tests of the registry and the
upgrade, and a README; xtask's layer table lists it as shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* Shared format crate: newer-file keeping and the ZIP container, SolidCraft's design on them

Two more pieces of the file machinery move into `solidcraft-format`, each with what is SolidCraft's
left in its app crates:

- `newer`: opening a file a newer build saved without losing what this build can't read.
  `NewerFile` (its notice, warnings and report, worded with the app's name), the comparison of
  the file with what was read of it and the putting back on saving (`compare`, `restore_into`),
  the sections and list elements left out and kept (`keep_section`, `keep_element`,
  `leave_out_unreadable`, `read_around`). crates/doc keeps what is a design's: a feature it can't
  read stays on the timeline as a placeholder, a parameter is left out, the sections a design
  can't open without, the fields a container adds; `newer_file::NewerFile` is the shared type
  and `newer_file::newer_file(&newer)` makes one for SolidCraft.
- `container`: the ZIP package (`Writer`, `Reader`): parts never extracted to paths, the
  directory checked on opening, content-addressed blobs `blobs/<sha256>.<ext>` hash-checked when
  read, every size within the app's `Limits`, room for optional caches, `Compression`, and the
  `Thumbnail` keyed to its file. crates/io keeps its budgets (the preference-driven limits, the
  STEP and mesh rules), the payload encodings (meshes, point clouds), the HDR and texture
  manifests, the model cache, the preview's meshes and its container tag; `DesignCompression` is
  the shared `Compression`, and the shared crate's refusals read as a design container's.

Files are read and written as before, byte for byte: the same parts, names, levels and keys, the
same checks in the same order, the same messages. The io and doc tests are unchanged. The shared
crate has its own tests of the container (parts, blobs, budgets, the thumbnail's key) and of
newer-file keeping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* io: the model cache key covers the shared format crate

The saved model is read through solidcraft-format now, so a change there must invalidate
cached models as a change in doc does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* Cargo.lock: solidcraft-format at the workspace's 0.40.0

The merge with main kept the new crate's lock entry at 0.40.0-rc.4 while
main's release moved the workspace to 0.40.0, so every --locked cargo call
refused to update the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

---------

Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 00:39:47 +00:00

25 lines
1.3 KiB
Rust

//! Lists the format changes of each family of files versioned by `src/format.rs`: designs in
//! `src/format/`, drawings in `src/drawing/format/` (#3890). One file per change, in `v<N>/` once a
//! release fixed its number, else in `pending/` (see `src/format/pending/README.md`). The lists are
//! generated (`solidcraft_format::build`) so that a change adds a file and never edits a line
//! another change also edits.
use std::path::PathBuf;
use solidcraft_format::build::Family;
/// Every family, each read by `scripts/fold-format-pending.sh` too. A design's upgrade steps are
/// written out in `format.rs` up to 22 (`JSON_STEPS`); a drawing's first format is 1.
const FAMILIES: [Family; 2] =
[Family { folder: "src/format", base: 22, list_prefix: "" }, Family { folder: "src/drawing/format", base: 1, list_prefix: "DRAWING_" }];
fn main() {
let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let lists = solidcraft_format::build::lists(&manifest, &FAMILIES).unwrap_or_else(|e| panic!("{e}"));
for folder in &lists.watch {
println!("cargo:rerun-if-changed={}", folder.display());
}
let dest = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("format_parts.rs");
std::fs::write(dest, lists.code).unwrap();
}