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§
- Asset
Node - One directory level of the assets tree (§18.5).
pathis the folder’s/-relative path underresource/assets/(""at the root); each child directory renders as anAssetDirconst AND a nested module sharing its name, sores::assets::web::minisitenames the folder andres::assets::web::minisite::index_htmla file within it. - 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
- 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§
- 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}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. - 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 lintvalidates function names and option values across every locale file with this (the shared fluent-syntax parse, likemessage_keys). Byte offset ofpartwithinsrc, whenpartis 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.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). - res_
str_ ident - The message keys defined in a Fluent source (terms/comments ignored — and ATTRIBUTES too:
a locale that omits
menu_group.keydeliberately inherits the default locale’s shortcut, so the coverage lint must not demand attributes everywhere). 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. Theres::strfunction 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.