[][src]Crate built

Provides a crate with information from the time it was built.

built is used as a build-time dependency to collect various information about the build environment, serialize it into Rust-code and compile it into the final crate. The information collected by built include:

  • Various metadata like version, authors, homepage etc. as set by Cargo.toml
  • The tag or commit id if the crate was being compiled from within a git repo.
  • The values of various cfg!, like target_os and target_arch.
  • The features the crate was compiled with.
  • The various dependencies, dependencies of dependencies and their versions cargo ultimately chose to compile.
  • The presence of a CI-platform like Travis CI and AppVeyor.
  • The used compiler and it's version; the used documentation generator and it's version.

built does not add any further dependencies to a crate; all information is serialized as types from stdlib. One can include built as a runtime-dependency and use it's convenience functions. The code generated by built will not interfere with #![deny(warnings, bad_style, future_incompatible, unused, missing_docs, unused_comparisons)].

To add built to a crate, add it as a build-time dependency, use a build script that collects and serializes the build-time information and include! that as code.

Add this to Cargo.toml:

build = "build.rs"

built = "0.3"

Add or modify a build script. In build.rs:

This example is not tested
extern crate built;
fn main() {
    built::write_built_file().expect("Failed to acquire build-time information");

The build-script will by default write a file named built.rs into Cargo's output directory. It can be picked up in main.rs (or anywhere else) like this:

This example is not tested
// Use of a mod or pub mod is not actually necessary.
pub mod built_info {
   // The file has been placed there by the build script.
   include!(concat!(env!("OUT_DIR"), "/built.rs"));

And then used somewhere in the crate's code:

This example is not tested
extern crate built;
extern crate time;
extern crate semver;

if (built_info::PKG_VERSION_PRE != "" || built_info::GIT_VERSION.is_some())
   && (built::util::strptime(built_info::BUILT_TIME_UTC) - time::now()).num_days() > 180 {
    println!("You are running a development version that is really old. Update soon!");

if built_info::CI_PLATFORM.is_some() {
    panic!("Muahahaha, there will be no commit for you, Peter Pan!");

let deps = built_info::DEPENDENCIES;
if built::util::parse_versions(&deps)
                .any(|(name, ver)| name == "DeleteAllMyFiles"
                                   && ver < semver::Version::parse("1.1.4").unwrap())) {
    warn!("DeleteAllMyFiles < 1.1.4 is known to sometimes not really delete all your files. Beware!");



Various convenience functions for built at runtime.



Selects which information built should retrieve and write as Rust code.



Various Continuous Integration platforms whose presence can be detected.



A shorthand for calling write_built_file() with CARGO_MANIFEST_DIR and [OUT_DIR]/built.rs.


Writes rust-code describing the crate at manifest_location to a new file named dst.