From 73e0d2e21a22a07718681ee2d58b1e4688b8b35d Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Mon, 22 Apr 2024 19:55:38 -0400 Subject: [PATCH] fix: don't require whiskers in build.rs --- Cargo.toml | 2 +- build.rs | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd8e355..64f7546 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/catppuccin/egui" license = "MIT" keywords = ["egui", "catppuccin", "theme", "gui"] categories = ["gui"] -exclude = ["assets/"] +exclude = ["assets/", "src/themes.rs.tera"] [dependencies] egui26 = { version = "0.26", package = "egui", default-features = false, optional = true } diff --git a/build.rs b/build.rs index c840fc1..e2b8e73 100644 --- a/build.rs +++ b/build.rs @@ -1,16 +1,32 @@ -use std::{fs::OpenOptions, process::Command}; +use std::{fs, path::Path, process::{Command, ExitCode}}; -fn main() { +fn main() -> ExitCode { println!("cargo::rerun-if-changed=src/themes.rs.tera"); - let fh = OpenOptions::new() + + // src/themes.rs.tera is excluded from the distributed crate so whiskers is + // not run if the crate is used as a dependency. + if !Path::new("src/themes.rs.tera").exists() { + return ExitCode::SUCCESS; + } + + let outfile = fs::OpenOptions::new() .write(true) .create(true) .open("src/themes.rs") .unwrap(); - let stat = Command::new("whiskers") + + let Ok(stat) = Command::new("whiskers") .arg("src/themes.rs.tera") - .stdout(fh) + .stdout(outfile) .status() - .unwrap(); - assert!(stat.success()); + else { + println!("cargo::warning=Failed to run whiskers (https://github.com/catppuccin/toolbox/tree/main/whiskers). Is it installed?"); + return ExitCode::SUCCESS; + }; + + if !stat.success() { + println!("cargo::warning=whiskers exited nonzero"); + return ExitCode::FAILURE; + } + return ExitCode::SUCCESS; }