aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-18 08:07:14 +0000
committerFuwn <[email protected]>2026-02-18 08:07:14 +0000
commit8259e4c8ddf604849d146905160dc693b1114b75 (patch)
tree97c2684d29b54d9b7b3ddba5c14ac697b8ed8418 /build.rs
parentchore(deps): Remove unused anyhow and disable comrak default features (diff)
downloadseptember-main.tar.xz
september-main.zip
chore(build): Replace vergen with git-based build scriptHEADmain
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs52
1 files changed, 49 insertions, 3 deletions
diff --git a/build.rs b/build.rs
index 2b8c3be..349f946 100644
--- a/build.rs
+++ b/build.rs
@@ -1,5 +1,51 @@
-fn main() -> Result<(), Box<dyn std::error::Error>> {
- vergen::EmitBuilder::builder().git_sha(true).emit()?;
+use std::{fs, path::Path, process::Command};
- Ok(())
+fn git_directory() -> Option<std::path::PathBuf> {
+ let directory = Path::new(".git");
+
+ if directory.is_dir() {
+ return Some(directory.to_path_buf());
+ }
+
+ let content = fs::read_to_string(directory).ok()?;
+ let path = Path::new(content.trim().strip_prefix("gitdir: ")?);
+
+ if path.is_absolute() {
+ Some(path.to_path_buf())
+ } else {
+ Some(directory.parent()?.join(path))
+ }
+}
+
+fn git_sha() -> Option<String> {
+ let output = Command::new("git").args(["rev-parse", "HEAD"]).output().ok()?;
+
+ if !output.status.success() {
+ return None;
+ }
+
+ let sha = String::from_utf8(output.stdout).ok()?.trim().to_string();
+
+ if sha.is_empty() { None } else { Some(sha) }
+}
+
+fn main() {
+ if let Some(git_dir) = git_directory() {
+ let head_path = git_dir.join("HEAD");
+
+ println!("cargo:rerun-if-changed={}", head_path.display());
+
+ if let Ok(head_contents) = fs::read_to_string(&head_path) {
+ if let Some(reference) = head_contents.trim().strip_prefix("ref: ") {
+ println!(
+ "cargo:rerun-if-changed={}",
+ git_dir.join(reference).display()
+ );
+ }
+ }
+ }
+
+ let sha = git_sha().unwrap_or_else(|| "UNKNOWN".to_string());
+
+ println!("cargo:rustc-env=VERGEN_GIT_SHA={sha}");
}