Skip to content

Commit ef8cbd6

Browse files
authored
feat(torii): git hash and branch in torii version (#9)
* feat(torii): git hash and branch in torii version * fmt * remove dev
1 parent 38af5ad commit ef8cbd6

8 files changed

Lines changed: 127 additions & 57 deletions

File tree

Cargo.lock

Lines changed: 73 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/torii/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ anyhow.workspace = true
1111
clap.workspace = true
1212
tracing.workspace = true
1313
tracing-subscriber.workspace = true
14+
15+
[build-dependencies]
16+
vergen = "9.0.6"
17+
vergen-gitcl = "1.0.8"

bin/torii/build.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::env;
2+
use std::error::Error;
3+
4+
use vergen::{BuildBuilder, Emitter};
5+
use vergen_gitcl::GitclBuilder;
6+
7+
fn main() -> Result<(), Box<dyn Error>> {
8+
let build = BuildBuilder::default().build_timestamp(true).build()?;
9+
let gitcl = GitclBuilder::default()
10+
.describe(true, true, None)
11+
.branch(true)
12+
.sha(true)
13+
.build()?;
14+
15+
// Emit the instructions
16+
Emitter::default()
17+
.add_instructions(&build)?
18+
.add_instructions(&gitcl)?
19+
.emit_and_set()?;
20+
21+
let version = env!("CARGO_PKG_VERSION");
22+
let git_branch = env::var("VERGEN_GIT_BRANCH").unwrap_or("unknown".to_string());
23+
let git_sha = env::var("VERGEN_GIT_SHA").unwrap_or("unknown".to_string());
24+
let git_describe = env::var("VERGEN_GIT_DESCRIBE").unwrap_or("unknown".to_string());
25+
26+
let dev = git_describe.contains(&git_sha) || git_describe.contains("dirty");
27+
28+
let version = if dev {
29+
format!("{} ({} {})", version, git_branch, git_sha)
30+
} else {
31+
format!("{} ({})", version, git_sha)
32+
};
33+
println!("cargo:rustc-env=TORII_VERSION_SPEC={}", version);
34+
35+
Ok(())
36+
}

bin/torii/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clap::Parser;
77
use torii_cli::ToriiArgs;
88

99
#[derive(Parser)]
10-
#[command(name = "torii", author, version, about, long_about = None)]
10+
#[command(name = "torii", author, version = env!("TORII_VERSION_SPEC"), about, long_about = None)]
1111
pub struct Cli {
1212
#[command(flatten)]
1313
pub args: ToriiArgs,

0 commit comments

Comments
 (0)