//! Render `branding/agent-configs.svg` → `$OUT_DIR/agent-configs.png` //! at compile time so the daemon can `include_bytes!` the PNG without //! checking the raster into git (#424 mara: "generate png on the fly //! or in build"). The SVG is the source of truth; the PNG is a build //! artifact. //! //! Uses `rsvg-convert` from PATH (librsvg, already available in //! nixpkgs and added to the naersk derivation's `nativeBuildInputs` //! in `flake.nix`). For dev builds outside Nix, install librsvg via //! your system package manager (Debian/Ubuntu: `librsvg2-bin`, //! macOS: `brew install librsvg`). use std::env; use std::path::PathBuf; use std::process::Command; const SVG_PATH: &str = "../branding/agent-configs.svg"; const PNG_NAME: &str = "agent-configs.png"; // 300×300 to match the existing branding/hyperhive.png, which the // Forgejo avatar endpoint accepts without resizing on upload. const PX: &str = "300"; fn main() { // Re-run the build script when either the SVG itself or this // script change. We deliberately don't watch every file in // `branding/` — only the one PNG we generate. println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed={SVG_PATH}"); let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR set by cargo")); let png_path = out_dir.join(PNG_NAME); let status = Command::new("rsvg-convert") .args(["--width", PX, "--height", PX, "-o"]) .arg(&png_path) .arg(SVG_PATH) .status(); match status { Ok(s) if s.success() => {} Ok(s) => panic!("rsvg-convert exited with {s} rendering {SVG_PATH}"), Err(e) => panic!( "failed to invoke rsvg-convert: {e}\n\ install librsvg (Debian/Ubuntu: librsvg2-bin, macOS: brew install librsvg, \ NixOS: pkgs.librsvg). The Nix derivation already pulls it in via \ flake.nix → naersk-lib.buildPackage.nativeBuildInputs.", ), } }