Rust implementation of OCI Distribution Spec with granular access control

fix: embed build version via build.rs instead of relying on BUILD_VERSION env var

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+25 -10
+24
build.rs
··· 1 + use std::process::Command; 2 + 3 + fn main() { 4 + // Re-run if git HEAD changes (new commit) 5 + println!("cargo:rerun-if-changed=.git/HEAD"); 6 + println!("cargo:rerun-if-changed=.git/refs/heads/"); 7 + 8 + let version = env!("CARGO_PKG_VERSION"); 9 + 10 + let short_sha = Command::new("git") 11 + .args(["rev-parse", "--short", "HEAD"]) 12 + .output() 13 + .ok() 14 + .filter(|o| o.status.success()) 15 + .and_then(|o| String::from_utf8(o.stdout).ok()) 16 + .map(|s| s.trim().to_string()); 17 + 18 + let full_version = match short_sha { 19 + Some(sha) => format!("{}-{}", version, sha), 20 + None => version.to_string(), 21 + }; 22 + 23 + println!("cargo:rustc-env=GRAIN_VERSION={}", full_version); 24 + }
+1 -10
src/utils.rs
··· 1 1 pub(crate) fn get_build_info() -> String { 2 - let raw_ver = option_env!("BUILD_VERSION"); 3 - if raw_ver.is_none() { 4 - return "test".to_string(); 5 - } 6 - let raw_ver = raw_ver.unwrap(); 7 - 8 - let long_sha = raw_ver.split("-").last().unwrap(); 9 - let short_sha = long_sha.chars().take(7).collect::<String>(); 10 - 11 - raw_ver.replace(long_sha, &short_sha) 2 + env!("GRAIN_VERSION").to_string() 12 3 }