Skip to content

Commit

Permalink
add the actual utils!
Browse files Browse the repository at this point in the history
  • Loading branch information
zancas committed Sep 1, 2023
1 parent d4ea4db commit 5d4f27d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build_utils/Cargo.toml
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]
22 changes: 22 additions & 0 deletions build_utils/src/lib.rs
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();
}

0 comments on commit 5d4f27d

Please sign in to comment.