Skip to content

Commit

Permalink
Add build script to determine version number from git tag, and make s…
Browse files Browse the repository at this point in the history
…ure clap knows where to find it
  • Loading branch information
TCatshoek committed Feb 9, 2023
1 parent 4bd7198 commit a22e9b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::process::{Command, exit};

fn main() {
let version = Command::new("git")
.args(&["describe", "--tags", "--always"])
.output()
.unwrap_or_else(|_| {
println!("cargo:warning=VERSION=Unknown");
println!("cargo:rustc-env=VERSION=Unknown");
exit(0);
});

let version = String::from_utf8(version.stdout)
.unwrap()
.trim()
.to_owned();

println!("cargo:rustc-env=VERSION={}", version);
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::Deserialize;

/// Build a database
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(author, version = env!("VERSION", "No version number set"), about, long_about = None)]
struct Args {
///Path to the log entries to show in table
#[clap(short, long)]
Expand Down

0 comments on commit a22e9b0

Please sign in to comment.