Skip to main content

Crate day_build

Crate day_build 

Source
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, the value string it wraps (the wire name the backend resolves by), and the source file (for the doc comment).
FtlCall
One FUNC(...) call in a message value — day lint validates function names and option values across every locale file with this (the shared fluent-syntax parse, like message_keys).
LocaleEntry
One locale’s catalog: the directory name under resource/locales/ (the tag apps pass to set_locale) and every .ftl beneath it, sorted. Multiple files concatenate into the single source string the Fluent bundle is built from.
ResourcePlan
The full set of constants to emit, grouped by bucket.
StrEntry
A generated localization function: the Fluent message key (the Rust fn name), its sorted params (each $variable the message references, agreed across all locales), and doc (the reference-locale value text, for the generated doc comment).
StrParam
One generated function parameter: the Fluent $variable name and whether it is used as a number (a plural/select selector or NUMBER() argument) — which types it as IntoNumberFArg instead of IntoFArg, 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} under CARGO_MANIFEST_DIR, emit $OUT_DIR/day_resources.rs, and register the resource dirs for cargo:rerun-if-changed. Returns Err (with a fix hint) on a name that is not portable or a symbol collision — the app build.rs should .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 lint fluent coverage) shares this one fluent-syntax parser 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.rs source text. This file is include!d inside the app’s pub mod res { … }, so the lint waivers are outer attributes on each bucket module (an inner #![…] is not valid at an include! site) and cover a bucket with no constants (unused use).
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.