Skip to content

Commit 1d0e702

Browse files
committed
Add git hash to compiler versioning
1 parent b942c99 commit 1d0e702

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
name = "qcc"
33
version = "0.1.0"
44
edition = "2021"
5+
build = "build.rs"

build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::process::Command;
2+
use std::str;
3+
4+
fn main() {
5+
let revision = Command::new("git")
6+
.args(&["rev-parse", "--short", "HEAD"])
7+
.output()
8+
.expect("failed to run git");
9+
10+
if revision.status.success() {
11+
let hash = str::from_utf8(&revision.stdout).unwrap().trim();
12+
println!("cargo:rustc-env=GIT_HASH={}", hash);
13+
} else {
14+
println!("cargo:rustc-env=GIT_HASH=unknown");
15+
}
16+
}

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ pub struct Config {
1414
}
1515

1616
impl Config {
17+
#[inline]
1718
fn version() -> &'static str {
18-
env!("CARGO_PKG_VERSION") // + add latest commit hash
19+
concat!(env!("CARGO_PKG_VERSION"), "+", env!("GIT_HASH"))
1920
}
2021

2122
pub(crate) fn new() -> Self {

src/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub(crate) fn usage() {
4141
{:14}\t{:<20}
4242
{:14}\t{:<20}
4343
{:14}\t{:<20}
44+
{:14}\t{:<20}
4445
",
4546
"--help",
4647
"show this page",
@@ -61,7 +62,9 @@ pub(crate) fn usage() {
6162
"-d,--debug",
6263
"run compiler in debug-mode",
6364
"-o",
64-
"compiled output"
65+
"compiled output",
66+
"-v,--version",
67+
"compiler version"
6568
);
6669
}
6770

0 commit comments

Comments
 (0)