use std::path::PathBuf; use std::process::Command; // Same GResource embedding as ahfail-display: the sprites and the audio clip are // compiled into the binary, and ahfail_ui::animation looks them up through the // `ahfail_get_resource` symbol that glib-compile-resources generates. fn main() { let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let workspace_root = manifest_dir.join("../..").canonicalize().unwrap(); let assets_dir = workspace_root.join("assets"); let gresource_xml = assets_dir.join("ahfail.gresource.xml"); let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); let c_src = out_dir.join("ahfail-resources.c"); println!("cargo:rerun-if-changed={}", gresource_xml.display()); for entry in std::fs::read_dir(&assets_dir).unwrap() { println!("cargo:rerun-if-changed={}", entry.unwrap().path().display()); } let status = Command::new("glib-compile-resources") .args([ "--generate-source", "--target", c_src.to_str().unwrap(), "--sourcedir", assets_dir.to_str().unwrap(), gresource_xml.to_str().unwrap(), ]) .status() .expect("glib-compile-resources not found"); assert!(status.success(), "glib-compile-resources failed"); let gio = pkg_config::probe_library("gio-2.0").expect("gio-2.0 not found"); let mut build = cc::Build::new(); build.file(&c_src).flag_if_supported("-w"); for inc in &gio.include_paths { build.include(inc); } build.compile("ahfail_resources"); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); if target_os == "linux" { // The Wayland backend drives ext-session-lock-v1 through gtk-session-lock, // the same library gtklock uses. The X11 backend and PAM need libpam. pkg_config::probe_library("gtk-session-lock-0").expect( "gtk-session-lock not found (Arch: pacman -S gtk-session-lock)", ); println!("cargo:rustc-link-lib=pam"); } }