euv_cli/hot/struct.rs
1use super::*;
2
3/// Filesystem modification stamp used for deterministic cross-platform change detection.
4#[derive(Clone, Copy, Debug, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
5pub struct FileStamp {
6 /// Nanoseconds since UNIX epoch of last file modification.
7 #[get(type(copy))]
8 pub(crate) modified_nanos: u128,
9 /// File byte length.
10 #[get(type(copy))]
11 pub(crate) size_bytes: u64,
12}
13
14/// Recursive file tree snapshot capturing stamps for all watched source files.
15#[derive(Clone, Debug, Default, Eq, Getter, PartialEq)]
16pub struct WatchSnapshot {
17 /// Ordered map from watched file paths to their modification stamps.
18 pub(crate) entries: BTreeMap<PathBuf, FileStamp>,
19}
20
21/// Categorized file changes detected between two consecutive `WatchSnapshot` scans.
22#[derive(Clone, Debug, Default, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
23pub struct FileChangeSet {
24 /// Newly created file paths.
25 pub(crate) added: Vec<String>,
26 /// Modified file paths.
27 pub(crate) modified: Vec<String>,
28 /// Deleted file paths.
29 pub(crate) removed: Vec<String>,
30}
31
32/// Signed Dynamic WASM OTA manifest served at `/__euv_ota/manifest.json`.
33#[derive(Clone, Debug, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
34pub struct OtaManifest {
35 /// Monotonically increasing hot-update version number.
36 #[get(type(copy))]
37 pub(crate) version: u64,
38 /// Target dynamic component slot identifier.
39 pub(crate) slot_id: String,
40 /// HTTP URL path serving the executable `.wasm` binary.
41 pub(crate) module_url: String,
42 /// FNV-1a integrity checksum of the `.wasm` bytes.
43 #[get(type(copy))]
44 pub(crate) checksum: u64,
45 /// Keyed integrity signature matching `OTA_DEV_SIGNING_KEY`.
46 pub(crate) signature: String,
47 /// Byte size of the compiled `.wasm` binary.
48 #[get(type(copy))]
49 pub(crate) size_bytes: usize,
50 /// Source files that triggered this hot-update build.
51 pub(crate) changed_files: Vec<String>,
52}
53
54/// In-memory pair holding the active OTA manifest and its executable `.wasm` bytes.
55#[derive(Clone, Debug, Eq, Getter, New, PartialEq)]
56pub struct OtaBundleState {
57 /// Public manifest metadata.
58 pub(crate) manifest: OtaManifest,
59 /// Raw executable `.wasm` binary bytes.
60 pub(crate) wasm_bytes: Vec<u8>,
61}
62
63/// Structured live-reload notification broadcast over SSE `/__euv_hmr`.
64#[derive(Clone, Debug, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
65pub struct HmrEvent {
66 /// Monotonic reload revision number.
67 #[get(type(copy))]
68 pub(crate) revision: u64,
69 /// Event kind (`Reload`, `OtaUpdate`, or `BuildError`).
70 #[get(type(copy))]
71 pub(crate) kind: HmrEventKind,
72 /// Human-readable status summary.
73 pub(crate) message: String,
74 /// Paths of changed files that triggered this event.
75 pub(crate) changed_files: Vec<String>,
76}
77
78/// Configuration for starting a live hot-reload and Dynamic WASM OTA development server.
79#[derive(Clone, Data, Debug, Deserialize, Eq, PartialEq, Serialize)]
80pub struct DevServerConfig {
81 /// Development target (`Docs`, `Web`, or `Native`).
82 #[get(type(copy))]
83 pub(crate) target: DevTargetArg,
84 /// Render mode forwarded to native or web runs.
85 #[get(type(copy))]
86 pub(crate) render: RenderArg,
87 /// Whether release optimization profile is enabled for Web or Native rebuilds.
88 #[get(type(copy))]
89 pub(crate) release: bool,
90 /// Source root directory watched for live changes.
91 pub(crate) src_dir: PathBuf,
92 /// Output directory served over HTTP.
93 pub(crate) out_dir: PathBuf,
94 /// Optional site title (used in Docs mode).
95 pub(crate) title: Option<String>,
96 /// Optional base URL prefix (used in Docs mode).
97 pub(crate) base_url: String,
98 /// Optional Cargo package name (used in Web/Native modes).
99 pub(crate) package: Option<String>,
100 /// Bind host address (default `127.0.0.1`).
101 pub(crate) host: String,
102 /// Bind TCP port (`0` selects an available ephemeral port).
103 #[get(type(copy))]
104 pub(crate) port: u16,
105 /// File watcher polling interval in milliseconds.
106 #[get(type(copy))]
107 pub(crate) poll_ms: u64,
108 /// Whether to expose Dynamic WASM OTA manifest and `.wasm` binary endpoints.
109 #[get(type(copy))]
110 pub(crate) enable_ota: bool,
111 /// When `true`, performs initial build and server check then exits immediately.
112 #[get(type(copy))]
113 pub(crate) once: bool,
114}
115
116/// Machine-readable report returned when starting or probing the dev/docs server.
117#[derive(Clone, Debug, Deserialize, Eq, Getter, New, PartialEq, Serialize)]
118pub struct DevServerReport {
119 /// Active dev mode (`docs`, `web`, or `native`).
120 pub(crate) mode: String,
121 /// Base HTTP URL of the live dev server.
122 pub(crate) url: String,
123 /// SSE hot-reload stream URL.
124 pub(crate) hmr_url: String,
125 /// Dynamic WASM OTA manifest URL.
126 pub(crate) ota_manifest_url: String,
127 /// Output bundle directory served by the dev server.
128 pub(crate) out_dir: String,
129 /// Initial build revision number.
130 #[get(type(copy))]
131 pub(crate) revision: u64,
132 /// Total generated documentation pages (for Docs mode, `0` otherwise).
133 #[get(type(copy))]
134 pub(crate) page_count: usize,
135}
136
137/// Shared concurrent state coordinating SSE reload notifications, OTA bundles, and server shutdown.
138#[derive(Debug)]
139pub struct HmrHub {
140 /// Monotonically incremented rebuild revision counter.
141 pub(crate) revision: AtomicU64,
142 /// Latest broadcast `HmrEvent`.
143 pub(crate) last_event: Mutex<Option<HmrEvent>>,
144 /// Latest signed Dynamic WASM OTA manifest and binary bytes.
145 pub(crate) ota_state: Mutex<OtaBundleState>,
146 /// Flag indicating whether background HTTP and watcher loops should keep running.
147 pub(crate) running: AtomicBool,
148}
149
150/// Running hot-reload dev server handle supporting clean programmatic shutdown and inspection.
151#[derive(Debug)]
152pub struct DevServerHandle {
153 /// Bound socket address (`ip:port`).
154 pub(crate) address: SocketAddr,
155 /// Served output directory path.
156 pub(crate) out_dir: PathBuf,
157 /// Active mode label (`docs`, `web`, `native`).
158 pub(crate) mode: String,
159 /// Initial page count produced during startup build.
160 pub(crate) page_count: usize,
161 /// Shared HMR and OTA state hub.
162 pub(crate) hub: Arc<HmrHub>,
163 /// Background HTTP/SSE/OTA server thread.
164 pub(crate) http_thread: Option<JoinHandle<()>>,
165 /// Background recursive file watcher and rebuild thread.
166 pub(crate) watch_thread: Option<JoinHandle<()>>,
167}
168
169/// Internal HTTP serving parameters shared across accepted connections.
170#[derive(Clone, Debug, Getter)]
171pub(crate) struct HttpServeContext {
172 /// Output root directory served over HTTP.
173 #[get(pub(crate))]
174 pub(crate) out_dir: PathBuf,
175 /// Optional base URL prefix stripped from incoming static requests.
176 #[get(pub(crate))]
177 pub(crate) base_url: String,
178 /// Whether Dynamic WASM OTA endpoints are exposed.
179 #[get(pub(crate), type(copy))]
180 pub(crate) enable_ota: bool,
181 /// Shared HMR and OTA state hub.
182 #[get(pub(crate))]
183 pub(crate) hub: Arc<HmrHub>,
184}