FeedTheMonkey/build.rs
Jeena 8db0b16954 scaffold: compile GSettings schema at build time for dev runs
build.rs now runs glib-compile-schemas on data/ so that debug builds
can find the schema without a system-wide install. main.rs sets
GSETTINGS_SCHEMA_DIR from the build-time constant when running in
debug mode.
2026-03-20 11:36:12 +00:00

58 lines
2.3 KiB
Rust

use std::path::PathBuf;
use std::process::Command;
fn main() {
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let data_dir = manifest_dir.join("data");
let ui_dir = data_dir.join("ui");
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
// Compile all .blp files to .ui files
let blp_files: Vec<_> = std::fs::read_dir(&ui_dir)
.expect("data/ui/ directory not found")
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|p| p.extension().map_or(false, |ext| ext == "blp"))
.collect();
for blp in &blp_files {
println!("cargo:rerun-if-changed={}", blp.display());
}
if !blp_files.is_empty() {
let status = Command::new("blueprint-compiler")
.arg("batch-compile")
.arg(&ui_dir)
.arg(&ui_dir)
.args(&blp_files)
.status()
.expect("failed to run blueprint-compiler — is it installed?");
assert!(status.success(), "blueprint-compiler failed");
}
// Compile GSettings schema into data/ so dev builds can find it
let schema_file = data_dir.join("net.jeena.FeedTheMonkey.gschema.xml");
println!("cargo:rerun-if-changed={}", schema_file.display());
let status = Command::new("glib-compile-schemas")
.arg(&data_dir)
.status()
.expect("failed to run glib-compile-schemas — is it installed?");
assert!(status.success(), "glib-compile-schemas failed");
println!("cargo:rustc-env=GSETTINGS_SCHEMA_DIR={}", data_dir.display());
// Compile GResource
let gresource_xml = data_dir.join("resources.gresource.xml");
println!("cargo:rerun-if-changed={}", gresource_xml.display());
let gresource_out = out_dir.join("feedthemonkey.gresource");
let status = Command::new("glib-compile-resources")
.arg(format!("--sourcedir={}", data_dir.display()))
.arg(format!("--sourcedir={}", manifest_dir.display()))
.arg(format!("--target={}", gresource_out.display()))
.arg(&gresource_xml)
.status()
.expect("failed to run glib-compile-resources — is it installed?");
assert!(status.success(), "glib-compile-resources failed");
println!("cargo:rustc-env=GRESOURCE_FILE={}", gresource_out.display());
}