Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

fn main() {
let git_hash = Command::new("git")
.args(["describe", "--always", "--dirty"])
.output()
.map(|output| {
if output.status.success() {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
"unknown".to_string()
}
})
.unwrap_or_else(|_| "unknown".to_string());

let git_date = Command::new("git")
.args(["log", "-1", "--format=%cs"])
.output()
.map(|output| {
if output.status.success() {
String::from_utf8_lossy(&output.stdout).trim().to_string()
} else {
"unknown".to_string()
}
})
.unwrap_or_else(|_| "unknown".to_string());

// Make the git info available to the program
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!("cargo:rustc-env=GIT_DATE={}", git_date);

// Re-run build script if git HEAD changes
println!("cargo:rerun-if-changed=.git/HEAD");
}
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ use std::env;

use cargo_hyperlight::cargo;

const VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_HASH: &str = env!("GIT_HASH");
const GIT_DATE: &str = env!("GIT_DATE");

fn main() {
if env::args().any(|arg| arg == "--version" || arg == "-V") {
println!("cargo-hyperlight {} ({} {})", VERSION, GIT_HASH, GIT_DATE);
return;
}

let args = env::args_os().enumerate().filter_map(|(i, arg)| {
// skip the binary name and the "hyperlight" subcommand if present
if i == 0 || (i == 1 && arg == "hyperlight") {
Expand Down