#git #compile-time #macro

macro git-const

Proc macro to provide properties of git repo

2 stable releases

1.1.0 Dec 23, 2022
1.0.0 Dec 22, 2022

#2217 in Procedural macros

Download history 6/week @ 2023-07-29 4/week @ 2023-08-19 2/week @ 2023-08-26 4/week @ 2023-09-02 4/week @ 2023-09-09 4/week @ 2023-09-23 5/week @ 2023-09-30 30/week @ 2023-10-07 35/week @ 2023-10-14 11/week @ 2023-10-21 8/week @ 2023-10-28 17/week @ 2023-11-04 16/week @ 2023-11-11

52 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