Skip to content
Permalink
Browse files

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...
xobs committed Oct 29, 2018
1 parent d272679 commit 49287f86c8401753973f7a72b196853148b20c0c
Showing with 30 additions and 1 deletion.
  1. +28 −0 build.rs
  2. +2 −1 src/main.rs
@@ -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");
}
@@ -44,7 +44,8 @@ fn main() {
}).expect("Error setting Ctrl-C handler");

let matches = App::new("Exclave Testing System")
.version("1.0")
.version(env!("CARGO_PKG_VERSION"))
.long_version(env!("GIT_VERSION"))
.author("Sean Cross <sean@xobs.io>")
.about("Orchestrates the Common Factory Test Interface server")
.arg(

0 comments on commit 49287f8

Please sign in to comment.
You can’t perform that action at this time.