Skip to main content

consortium_builder/
lib.rs

1// Copyright 2026 Ethan Wu
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// SPDX-License-Identifier: Apache-2.0
16
17//! Compiles, post-processes, and stages every artifact a `Consortium.toml` describes.
18//!
19//! `consortium-cfg` answers "what does this system look like, and is it valid?" and emits
20//! generated source. This crate answers "now actually build it": four compilers, a
21//! post-processing step remoteproc requires, and a staging tree a packaging recipe can
22//! consume.
23//!
24//! It stops short of deployment. Nothing here writes to a live target filesystem — the
25//! output is a local `dist/` tree plus an optional BitBake hand-off.
26//!
27//! # Layout
28//!
29//! | Module         | Role                                                        |
30//! | -------------- | ----------------------------------------------------------- |
31//! | [`pipeline`]   | The end-to-end `Consortium.toml` → `dist/` flow, stage by stage. |
32//! | `compile`      | One compiler per artifact kind, behind the [`Compiler`] trait. |
33//! | [`progress`]   | Reporting hooks the CLI uses to keep a step prompt visible.    |
34//!
35//! # The `Compiler` trait
36//!
37//! Firmware, the Linux application, the OP-TEE TA, and the HMI frontend are built by
38//! very different toolchains, but callers drive them identically: each implementor owns
39//! a `Configuration` carrying all its parameters, a typed `Error`, and an `Output`
40//! (usually the path to the built artifact). See [`Compiler`].
41//!
42//! # Plan, then run
43//!
44//! [`pipeline::plan`] resolves every stage's inputs — paths, env vars, artifact
45//! locations — **without running any build**, threading the data flow between stages.
46//! [`pipeline::run`] plans, then executes.
47//!
48//! That split is what makes the pipeline debuggable: a wrong sysroot or a missing
49//! firmware ELF surfaces as a planning failure naming the stage, rather than as a cargo
50//! error several minutes into a cross-compile.
51//!
52//! # Compile-time configuration
53//!
54//! Much of what generated code needs is passed as `CONSORTIUM_*` environment variables
55//! read with `option_env!`/`env!`, not as generated source. The carriers in
56//! `compile::env` describe what gets injected: [`SharedMemConfig`], [`DbgConfig`],
57//! [`HmiConfig`].
58//!
59//! Numeric values are emitted as **decimal strings**, so a firmware-side consumer that
60//! needs const parsing can use `const-str` without depending on the std-oriented schema
61//! crates. Note that there is deliberately no `CONSORTIUM_IPC_BASE`: controller firmware
62//! gets its region base baked into generated init code, and the Linux application reaches
63//! the same memory through its UIO device, so neither side needs the physical address
64//! from the environment.
65//!
66//! # Firmware post-processing
67//!
68//! Linux remoteproc expects a coprocessor's vector table in a section named
69//! `.isr_vectors`, but `cortex-m-rt` emits `.vector_table`. The pipeline renames it, and
70//! keeps the debug/original artifacts alongside the deployable ELF.
71//!
72//! # Staging
73//!
74//! The assembled tree can contain `app/`, `firmware/`, `ta/`, `www/`, `dts/linux/`,
75//! `kernel/`, `boot/`, and `systemd/`, plus a generated BitBake recipe. CLI flags can
76//! stage that tree into a recipe's `files/` directory and invoke or dry-run BitBake —
77//! the dry-run path exists for the split-machine flow, where `dist/` is produced on one
78//! host and the Yocto build runs on another.
79//!
80//! Keep the planning, compilation, staging, and external BitBake hand-off boundaries
81//! distinct when extending this crate; and prefer extending `consortium-cfg` lowering
82//! first, then the pipeline.
83
84mod compile;
85pub mod pipeline;
86pub mod progress;
87
88// Trait
89pub use compile::Compiler;
90pub use progress::{BuildReporter, BuildStep};
91
92// Deployment artifact rendering
93pub use compile::deploy::systemd::{
94    SystemdRestartPolicy, SystemdUnitConfig, render_unit as render_systemd_unit,
95    write_unit as write_systemd_unit,
96};
97
98// End-to-end pipeline
99pub use pipeline::{PipelineConfig, PipelineError, PipelinePlan, run as run_pipeline};
100
101// Compile-time environment-injection carriers
102pub use compile::env::{CortexMcuCore, DbgConfig, HmiConfig, SharedMemConfig};
103
104// Backward-compatible builders (String-error API)
105pub use compile::application::ApplicationBuilder;
106pub use compile::firmware::FirmwareBuilder;
107pub use compile::optee::{OpteeBuilder, OpteeEnvironment};
108
109// Typed compiler API
110pub use compile::application::{
111    ApplicationCompileError, ApplicationCompiler, ApplicationConfiguration,
112};
113pub use compile::firmware::{FirmwareCompileError, FirmwareCompiler, FirmwareConfiguration};
114pub use compile::optee::{OPTEE_TARGET, OpteeCompileError, OpteeCompiler, OpteeConfiguration};
115pub use compile::web::{HmiBuildCommand, HmiCompileError, HmiCompiler, HmiConfiguration};