Some checks failed
Run Check Script / check (pull_request) Failing after 59s
67 lines
2.7 KiB
Rust
67 lines
2.7 KiB
Rust
//! Best-effort Tailwind CSS build for the `web-frontend` feature.
|
|
//!
|
|
//! When the standalone `tailwindcss` v4 CLI is on PATH and the
|
|
//! `web-frontend` feature is on, this script generates the production
|
|
//! CSS bundle into `$OUT_DIR/tailwind.css`. The binary embeds that file
|
|
//! via `include_bytes!`.
|
|
//!
|
|
//! If the CLI is missing or fails we write an *empty* CSS file rather
|
|
//! than failing the build — the dev workflow uses
|
|
//! `serve-web --css-from <path>` to read Tailwind output from a sidecar
|
|
//! `tailwindcss --watch` process, so the embedded copy is irrelevant
|
|
//! there. Production builds should ensure `tailwindcss` is on PATH; the
|
|
//! warning below shows up in `cargo build` output when it is not.
|
|
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
fn main() {
|
|
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
|
let output = out_dir.join("tailwind.css");
|
|
|
|
if std::env::var_os("CARGO_FEATURE_WEB_FRONTEND").is_none() {
|
|
// Feature off — emit an empty placeholder so the `include_bytes!`
|
|
// path in src/frontend/assets.rs still compiles if anything
|
|
// references it (it should be cfg-gated, but belt-and-braces).
|
|
std::fs::write(&output, b"").unwrap();
|
|
return;
|
|
}
|
|
|
|
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
|
let input = manifest_dir.join("style/input.css");
|
|
|
|
println!("cargo:rerun-if-changed=style/input.css");
|
|
println!("cargo:rerun-if-changed=src/frontend");
|
|
println!("cargo:rerun-if-changed=src/service");
|
|
|
|
let status = Command::new("tailwindcss")
|
|
.arg("--input")
|
|
.arg(&input)
|
|
.arg("--output")
|
|
.arg(&output)
|
|
.arg("--minify")
|
|
.status();
|
|
|
|
match status {
|
|
Ok(s) if s.success() => {}
|
|
Ok(s) => {
|
|
println!(
|
|
"cargo:warning=tailwindcss exited with status {s}; embedded CSS will be empty. \
|
|
Install the v4 standalone CLI \
|
|
(https://github.com/tailwindlabs/tailwindcss/releases) for production builds, \
|
|
or use `serve-web --css-from <path>` against a `tailwindcss --watch` sidecar in dev."
|
|
);
|
|
std::fs::write(&output, b"").unwrap();
|
|
}
|
|
Err(e) => {
|
|
println!(
|
|
"cargo:warning=tailwindcss not invocable ({e}); embedded CSS will be empty. \
|
|
Install the v4 standalone CLI \
|
|
(https://github.com/tailwindlabs/tailwindcss/releases) for production builds, \
|
|
or use `serve-web --css-from <path>` against a `tailwindcss --watch` sidecar in dev."
|
|
);
|
|
std::fs::write(&output, b"").unwrap();
|
|
}
|
|
}
|
|
}
|