Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: include version number in final binary
Use git to parse the tag information, and include it in the output of `exclave --help`. Signed-off-by: Sean Cross <sean@xobs.io>
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::process::Command; | ||
|
||
/// Same as `set_env`, but using `name` as environment variable. | ||
/// | ||
/// You can, for example, override the `CARGO_PKG_VERSION` using in | ||
/// your `build.rs` script: | ||
/// | ||
/// ``` | ||
/// extern crate git_version; | ||
/// fn main() { git_version::set_env_with_name("CARGO_PKG_VERSION"); } | ||
/// ``` | ||
fn set_env_with_name(name: &str) { | ||
let cmd = Command::new("git") | ||
.args(&["describe", "--tags", "--dirty=-modified"]) | ||
.output() | ||
.unwrap(); | ||
assert!(cmd.status.success()); | ||
let ver = std::str::from_utf8(&cmd.stdout[..]).unwrap().trim(); | ||
println!("cargo:rustc-env={}={}", name, ver); | ||
println!("cargo:rerun-if-changed=.git/HEAD"); | ||
println!("cargo:rerun-if-changed=.git/index"); | ||
println!("cargo:rerun-if-changed=.git"); | ||
println!("cargo:rerun-if-env-changed={}", name); | ||
} | ||
|
||
fn main() { | ||
set_env_with_name("GIT_VERSION"); | ||
} |
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