Skip to main content

webui_desktop_build/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3
4//! Build-time typed IPC bindings for WebUI desktop applications.
5
6mod artifacts;
7mod compiler;
8mod emit;
9mod error;
10mod evolution;
11mod model;
12mod names;
13
14use std::path::PathBuf;
15
16pub use error::GenerateError;
17
18/// Inputs and destinations for deterministic application IPC generation.
19#[derive(Clone, Debug)]
20pub struct GenerateConfig {
21    /// Application proto files (not the SDK options schema).
22    pub roots: Vec<PathBuf>,
23    /// Protobuf import search directories.
24    pub includes: Vec<PathBuf>,
25    /// Destination for `ipc.rs`, `ipc_messages.rs`, and generated payload codecs.
26    pub rust_out: PathBuf,
27    /// Destination for `ipc.ts`, `ipc-runtime.ts`, and generated payload codecs.
28    pub ts_out: PathBuf,
29    /// Checked-in compatibility history, conventionally `ipc-schema.lock.json`.
30    pub lock_file: PathBuf,
31    /// Compare all artifacts without modifying existing files.
32    pub check: bool,
33    /// Explicit protoc executable, otherwise `PROTOC`, then `protoc` on PATH.
34    pub protoc: Option<PathBuf>,
35}
36
37/// Successfully generated (or verified) artifact destinations.
38#[derive(Clone, Debug)]
39pub struct GeneratedFiles {
40    /// All Rust output files.
41    pub rust: Vec<PathBuf>,
42    /// All TypeScript output files.
43    pub typescript: Vec<PathBuf>,
44    /// Normalized semantic manifest.
45    pub manifest: PathBuf,
46    /// Inventory used to detect and remove obsolete generated modules.
47    pub inventory: PathBuf,
48    /// Compatibility history.
49    pub lock_file: PathBuf,
50    /// SHA-256 of the normalized contract, shared by both endpoints.
51    pub schema_hash: String,
52}
53
54/// Compile, validate, and generate one coherent Rust/TypeScript IPC contract.
55///
56/// Requires installed protoc. No tools are downloaded.
57/// `check` reports drift without rewriting output or compatibility history.
58pub fn generate(config: &GenerateConfig) -> Result<GeneratedFiles, GenerateError> {
59    compiler::generate(config)
60}