canton_lf/lib.rs
1//! Daml-LF archive reader and decoder.
2//!
3//! The codegen front-end of the Canton Rust SDK: it reads a `.dar` and decodes
4//! its Daml-LF packages into the AST that `canton-codegen` lowers to IR and
5//! turns into Rust. Most users never call this crate directly — they run
6//! `canton-codegen-cli` (`dpm codegen-rust`).
7//!
8//! - [`Dar`] — the DAR **container** layer (zip + `MANIFEST.MF` → the raw
9//! Daml-LF bytes of the main package and its dependencies).
10//! - [`decode_all`] / [`decode_main_package`] — Daml-LF protobuf decode
11//! (LF 2.x → typed AST) with the interned-table resolvers.
12//!
13//! The decode is built **on the official `daml-lf-archive` schema**: the
14//! vendored `daml_lf.proto` / `daml_lf2.proto` under `proto/` are Digital
15//! Asset's own archive definitions (pinned to a Daml 3.3 snapshot), so the
16//! bytes→AST step is machine-generated from the authoritative source rather
17//! than hand-written. The interpretation on top (version dispatch, interning,
18//! reference resolution) is held to the official **JVM `daml-lf-archive`
19//! reader** by a conformance oracle: `tests/oracle.rs` renders the decoded
20//! type-signature surface and asserts byte-for-byte agreement with
21//! `tools/lf-oracle/LfOracle.scala`, which reads the same DAR through
22//! `com.daml:daml-lf-archive-reader` (the decoder Canton itself uses). No JVM
23//! is required to *use* the SDK or the codegen — the oracle is dev/CI-only.
24
25mod dar;
26mod decode;
27
28pub use dar::{Dar, DarError};
29pub use decode::{
30 DecodeError, decode_all, decode_main_package, decode_package, decode_payload,
31 imported_package_id, interned_dotted_name, interned_str, interned_type, package_name,
32 package_version,
33};
34
35/// The generated Daml-LF archive types, from the vendored `.proto` files:
36/// `pb::daml_lf` (the `Archive`/`ArchivePayload` wrapper) and
37/// `pb::daml_lf_2` (the LF 2 AST — `Package`, `Module`, `DefDataType`, …).
38/// These are the vendored schema, generated: they change whenever the schema
39/// is re-vendored for a newer Canton (a field added, an enum grown, a module
40/// renamed) and are exempt from the SemVer promise the hand-written API
41/// makes, as `canton-proto`'s types are (ADR-0002). Hidden from the rendered
42/// docs for that reason; they remain reachable for callers who want the raw
43/// archive.
44#[doc(hidden)]
45pub mod pb {
46 #![allow(
47 clippy::all,
48 clippy::pedantic,
49 missing_docs,
50 unreachable_pub,
51 clippy::doc_markdown
52 )]
53 include!(concat!(env!("OUT_DIR"), "/_daml_lf.rs"));
54}