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 prebuild_project, the one entry point a Day project needs. It performs 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 both 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.
WindowGeometry
The window geometry Day.toml [window] declares, for the generated res::window_options(): size when it names width or height, min_size when it names min_width or min_height. A key left out takes the CLI’s default (480x640, minimum 320x400). No Day.toml, or no [window], declares nothing, and the window keeps WindowOptions’ own defaults.

Functions§

app_title
The app’s display title for embedding in its UI from build.rs.
ftl_key_offsets
Every message key in a Fluent resource with the byte offset of its identifier, which 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_locales
Generate private crate/file catalogs into day_locales.rs.
generate_resources
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
message_texts
Message key → value text for every message in a Fluent resource (attributes excluded; placeables rendered as { $var }), for tooling that reads a catalog message as data rather than as UI copy: the permission reasons day build writes into each platform’s manifest (docs/permissions.md, “Localized reasons”).
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.
pascal_case
items_moved → ItemsMoved: the name of a message’s argument struct.
plan_resources
Scan and validate a project’s resources into a ResourcePlan (the pure, testable core).
plan_resources_in
The same, given the resource tree itself rather than the project root: what a flavored build passes, because its tree is the merge of the app’s and the flavor’s and lives under build/.
prebuild_project
Everything a Day project’s build.rs has to do, in one call:
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).
render_app
render with the app’s Day.toml identity: its title for window_options() when the catalog has no app_title message, and its [window] geometry.
render_crate_locales
Pure code-generation entry point for crate catalogs. name is their diagnostic/script namespace.
res_str_ident
The message keys defined in a Fluent source (terms/comments ignored, and attributes too: a locale that omits menu_group.key 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.
window_geometry
Read WindowGeometry from the project’s Day.toml (registered for rerun by app_title).