1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-29 21:44:24 +03:00
wezterm/wezterm-version/build.rs
Wez Furlong 5e5989f3e2
build: revise dep graph for version changes
Previously, the config crate would get rebuilt each time the
git state changed, which has a lot of fan out and makes the build
take longer than it really needs to.

This commit breaks out the version changing stuff to its own crate
and then provides a runtime mechanism for assigning the version
information back into the config crate.

The env-bootstrap crate is responsible for setting that up.
2023-04-08 17:03:03 -07:00

54 lines
1.9 KiB
Rust

fn main() {
println!("cargo:rerun-if-changed=build.rs");
// If a file named `.tag` is present, we'll take its contents for the
// version number that we report in wezterm -h.
let mut ci_tag = String::new();
if let Ok(tag) = std::fs::read("../.tag") {
if let Ok(s) = String::from_utf8(tag) {
ci_tag = s.trim().to_string();
println!("cargo:rerun-if-changed=../.tag");
}
} else {
// Otherwise we'll derive it from the git information
if let Ok(repo) = git2::Repository::discover(".") {
if let Ok(ref_head) = repo.find_reference("HEAD") {
let repo_path = repo.path().to_path_buf();
if let Ok(resolved) = ref_head.resolve() {
if let Some(name) = resolved.name() {
let path = repo_path.join(name);
if path.exists() {
println!(
"cargo:rerun-if-changed={}",
path.canonicalize().unwrap().display()
);
}
}
}
}
if let Ok(output) = std::process::Command::new("git")
.args(&[
"-c",
"core.abbrev=8",
"show",
"-s",
"--format=%cd-%h",
"--date=format:%Y%m%d-%H%M%S",
])
.output()
{
let info = String::from_utf8_lossy(&output.stdout);
ci_tag = info.trim().to_string();
}
}
}
let target = std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());
println!("cargo:rustc-env=WEZTERM_TARGET_TRIPLE={}", target);
println!("cargo:rustc-env=WEZTERM_CI_TAG={}", ci_tag);
}