#cargo #build

build built

Provides a crate with information from the time it was built

11 releases

✓ Uses Rust 2018 edition

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

#6 in Cargo plugins

Download history 3269/week @ 2020-01-25 3893/week @ 2020-02-01 3294/week @ 2020-02-08 2771/week @ 2020-02-15 3204/week @ 2020-02-22 2850/week @ 2020-02-29 2848/week @ 2020-03-07 2866/week @ 2020-03-14 3369/week @ 2020-03-21 3601/week @ 2020-03-28 4467/week @ 2020-04-04 3917/week @ 2020-04-11 4528/week @ 2020-04-18 6237/week @ 2020-04-25 4064/week @ 2020-05-02 5417/week @ 2020-05-09

14,450 downloads per month
Used in 55 crates (30 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.2–4MB
~106K SLoC