Skip to main content

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, imported_package_id,
31    interned_dotted_name, interned_str, interned_type, package_name, package_version,
32};
33
34/// The generated Daml-LF archive types, from the vendored `.proto` files:
35/// `pb::daml_lf_dev` (the `Archive`/`ArchivePayload` wrapper) and
36/// `pb::daml_lf_2` (the LF 2 AST — `Package`, `Module`, `DefDataType`, …).
37pub mod pb {
38    #![allow(
39        clippy::all,
40        clippy::pedantic,
41        missing_docs,
42        unreachable_pub,
43        clippy::doc_markdown
44    )]
45    include!(concat!(env!("OUT_DIR"), "/_daml_lf.rs"));
46}