diff --git a/ui/build.rs b/ui/build.rs index b9826ab..447a91f 100644 --- a/ui/build.rs +++ b/ui/build.rs @@ -1,38 +1,41 @@ use std::process::Command; - -use vergen::{vergen, Config}; +use std::str; fn main() { - println!("cargo:rerun-if-changed=./src"); + println!("cargo:rerun-if-changed=/src"); - // Save details from build environment so they can be included in the binary - vergen(Config::default()).unwrap(); + // Explicilty set variables because git isn't available + println!("cargo:rustc-env=GIT_VERSION={}", "v0.3.0"); + println!("cargo:rustc-env=GIT_COMMIT_HASH={}", "1044026"); + println!("cargo:rustc-env=VERGEN_CARGO_TARGET_TRIPLE=x86_64-gentoo-linux-gnu"); - if let Some(git_tag) = Command::new("git") - .args(["describe", "--exact-match", "--tags", "HEAD"]) + let rustc_output = Command::new("rustc") + .arg("--version") .output() - .ok() - .and_then(|output| String::from_utf8(output.stdout).ok()) - { - if !git_tag.is_empty() { - println!("cargo:rustc-env=GIT_VERSION={}", git_tag); - } - } + .expect("Failed to run rustc"); + if !rustc_output.status.success() { + panic!("Failed to get rustc version"); - if let Some(short_commit) = Command::new("git") - .args(["rev-parse", "--short", "HEAD"]) - .output() - .ok() - .and_then(|output| String::from_utf8(output.stdout).ok()) - { - println!("cargo:rustc-env=GIT_COMMIT_HASH={}", short_commit); + } + let rustc_output_str = str::from_utf8(&rustc_output.stdout).expect("Output is not valid UTF-8"); + let rustc_version = rustc_output_str + .lines() + .next() + .and_then(|line| line.split_whitespace().nth(1)); + match rustc_version { + Some(version_str) => { + println!("cargo:rustc-env=VERGEN_RUSTC_SEMVER={}", version_str) + } + None => { + panic!("Unable to parse rustc version"); + } } // Load icon data let out_dir = std::env::var_os("OUT_DIR").unwrap(); let dest_path = std::path::Path::new(&out_dir).join("icon_bytes"); let icon = image::io::Reader::open("../resources/icons/256x256.png") .expect("Failed to load icon file") .decode() .expect("Failed to decode icon file"); let icon_bytes = icon.as_bytes(); std::fs::write(dest_path, icon_bytes).expect("Failed to write icon bytes"); }