From a1ca1a46abf7b8edeca998dc0d610449d4515709 Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sun, 22 Jun 2025 18:56:17 +1000 Subject: [PATCH] dep: Replace vergen with vergen-gitcl (#2207) * dep: Bump vergen to 9.0.6 Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Replace vergen with vergen-gitcl Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix vergen-gitcl dep req Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix use of vergen_gitcl in build.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix build.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix build.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix fmt in build.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Fix fmt in build.rs Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> * Print out newly installed cargo-binstall version verbose in self-install.sh Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> --------- Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> --- crates/bin/Cargo.toml | 2 +- crates/bin/build.rs | 46 ++++++++++++++++++++++++++++----------- e2e-tests/self-install.sh | 2 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/crates/bin/Cargo.toml b/crates/bin/Cargo.toml index 23dcd7a7..d454e619 100644 --- a/crates/bin/Cargo.toml +++ b/crates/bin/Cargo.toml @@ -49,7 +49,7 @@ zeroize = "1.8.1" [build-dependencies] embed-resource = "3.0.1" -vergen = { version = "8.2.7", features = ["build", "cargo", "git", "gitcl", "rustc"] } +vergen-gitcl = { version = "1.0.8", features = ["build", "cargo", "rustc"] } [features] default = ["static", "rustls", "trust-dns", "fancy-no-backtrace", "zstd-thin", "git"] diff --git a/crates/bin/build.rs b/crates/bin/build.rs index 617c8d87..6f08aa57 100644 --- a/crates/bin/build.rs +++ b/crates/bin/build.rs @@ -12,6 +12,8 @@ fn succeeds(res: io::Result) -> bool { } fn emit_vergen_info() { + use vergen_gitcl::*; + let git = Command::new("git").arg("--version").spawn(); // .git is usually a dir, but it also can be a file containing @@ -21,24 +23,42 @@ fn emit_vergen_info() { // should exists. let is_git_repo = Path::new("../../.git").exists(); - let mut builder = vergen::EmitBuilder::builder(); - builder.all_build().all_cargo().all_rustc(); - - if is_git_repo && succeeds(git) { - builder.all_git(); - } else { - builder.disable_git(); - } - - builder.emit().unwrap(); + Emitter::default() + .fail_on_error() + .add_instructions(&BuildBuilder::default().build_date(true).build().unwrap()) + .unwrap() + .add_instructions(&CargoBuilder::default().features(true).build().unwrap()) + .unwrap() + .add_instructions( + &RustcBuilder::default() + .semver(true) + .commit_hash(true) + .llvm_version(true) + .build() + .unwrap(), + ) + .unwrap() + .add_instructions(&{ + let mut gitcl_builder = GitclBuilder::default(); + if is_git_repo && succeeds(git) { + // sha(false) means enable the default sha output but not the short output + gitcl_builder.commit_date(true).sha(false); + } + gitcl_builder.build().unwrap() + }) + .unwrap() + .emit() + .unwrap(); } +const RERUN_INSTRUCTIONS: &str = "cargo:rerun-if-changed=build.rs +cargo:rerun-if-changed=manifest.rc +cargo:rerun-if-changed=windows.manifest"; + fn main() { thread::scope(|s| { let handle = s.spawn(|| { - println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-changed=manifest.rc"); - println!("cargo:rerun-if-changed=windows.manifest"); + println!("{RERUN_INSTRUCTIONS}"); embed_resource::compile("manifest.rc", embed_resource::NONE) .manifest_required() diff --git a/e2e-tests/self-install.sh b/e2e-tests/self-install.sh index e00f3538..4691ea42 100644 --- a/e2e-tests/self-install.sh +++ b/e2e-tests/self-install.sh @@ -10,5 +10,5 @@ export PATH="$CARGO_HOME/bin:$PATH" "./$1" --self-install -cargo binstall --help +cargo binstall -vV cargo install --list