-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
34 lines (31 loc) · 906 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use git2::{DescribeFormatOptions, DescribeOptions, Error, Repository};
use std::io;
#[cfg(windows)]
use winres::WindowsResource;
fn main() -> io::Result<()> {
match get_git_describe_result() {
Ok(result) => println!("cargo::rustc-env=GIT_DESCRIBE={result}"),
Err(e) => println!("cargo::warning={}", e),
}
#[cfg(windows)]
{
WindowsResource::new()
.set_icon("assets/icon.ico")
.compile()?;
}
Ok(())
}
fn get_git_describe_result() -> Result<String, Error> {
let repo = Repository::open(".")?;
let describe = repo.describe(
DescribeOptions::new()
.describe_tags()
.show_commit_oid_as_fallback(true),
)?;
let formatted = describe.format(Some(
DescribeFormatOptions::new()
.always_use_long_format(true)
.dirty_suffix("-dirty"),
))?;
Ok(formatted)
}