Crate build_data[−][src]
build-data
Include build data in your program.
Features
- Saves build-time data:
- Git commit, branch, and dirtiness
- Date & time
- Epoch time
- Hostname
- Rustc version
- Does all of its work in your
build.rs. - No macros
- Depends only on
core::alloc forbid(unsafe_code)- 100% test coverage
Alternatives
build-info- Mature & popular
- Confusing API
- Uses procedural macros
Example
// Cargo.toml
[dependencies]
build-data = "0"
[build-dependencies]
build-data-writer = "0"
Add a build.rs
file next to your Cargo.toml.
Call build_data_writer::write
to collect data and write it to the file.
// build.rs use std::env; use std::path::Path; fn main() { build_data_writer::write( &Path::new(&env::var_os("OUT_DIR").unwrap()) .join("build-data.txt") ).unwrap(); build_data_writer::no_debug_rebuilds(); }
When you run cargo build, Cargo compiles and runs your build.rs which
writes the file:
// target/build-data.txt
GIT_BRANCH:release
GIT_COMMIT:a5547bfb1edb9712588f0f85d3e2c8ba618ac51f
GIT_DIRTY:false
HOSTNAME:builder2
RUSTC_VERSION:rustc 1.53.0-nightly (07e0e2ec2 2021-03-24)
TIME:2021-04-14T06:25:59+00:00
TIME_SECONDS:1618381559
Include and parse the file in your program.
See include_str!,
concat!,
env!, and
build_data::BuildData::new.
// src/bin/main.rs fn main() { let bd = build_data::BuildData::new(include_str!( concat!(env!("OUT_DIR"), "/build-data.txt") )).unwrap(); // Built 2021-04-13T08:17:32+00:00 branch=release // commit=a5547bfb1edb9712588f0f85d3e2c8ba618ac51f // host=builder2 // rustc 1.53.0-nightly (07e0e2ec2 2021-03-24) log!("{}", bd); }
Cargo Geiger Safety Report
Changelog
- v0.1.0 - Initial version
Happy Contributors 🙂
Fixing bugs and adding features is easy and fast. Send us a pull request and we intend to:
- Always respond within 24 hours
- Provide clear & concrete feedback
- Immediately make a new release for your accepted change
Structs
| BuildData | Build data parser and holder. Example in module docs. |