yggdrasil/lib.rs
1#![recursion_limit = "256"]
2#![doc(html_favicon_url = "/favicon.svg")]
3//! Yggdrasil 库目标:承载全部业务模块。
4//!
5//! 服务端二进制(`src/main.rs`)调用 [`startup::run`];浏览器 WASM 由 cargo-leptos
6//! 以 `hydrate` feature 编译本库,入口是文件末尾的 `hydrate()`。
7//! `server` 与 `hydrate` 互斥,不要同时开启。
8
9// 业务模块
10pub mod api;
11pub mod app;
12pub mod auth;
13pub mod bridges;
14// build_info:编译期注入的 git/rustc/构建时间信息。模块内部 gate 在 server feature,
15// 模块声明本身不需要再加 cfg(空模块在 WASM 端也能编译)。
16pub mod build_info;
17pub mod cache;
18pub mod components;
19// compression:响应压缩配置、Accept-Encoding 协商与编码器,server-only。
20#[cfg(feature = "server")]
21pub mod compression;
22pub mod config;
23pub mod context;
24pub mod db;
25// highlight 模块仅在服务端构建时编译
26#[cfg(feature = "server")]
27pub mod highlight;
28pub mod hooks;
29pub mod infra;
30// mcp:Model Context Protocol 服务器(/mcp Streamable HTTP,bearer token 鉴权)。
31// 仅 server feature 编译;WASM 前端不引用任何 mcp 符号。
32#[cfg(feature = "server")]
33pub mod mcp;
34// middleware:Axum 中间件与启动期纯函数(cache-control / admin 守卫 / 上一发布资源),
35// server-only。从 startup.rs 抽出以便独立测试,路由组装处以 crate::middleware::xxx 调用。
36#[cfg(feature = "server")]
37pub mod middleware;
38pub mod models;
39pub mod navigation;
40// og:分享图(og:image)渲染,字体随二进制嵌入,server-only。
41#[cfg(feature = "server")]
42pub mod og;
43pub mod pages;
44pub mod request_ctx;
45pub mod route_prefetch;
46pub mod routes;
47// ssr_cache 仅在 server feature 启用时编译;保存 SSR 世代号失效状态。
48#[cfg(feature = "server")]
49pub mod ssr_cache;
50// shutdown:SIGTERM 后通知长连接收尾,server-only。
51#[cfg(feature = "server")]
52pub mod shutdown;
53#[cfg(feature = "server")]
54pub mod startup;
55// static_assets:public/ 下固定路径资源的内容版本号,两端共用。
56pub mod static_assets;
57pub mod tasks;
58pub mod theme;
59pub mod utils;
60
61/// 浏览器端入口:懒加载路由的水合。
62#[cfg(feature = "hydrate")]
63#[wasm_bindgen::prelude::wasm_bindgen]
64pub fn hydrate() {
65 leptos::mount::hydrate_lazy(crate::app::App);
66}
67
68/// `--split` 的数据段腾挪余量。
69///
70/// wasm-split 会把只被某个分包引用的只读数据(页面文案、class 名、fixture 字符串)从主包的
71/// `.rodata` 挪进那个分包;但重新排布后每个分包的数据要按段对齐,总长度若超过输入 `.rodata`
72/// 哪怕几百字节,工具就放弃腾挪、把整段留在主包(实测超出 735 B,主包因此多背约 95 KB
73/// brotli 的后台/图鉴文案)。这个静态量保留在 `.rodata` 里却没有任何代码引用,不会被输出到
74/// 任何模块,等于给重新排布留出 16 KiB 余量。删掉它,`make test-release-split` 的体积门槛
75/// 会失败。
76#[cfg(feature = "hydrate")]
77#[used]
78static SPLIT_DATA_SLACK: [u8; 16384] = [0xA5; 16384];