-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
5df8a91
commit 100a225
Showing
4 changed files
with
30 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,25 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
// Get the directory where the output will be placed. | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let dest_path = Path::new(&out_dir).join("git_commit.rs"); | ||
let mut f = File::create(&dest_path).unwrap(); | ||
|
||
// Use git to get the current commit hash. | ||
let git_output = Command::new("git") | ||
.args(["rev-parse", "HEAD"]) | ||
.output() | ||
.expect("Failed to execute git command"); | ||
|
||
let git_hash = String::from_utf8_lossy(&git_output.stdout).trim().to_string(); | ||
|
||
// Write the git hash to a file as a constant. | ||
writeln!(f, "pub const GIT_COMMIT: &str = \"{}\";", git_hash).unwrap(); | ||
println!("cargo:rerun-if-changed=.git/HEAD"); | ||
println!("cargo:rerun-if-changed=.git/index"); | ||
} |
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