| 1 |
```built``` provides a crate with information from the time it was built. |
| 2 |
|
| 3 |
[](https://crates.io/crates/built) |
| 4 |
[](https://docs.rs/built) |
| 5 |
[](https://github.com/lukaslueg/built/actions/workflows/check.yml) |
| 6 |
[](https://crates.io/crates/built) |
| 7 |
|
| 8 |
`built` is used as a build-time dependency to collect various information |
| 9 |
about the build-environment, serialize this information into Rust-code and |
| 10 |
provide that to the crate. The information collected by `built` include: |
| 11 |
|
| 12 |
* Various metadata like version, authors, homepage etc. as set by `Cargo.toml` |
| 13 |
* The tag or commit id if the crate was being compiled from within a Git repository. |
| 14 |
* The values of `CARGO_CFG_*` build script environment variables, like `CARGO_CFG_TARGET_OS` and `CARGO_CFG_TARGET_ARCH`. |
| 15 |
* The features the crate was compiled with. |
| 16 |
* The various dependencies, dependencies of dependencies and their versions Cargo ultimately chose to compile. |
| 17 |
* The presence of a CI-platform like `Github Actions`, `Travis CI` and `AppVeyor`. |
| 18 |
* The compiler and it's version; the documentation-generator and it's version. |
| 19 |
|
| 20 |
See [the example](https://github.com/lukaslueg/built/tree/master/example_project) or the [docs](https://docs.rs/built) for more information. |
| 21 |
|
| 22 |
### MSRV |
| 23 |
|
| 24 |
`built-0.8` itself currently requires Rust 1.81 with all features enabled. |
| 25 |
|
| 26 |
--- |
| 27 |
|
| 28 |
```rust,ignore |
| 29 |
// In build.rs |
| 30 |
|
| 31 |
fn main() { |
| 32 |
built::write_built_file().expect("Failed to acquire build-time information") |
| 33 |
} |
| 34 |
``` |
| 35 |
|
| 36 |
```rust,ignore |
| 37 |
// In lib.rs or main.rs |
| 38 |
|
| 39 |
// Include the generated-file as a separate module |
| 40 |
pub mod built_info { |
| 41 |
include!(concat!(env!("OUT_DIR"), "/built.rs")); |
| 42 |
} |
| 43 |
|
| 44 |
println!( |
| 45 |
"This is version {}, built for {} by {}.", |
| 46 |
built_info::PKG_VERSION, |
| 47 |
built_info::TARGET, |
| 48 |
built_info::RUSTC_VERSION |
| 49 |
); |
| 50 |
|
| 51 |
match built_info::CI_PLATFORM { |
| 52 |
None => print!("It seems I've not been built on a continuous integration platform,"), |
| 53 |
Some(ci) => print!("I've been built on CI-platform {},", ci), |
| 54 |
} |
| 55 |
|
| 56 |
if built::util::detect_ci().is_some() { |
| 57 |
println!(" but I'm currently executing on one!"); |
| 58 |
} else { |
| 59 |
println!(" and I'm currently not executing on one!"); |
| 60 |
} |
| 61 |
|
| 62 |
//.... |
| 63 |
``` |
| 64 |
|
| 65 |
> This is version 0.1.0, built for x86_64-unknown-linux-gnu by rustc 1.77.2 (25ef9e3d8 2024-04-09). |
| 66 |
> |
| 67 |
> I was built from git `0.7.2-3-g4014a2e`, commit 4014a2eb4e8575bec9a1f17ae7b92d8956ecd1fd, short_commit 4014a2e; the working directory was "clean". The branch was `refs/heads/master`. |
| 68 |
> |
| 69 |
> I was built for a x86_64-CPU, which is a little-endian architecture. I was compiled to run on linux (a unix-breed) and my runtime should be gnu. |
| 70 |
> |
| 71 |
> It seems I've not been built on a continuous integration platform, and I'm currently not executing on one! |
| 72 |
> |
| 73 |
> I was built with profile "debug", features "" on 2024-04-14 14:28:31 +00:00 (38 seconds ago) using `built 0.7.2` (with help from `android-tzdata 0.1.1, android_system_properties 0.1.5, autocfg 1.2.0, bitflags 2.5.0, bumpalo 3.16.0, cargo-lock 9.0.0, cc 1.0.94, cfg-if 1.0.0, chrono 0.4.37, core-foundation-sys 0.8.6, equivalent 1.0.1, fixedbitset 0.4.2, form_urlencoded 1.2.1, git2 0.18.3, hashbrown 0.14.3, iana-time-zone 0.1.60, iana-time-zone-haiku 0.1.2, idna 0.5.0, indexmap 2.2.6, jobserver 0.1.30, js-sys 0.3.69, libc 0.2.153, libgit2-sys 0.16.2+1.7.2, libz-sys 1.1.16, log 0.4.21, memchr 2.7.2, num-traits 0.2.18, once_cell 1.19.0, percent-encoding 2.3.1, petgraph 0.6.4, pkg-config 0.3.30, proc-macro2 1.0.79, quote 1.0.36, semver 1.0.22, serde 1.0.197, serde_derive 1.0.197, serde_spanned 0.6.5, syn 2.0.58, tinyvec 1.6.0, tinyvec_macros 0.1.1, toml 0.7.8, toml_datetime 0.6.5, toml_edit 0.19.15, unicode-bidi 0.3.15, unicode-ident 1.0.12, unicode-normalization 0.1.23, url 2.5.0, vcpkg 0.2.15, wasm-bindgen 0.2.92, wasm-bindgen-backend 0.2.92, wasm-bindgen-macro 0.2.92, wasm-bindgen-macro-support 0.2.92, wasm-bindgen-shared 0.2.92, windows-core 0.52.0, windows-targets 0.52.5, windows_aarch64_gnullvm 0.52.5, windows_aarch64_msvc 0.52.5, windows_i686_gnu 0.52.5, windows_i686_gnullvm 0.52.5, windows_i686_msvc 0.52.5, windows_x86_64_gnu 0.52.5, windows_x86_64_gnullvm 0.52.5, windows_x86_64_msvc 0.52.5, winnow 0.5.40`). |