Expand description
day-build — resource-constant codegen for a Day app’s build.rs (DESIGN.md §18.5).
An app’s build.rs calls generate_resources, which scans the project’s
resource/{images,assets,fonts} directories and writes typed symbolic constants to
$OUT_DIR/day_resources.rs:
pub mod images { use day::ImageName;
pub const nav_system: ImageName = ImageName::from_static("nav_system"); }
pub mod assets { use day::AssetName;
pub const numbers_bin: AssetName = AssetName::from_static("numbers.bin"); }
pub mod fonts { use day::FontFamily;
pub const pacifico: FontFamily = FontFamily::from_static("Pacifico"); }
pub mod locales { pub const DEFAULT: &str = "en";
pub const CATALOG: &[(&str, &str)] = &[("en", include_str!("…/en/app.ftl")), …];
pub const ALL: &[(&str, &str)] = &[("en", "English"), …]; // tag + self-name
pub fn install() { day::install_locales(DEFAULT, CATALOG) } }The app surfaces it once (pub mod res { include!(concat!(env!("OUT_DIR"), "/day_resources.rs")); })
and then writes image(res::images::nav_system) — a typo is a compile error and the resource is
guaranteed bundled. cargo:rerun-if-changed on each resource dir regenerates when a file is
added or removed.
This crate is also the canonical source of the resource-name → identifier rules: the CLI stagers
(day-cli/src/resources) reuse sanitize_ident and the derivation helpers here so the string
baked into a constant is exactly the name staged into each backend’s native store.
For the same reason it owns permissions: the CLI generates each platform’s permission
declarations from that table while day-part-permissions queries the same permissions at
runtime, and the two must never disagree (docs/permissions.md).
Modules§
- permissions
- The portable-permission → native-declaration table (docs/permissions.md).
Structs§
- Entry
- A single generated constant: its Rust
symbol, thevaluestring it wraps (the wire name the backend resolves by), and thesourcefile (for the doc comment). - FtlCall
- One
FUNC(...)call in a message value —day lintvalidates function names and option values across every locale file with this (the shared fluent-syntax parse, likemessage_keys). - Locale
Entry - One locale’s catalog: the directory name under
resource/locales/(the tag apps pass toset_locale) and every.ftlbeneath it, sorted. Multiple files concatenate into the single source string the Fluent bundle is built from. - Resource
Plan - The full set of constants to emit, grouped by bucket.
- StrEntry
- A generated localization function: the Fluent message
key(the Rust fn name), its sortedparams(each$variablethe message references, agreed across all locales), anddoc(the reference-locale value text, for the generated doc comment). - StrParam
- One generated function parameter: the Fluent
$variablename and whether it is used as a number (a plural/selectselector orNUMBER()argument) — which types it asIntoNumberFArginstead ofIntoFArg, so a string can’t be passed where a plural count is needed.
Functions§
- function_
calls - Every function call in every message of a Fluent resource (parse errors tolerated — the
partial resource is walked, matching
message_keys). - generate_
resources - The build-script entry point: scan
resource/{images,assets,fonts}underCARGO_MANIFEST_DIR, emit$OUT_DIR/day_resources.rs, and register the resource dirs forcargo:rerun-if-changed. ReturnsErr(with a fix hint) on a name that is not portable or a symbol collision — the appbuild.rsshould.expect(...)this so the problem fails the build loudly. - message_
keys - The message keys defined in a Fluent source (terms/attributes/comments ignored). Public so the
CLI lint (
day lintfluent coverage) shares this onefluent-syntaxparser with the codegen and the runtime resolver, instead of a hand-rolled line scanner. - plan_
resources - Scan and validate a project’s resources into a
ResourcePlan(the pure, testable core). - render
- Render a plan to the
day_resources.rssource text. This file isinclude!d inside the app’spub mod res { … }, so the lint waivers are outer attributes on each bucket module (an inner#![…]is not valid at aninclude!site) and cover a bucket with no constants (unuseduse). - sanitize_
ident - Sanitize a name to the strictest platform identifier rules (Android
R/ ArkUI): lowercase, only[a-z0-9_], forced leading letter. The canonical copy — the CLI stagers re-export this so the staged native name and the generated constant string agree by construction.