Skip to content

Commit

Permalink
git describe
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Aug 28, 2024
1 parent 0b46ae1 commit 7e4d5d5
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 1 deletion.
162 changes: 162 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition = "2021"

[dependencies]

[build-dependencies]
git2 = { version = "0.19.0", default-features = false }

[profile.release]
strip = "symbols"
lto = "fat"
Expand Down
24 changes: 24 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use git2::{DescribeFormatOptions, DescribeOptions, Repository};

fn main() {
let Ok(repo) = Repository::open(".") else {
return;
};
let Ok(git_describe_result) = repo
.describe(
DescribeOptions::new()
.describe_tags()
.show_commit_oid_as_fallback(true),
)
.and_then(|describe| {
describe.format(Some(
DescribeFormatOptions::new()
.always_use_long_format(true)
.dirty_suffix("-dirty"),
))
})
else {
return;
};
println!("cargo::rustc-env=GIT_DESCRIBE={git_describe_result}")
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
println!("Hello, world!!!");
println!("Hello, world!!! - {}", env!("GIT_DESCRIBE"));
if cfg!(target_os = "macos") {
println!("You are running macos!");
} else if cfg!(target_os = "linux") {
Expand Down

0 comments on commit 7e4d5d5

Please sign in to comment.