//! Stages the web client bundle for embedding (feature `web-ui`, //! architecture/web-client.md): copies `cbd-web/dist` (the trunk //! output) into `OUT_DIR/webdist`, or generates a placeholder page //! when the bundle has not been built — a plain `cargo build` must //! neither fail nor require the wasm toolchain. Deliberately no //! cargo-in-cargo: this never invokes trunk itself. use std::path::Path; fn main() { // Rerun when the bundle changes (or appears). println!("cargo:rerun-if-changed=../cbd-web/dist"); if std::env::var_os("CARGO_FEATURE_WEB_UI").is_none() { return; } let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is set for build scripts"); let staged = Path::new(&out_dir).join("webdist"); // Start fresh so removed assets do not linger across builds. if staged.exists() { std::fs::remove_dir_all(&staged).expect("clean staged webdist"); } std::fs::create_dir_all(&staged).expect("create staged webdist"); let dist = Path::new(env!("CARGO_MANIFEST_DIR")).join("../cbd-web/dist"); if dist.join("index.html").is_file() { copy_dir(&dist, &staged); } else { println!( "cargo:warning=cbd-web/dist not found - embedding a placeholder web UI \ (build the bundle with: devenv shell -- build-web)" ); std::fs::write( staged.join("index.html"), "
This server binary was compiled without the web bundle. \
Build it with devenv shell -- build-web and \
rebuild the server.