mf2_build/lib.rs
1//! `mf2-build` — a directory of translated message resources to what an
2//! application ships: the manifest, one catalog per locale, and a generated
3//! Rust module.
4//!
5//! It runs from the `build.rs` of the crate that includes the generated
6//! module — `fn main() { mf2_build::run(); }`, which reads `mf2`'s features
7//! through `links` ([`run`]) — and from `mf2-cli`, reading the same
8//! [`Config`] both times so that the two can never disagree. Nothing here is
9//! linked into the client wasm.
10//!
11//! ```text
12//! locales/<tag>/*.mf2 ─▶ Loader ─▶ records ─▶ mf2-syntax ─▶ models
13//! │
14//! manifest ◀───┤ ids → MsgId, slots,
15//! │ markup, functions, hash
16//! lints (mf2 check) ◀──┤
17//! ▼
18//! fallbacks flattened
19//! ▼
20//! locale data sliced ─▶ mf2-catalog writer ─▶ .mf2b + .br/.gz
21//! ▼
22//! the generated Rust module
23//! ```
24//!
25//! # What 2.x promises here
26//!
27//! What an i18n crate's `build.rs` and a tool call: [`Build`] and what it
28//! returns ([`Outcome`], [`Published`], [`LocaleInfo`], [`Report`],
29//! [`Diagnostic`]), the `mf2.toml` it reads ([`Config`] and its parts), the
30//! client [`Features`], the lints ([`Lint`], [`Level`]) and the [`Error`].
31//! The pipeline — the modules below, which `mf2-cli` and the conformance
32//! crate reach into — is private or hidden from the documentation, and not
33//! promised (`docs/versioning.md`):
34//!
35//! | Module | What it does |
36//! |---|---|
37//! | `config` | `mf2.toml` |
38//! | `features` | the client feature set, from `CARGO_FEATURE_*` or `--features` |
39//! | `loader` | a locale's files to records: `.mf2` resources or flat JSON |
40//! | `lint` | the names and levels of `mf2 check`'s lints |
41//! | `corpus` | reading and parsing every locale, with errors placed in their files |
42//! | `manifest` | ids → `MsgId`, slots, markup, functions, the hash |
43//! | `check` | the lints themselves |
44//! | `slice` | the locale data a corpus needs |
45//! | `catalog` | one catalog per locale: fallbacks, compression, content hashes |
46//! | `codegen` | the generated Rust module |
47//! | `pseudo` | the pseudo-locales `en-XA` and `ar-XB` |
48//! | `build` | [`Build`], which runs all of it |
49//!
50//! # The user guide
51//!
52//! The [Rust MF2 book](https://evancarroll.github.io/rust-mf2/) is the user
53//! guide: how the crates fit together, web and native applications, the
54//! command line, and what 2.x promises.
55//! An application names this crate in its i18n crate's
56//! `[build-dependencies]`, and [`mf2`](https://docs.rs/mf2) in its
57//! `[dependencies]`.
58
59#![warn(missing_docs)]
60// docs.rs (`cargo xtask docs-rs`): each feature-gated item says which features it needs.
61#![cfg_attr(docsrs, feature(doc_cfg))]
62#![forbid(unsafe_code)]
63// `Error` carries a path and the error it wraps, which makes it wide. A build
64// returns one of these at most once per run, never in a loop, so keeping the
65// variants readable is worth more than the bytes.
66#![allow(clippy::result_large_err)]
67
68mod build;
69#[doc(hidden)]
70pub mod catalog;
71#[doc(hidden)]
72pub mod check;
73#[doc(hidden)]
74pub mod codegen;
75mod config;
76#[doc(hidden)]
77pub mod corpus;
78mod error;
79mod features;
80mod lint;
81#[doc(hidden)]
82pub mod loader;
83#[doc(hidden)]
84pub mod manifest;
85#[doc(hidden)]
86pub mod pseudo;
87mod report;
88mod run;
89#[doc(hidden)]
90pub mod slice;
91
92pub use build::{Build, Emit, LocaleInfo, Outcome, Published};
93/// What `mf2-cli` and the conformance crate read of the modules above,
94/// which are private: the client feature set's function and option tables,
95/// and where `mf2.toml` and `locales/` are.
96#[doc(hidden)]
97pub use config::FILE_NAME as CONFIG_FILE;
98#[doc(hidden)]
99pub use config::Layout;
100pub use config::{CatalogConfig, Config, DataSet, LocaleDataConfig, Missing, Strip};
101pub use error::{Error, Result};
102pub use features::Features;
103#[doc(hidden)]
104pub use features::{BUILTINS, CATALOG_FEATURES, OPTIONS, defines_option};
105pub use lint::{Level, Lint};
106#[doc(hidden)]
107pub use loader::{Loaded, Loader, Problem, Property, Record, SourceFile};
108/// The manifest a build derived from the source locale (`mf2-catalog`).
109#[doc(hidden)]
110pub use mf2_catalog::Manifest;
111pub use report::{Diagnostic, Report};
112pub use run::run;