Crates.io | build-data |
lib.rs | build-data |
version | 0.3.3 |
created_at | 2021-04-14 09:43:14.540302+00 |
updated_at | 2025-06-03 22:25:13.9768+00 |
description | Include build data in your program: date, rustc version, git commit & branch, etc. |
homepage | |
repository | https://gitlab.com/leonhard-llc/ops |
max_upload_size | |
id | 383837 |
size | 65,421 |
Include build data in your program.
build.rs
.env!
to use them
in your program.forbid(unsafe_code)
CARGO_PKG_NAME
CARGO_PKG_VERSION
CARGO_BIN_NAME
vergen
env!
to retrieve valuesbuild-info
# Cargo.toml
[dependencies]
[build-dependencies]
build-data = "0.3"
Add a build.rs
file next to your Cargo.toml
.
Call build_data::set_*
functions to
set variables.
// build.rs
fn main() {
build_data::set_GIT_BRANCH().unwrap();
build_data::set_GIT_COMMIT().unwrap();
build_data::set_GIT_DIRTY().unwrap();
build_data::set_SOURCE_TIMESTAMP().unwrap();
build_data::no_debug_rebuilds().unwrap();
}
Use env!
to access the
variables in your program:
// src/bin/main.rs
fn main() {
// Built from branch=release
// commit=a5547bfb1edb9712588f0f85d3e2c8ba618ac51f
// dirty=false
// source_timestamp=2021-04-14T06:25:59+00:00
println!("Built from branch={} commit={} dirty={} source_timestamp={}",
env!("GIT_BRANCH"),
env!("GIT_COMMIT"),
env!("GIT_DIRTY"),
env!("SOURCE_TIMESTAMP"),
);
}
Metric output format: x/y
x = unsafe code used by the build
y = total unsafe code found in the crate
Symbols:
🔒 = No `unsafe` usage found, declares #![forbid(unsafe_code)]
❓ = No `unsafe` usage found, missing #![forbid(unsafe_code)]
☢️ = `unsafe` usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/6 0/0 0/0 0/0 🔒 build-data 0.3.3
0/0 1/13 1/1 0/0 0/0 ☢️ ├── chrono 0.4.41
0/0 0/0 0/0 0/0 0/0 ❓ │ ├── num-traits 0.2.19
0/0 0/5 0/0 0/0 0/0 ❓ │ └── serde 1.0.219
0/0 0/0 0/0 0/0 0/0 ❓ │ └── serde_derive 1.0.219
0/0 0/14 0/0 0/0 0/3 ❓ │ ├── proc-macro2 1.0.95
0/0 0/4 0/0 0/0 0/0 ❓ │ │ └── unicode-ident 1.0.18
0/0 0/0 0/0 0/0 0/0 ❓ │ ├── quote 1.0.40
0/0 0/14 0/0 0/0 0/3 ❓ │ │ └── proc-macro2 1.0.95
0/0 0/88 0/3 0/0 0/2 ❓ │ └── syn 2.0.101
0/0 0/14 0/0 0/0 0/3 ❓ │ ├── proc-macro2 1.0.95
0/0 0/0 0/0 0/0 0/0 ❓ │ ├── quote 1.0.40
0/0 0/4 0/0 0/0 0/0 ❓ │ └── unicode-ident 1.0.18
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex 0.3.0
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-macro 0.3.0
0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.95
0/0 0/0 0/0 0/0 0/0 🔒 │ └── unicode-xid 0.2.6
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-regex-compiler 0.3.0
0/0 0/0 0/0 0/0 0/0 🔒 ├── safe-proc-macro2 1.0.95
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-quote 1.0.40
0/0 0/0 0/0 0/0 0/0 🔒 └── safe-proc-macro2 1.0.95
0/0 1/130 1/4 0/0 0/5
Result
and don't panic.rerun_if_git_commit_or_branch_changed
.get_source_time
when git config has log.showsignature=true
.set_TARGET_PLATFORM
. Thanks tison!License: Apache-2.0