forked from casper-network/casper-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build.rs to eliminate vergen and gitoxide dependencies in the …
…node.
- Loading branch information
Zach Showalter
committed
Apr 29, 2024
1 parent
44e99ef
commit 0b5b283
Showing
1 changed file
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
use std::env; | ||
use std::{env, process::Command}; | ||
|
||
use vergen::EmitBuilder; | ||
const NODE_BUILD_PROFILE_ENV_VAR: &str = "NODE_BUILD_PROFILE"; | ||
|
||
const DEFAULT_BUILD_PROFILE: &str = "PROFILE"; | ||
|
||
/// | ||
/// `casper-node` build script to capture the git revision hash and export it to cargo to include | ||
/// it in the version information | ||
/// | ||
/// Notes: This script exports information to cargo via println! with the old invocation prefix of | ||
/// `cargo:`, if/when the node uses a Rust version `1.77` or above, this should be changed to | ||
/// `cargo::` as the prefix changed in that version of rust | ||
fn main() { | ||
if let Err(error) = EmitBuilder::builder().fail_on_error().git_sha(true).emit() { | ||
println!("cargo:warning={}", error); | ||
println!("cargo:warning=casper-node build version will not include git short hash"); | ||
} | ||
match Command::new("git") | ||
.arg("rev-parse") | ||
.arg("--short") | ||
.arg("HEAD") | ||
.output() | ||
{ | ||
Ok(output) => { | ||
//In the event the git command is successful, export the properly formatted git hash to | ||
// cargo at compile time. | ||
let git_hash_raw = | ||
String::from_utf8(output.stdout).expect("Failed to obtain commit hash to string"); | ||
let git_hash = git_hash_raw.trim_end_matches('\n'); | ||
|
||
// Make the build profile available to rustc at compile time. | ||
println!( | ||
"cargo:rustc-env=NODE_BUILD_PROFILE={}", | ||
env::var("PROFILE").unwrap() | ||
); | ||
println!( | ||
"cargo:rustc-env={}={}", | ||
NODE_BUILD_PROFILE_ENV_VAR, git_hash | ||
); | ||
} | ||
|
||
Err(error) => { | ||
println!("cargo:warning={}", error); | ||
println!("cargo:warning=casper-node build version will not include git short hash"); | ||
// In the event of an error, export the error, and export a default build profile to | ||
// cargo at compile time. | ||
println!( | ||
"cargo:rustc-env={}={}", | ||
NODE_BUILD_PROFILE_ENV_VAR, | ||
env::var(DEFAULT_BUILD_PROFILE).unwrap() | ||
); | ||
} | ||
} | ||
} |