-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We only need the version, build time, rust target triple, and git commit for the version command. These values can easily be generated with little code so we do not need an extra dependency for this. The main reason for this change is that vergen will fail if no git commit is found. On distro build systems this is often the case since they build from a source tar without the git repo. Instead of erroring we should just show an empty commit in the version output. Fixes #247 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
- Loading branch information
Showing
5 changed files
with
29 additions
and
143 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,7 +1,26 @@ | ||
use anyhow::Result; | ||
use vergen::{vergen, Config}; | ||
use chrono::Utc; | ||
use std::process::Command; | ||
|
||
fn main() -> Result<()> { | ||
fn main() { | ||
// Generate the default 'cargo:' instruction output | ||
vergen(Config::default()) | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
// get timestamp | ||
let now = Utc::now(); | ||
println!("cargo:rustc-env=BUILD_TIMESTAMP={}", now.to_rfc3339()); | ||
|
||
// get rust target triple from TARGET env | ||
println!( | ||
"cargo:rustc-env=BUILD_TARGET={}", | ||
std::env::var("TARGET").unwrap() | ||
); | ||
|
||
// get git commit | ||
let command = Command::new("git").args(&["rev-parse", "HEAD"]).output(); | ||
let commit = match command { | ||
Ok(output) => String::from_utf8(output.stdout).unwrap(), | ||
// if error, e.g. build from source with git repo, just show empty string | ||
Err(_) => "".to_string(), | ||
}; | ||
println!("cargo:rustc-env=GIT_COMMIT={}", commit); | ||
} |
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
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