1 个不稳定版本
使用旧的 Rust 2015
0.1.0 | 2017年8月28日 |
---|
#105 in #embed
6KB
64 行
构建元数据
使用此包在编译时嵌入存储库和构建元数据
该项目使用过程宏为您提供这些元数据,公开了三个宏
head!()
:当前所在的 git 分支或标签的名称commit!()
:简短的 git 提交 IDtime!()
:UTC 编译时间。此值被缓存,因此在一个包中的每次调用都将保持相同。请注意,使用此功能会使构建不可重复(因为生成的二进制文件将根据编译时间而变化)
用法
通过将以下内容添加到您的 Cargo.toml 文件中,使用 cargo 从 crates.io
导入它
[dependencies]
build_metadata = "^0.1"
#![feature(plugin)]
#![plugin(build_metadata)]
fn main() {
println!("build time: {}", time!());
println!("head: {}", head!());
println!("commit id: {}", commit!());
}
lib.rs
:
使用此包在编译时嵌入存储库和构建元数据
该项目使用过程宏为您提供这些元数据,公开了三个宏
head!()
:当前所在的 git 分支或标签的名称commit!()
:简短的 git 提交 IDtime!()
:UTC 编译时间。此值被缓存,因此在一个包中的每次调用都将保持相同。请注意,使用此功能会使构建不可重复(因为生成的二进制文件将根据编译时间而变化)
示例
#![feature(plugin)]
#![plugin(build_metadata)]
fn main() {
println!("build time: {}", time!());
println!("head: {}", head!());
println!("commit id: {}", commit!());
}
依赖项
~11MB
~281K SLoC