-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "build_utils" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::io::Write; | ||
use std::{env, fs::File, path::Path, process::Command}; | ||
|
||
pub fn git_description() { | ||
let output = Command::new("git") | ||
.args(["describe", "--dirty"]) | ||
.output() | ||
.expect("Failed to execute git command"); | ||
|
||
let git_description = String::from_utf8(output.stdout).unwrap(); | ||
|
||
// Write the git description to a file which will be included in the crate | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let dest_path = Path::new(&out_dir).join("git_description.rs"); | ||
let mut f = File::create(dest_path).unwrap(); | ||
writeln!( | ||
f, | ||
"pub fn git_description() -> &'static str {{\"{}\"}}", | ||
git_description | ||
) | ||
.unwrap(); | ||
} |