Add scss colors into rust via build-script, flesh out math evaluation in launcher, Restructure some code
This commit is contained in:
28
build.rs
28
build.rs
@@ -1,7 +1,35 @@
|
||||
use regex::Regex;
|
||||
use std::path::PathBuf;
|
||||
use std::{env, fs};
|
||||
|
||||
fn main() {
|
||||
glib_build_tools::compile_resources(
|
||||
&["resources"],
|
||||
"resources/resources.gresource.xml",
|
||||
"templates.gresource",
|
||||
);
|
||||
|
||||
let colors_path = "style/_colors.scss";
|
||||
|
||||
println!("cargo:rerun-if-changed={colors_path}");
|
||||
|
||||
let scss = fs::read_to_string(colors_path).expect("Failed to read SCSS colors");
|
||||
|
||||
let regex =
|
||||
Regex::new(r"(?m)^\s*\$([a-zA-Z_][a-zA-Z0-9_-]*)\s*:\s*(#[0-9a-fA-F]{3,8})\s*;").unwrap();
|
||||
|
||||
let mut generated = String::from("// Generated by build.rs. Do not edit\n\n");
|
||||
|
||||
for captures in regex.captures_iter(&scss) {
|
||||
let name = captures.get(1).unwrap().as_str();
|
||||
let value = captures.get(2).unwrap().as_str();
|
||||
|
||||
let constant_name = name.replace('-', "_").to_uppercase();
|
||||
|
||||
generated.push_str(&format!("pub const {constant_name}: &str = \"{value}\";\n"));
|
||||
}
|
||||
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
|
||||
fs::write(out_dir.join("theme.rs"), generated).expect("Failed to generate theme.rs");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user