#cargo #build

build built

Provides a crate with information from the time it was built

10 releases

✓ Uses Rust 2018 edition

0.4.0 Feb 1, 2020
0.3.2 Aug 26, 2019
0.3.1 Jun 10, 2019
0.3.0 Apr 22, 2018
0.1.0 Feb 22, 2017

#6 in Cargo plugins

Download history 1710/week @ 2019-11-08 1997/week @ 2019-11-15 2850/week @ 2019-11-22 2041/week @ 2019-11-29 2445/week @ 2019-12-06 2318/week @ 2019-12-13 1291/week @ 2019-12-20 1196/week @ 2019-12-27 2774/week @ 2020-01-03 2699/week @ 2020-01-10 3058/week @ 2020-01-17 2903/week @ 2020-01-24 4182/week @ 2020-01-31 3285/week @ 2020-02-07 2492/week @ 2020-02-14

9,731 downloads per month
Used in 43 crates (20 directly)

MIT license

38KB
602 lines

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

Crates.io Version Docs Build status Build Status

built is used as a build-time dependency to collect various information about the build environment and serialize 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.

// In build.rs

fn main() {
    built::write_built_file().expect("Failed to acquire build-time information")
}
// In lib.rs or main.rs

pub mod built_info {
    include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

println!(
    "This is version {}{}, built for {} by {}.",
    built_info::PKG_VERSION,
    built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)),
    built_info::TARGET,
    built_info::RUSTC_VERSION
);

match built_info::CI_PLATFORM {
    None => print!("It seems I've not been built on a continuous integration platform,"),
    Some(ci) => print!("I've been built on CI-platform {},", ci),
}

if built::util::detect_ci().is_some() {
    println!(" but I'm currently executing on one!");
} else {
    println!(" and I'm currently not executing on one!");
}

This is version 0.1.0 (git 0.1-62-gcfdfb93), built for x86_64-unknown-linux-gnu by rustc 1.40.0 (73528e339 2019-12-16). It seems I've not been built on a continuous integration platform, and I'm currently not executing on one!

Dependencies

~2.3–4.5MB
~108K SLoC