islands_build/lib.rs
1//! # islands-build — the islands.rs build pipeline, as a library
2//!
3//! Everything needed to **build** an islands.rs app, decoupled from any one
4//! repository's layout. A thin `xtask` (this repo's, or a downstream consumer's)
5//! constructs a [`BuildPlan`] — from an [`IslandsConfig`] (`islands.toml`) or its
6//! own discovery — and calls [`build`].
7//!
8//! The pipeline:
9//! 1. **WASM** ([`wasm::build_wasm`]): resolve + install the matching
10//! `wasm-bindgen-cli`, compile the runtime ([`wasm::build_runtime`]) and page
11//! crates to `wasm32-unknown-unknown`, run `wasm-bindgen --target web`, verify
12//! the artifacts, and apply the load-bearing [V8 namespace patch](patch).
13//! 2. **CSS** ([`css::build_css`]): build the shared `base.css` and a per-page
14//! Tailwind bundle for each page (optionally materializing `basecoat.css`).
15//! 3. **Manifest** ([`hashing::post_build_hashing_pass`], gated by
16//! [`BuildPlan::manifest`]): content-hash every asset, rewrite cross-asset
17//! references, and write `manifest.json`. Off ⇒ logical filenames, resolved by
18//! `page_shell`'s logical-path fallback.
19//!
20//! The [V8 namespace patch](patch) is exported as a first-class, tested API:
21//! skipping it produces a bundle the browser refuses to instantiate, so no
22//! consumer should ever have to rediscover it.
23
24pub mod config;
25pub mod css;
26pub mod discovery;
27pub mod hashing;
28pub mod manifest;
29pub mod patch;
30pub mod wasm;
31
32pub use config::{BuildPlan, CssConfig, PageBuild, RuntimeBuild};
33pub use css::{build_base_css, build_css, build_page_css};
34pub use discovery::IslandsConfig;
35pub use hashing::post_build_hashing_pass;
36pub use manifest::{BuildManifest, ManifestBundleEntry};
37pub use patch::{patch_page_js, patch_runtime_snippets, PATCH_TOKEN};
38pub use wasm::{build_page_wasm, build_runtime, build_wasm, wasm_bindgen_bundle};
39
40#[cfg(feature = "basecoat")]
41pub use css::materialize_basecoat_css;
42
43use anyhow::Result;
44
45/// Run the full build: WASM (runtime + pages) → CSS → (optional) content-hash +
46/// manifest.
47///
48/// Does **not** clean `out_dir` first — cleaning policy (which directories to
49/// wipe, which checked-in inputs to preserve) belongs to the caller.
50pub fn build(plan: &BuildPlan) -> Result<()> {
51 wasm::build_wasm(plan)?;
52 css::build_css(plan)?;
53 if plan.manifest {
54 hashing::post_build_hashing_pass(plan)?;
55 }
56 Ok(())
57}