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§

bridge
daybridge codegen (docs/bridge.md, DESIGN.md §15.6) — the Rust half.
permissions
The portable-permission → native-declaration table (docs/permissions.md).
swiftui
SwiftUI view scanning + codegen for embedded SwiftPM packages (docs/swiftui.md).

Structs§

AssetNode
One directory level of the assets tree (§18.5). path is the folder’s /-relative path under resource/assets/ ("" at the root); each child directory renders as an AssetDir const AND a nested module sharing its name, so res::assets::web::minisite names the folder and res::assets::web::minisite::index_html a file within it.
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
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§

ftl_key_offsets
Every message key in a Fluent resource with the byte offset of its identifier — what turns a coverage finding into a diagnostic on the right line rather than on line 1.
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.
line_col
The 1-based line and column of a byte offset, for callers that report positions to a human or an editor. Columns count CHARACTERS rather than bytes, which is what an editor’s column means.
message_keys
offset_in
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). Byte offset of part within src, when part is a SUBSLICE of it.
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).
res_str_ident
The message keys defined in a Fluent source (terms/comments ignored — and ATTRIBUTES too: a locale that omits menu_group.key deliberately inherits the default locale’s shortcut, so the coverage lint must not demand attributes everywhere). 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. The res::str function name a localization key generates.
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.