2 stable releases

1.1.0 Dec 23, 2022
1.0.0 Dec 22, 2022

#2337 in Procedural macros

22 downloads per month

BSL-1.0 license

5KB
65 lines

Proc macro to access git repo properties at build time.

Usage

use git_const::{git_hash, git_short_hash, git_root};

const ROOT: &str = git_root!();
const SHORT_VERSION: &str = git_short_hash!();
const VERSION: &str = git_hash!();
assert_ne!(VERSION, "");
assert!(!VERSION.contains('\n'));
assert_ne!(VERSION, SHORT_VERSION);
assert!(VERSION.starts_with(SHORT_VERSION));

const MASTER_VERSION: &str = git_hash!(master);
assert_eq!(MASTER_VERSION, VERSION); //true if current branch is master
let path = std::path::Path::new(ROOT);
assert_eq!(path.file_name().unwrap().to_str().unwrap(), "git-const");

No runtime deps