Skip to main content

build_context/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2
3/*!
4<!-- Note: Document from sync-markdown-to-rustdoc:start through sync-markdown-to-rustdoc:end
5     is synchronized from README.md. Any changes to that range are not preserved. -->
6<!-- tidy:sync-markdown-to-rustdoc:start -->
7
8Make [build environment/target information](https://doc.rust-lang.org/nightly/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts) available as constants in normal libraries and binaries.
9
10This is intended primarily for use in tests and its helpers. When used in libraries or binaries, be careful not to depend on constants that depend on the host build environment.
11
12Some constants duplicate those provided in `std::env::consts`.
13
14<!-- tidy:sync-markdown-to-rustdoc:end -->
15*/
16
17#![no_std]
18#![doc(test(
19    no_crate_inject,
20    attr(allow(
21        dead_code,
22        unused_variables,
23        clippy::undocumented_unsafe_blocks,
24        clippy::unused_trait_names,
25    ))
26))]
27#![forbid(unsafe_code)]
28#![warn(
29    // Lints that may help when writing public library.
30    missing_debug_implementations,
31    missing_docs,
32    clippy::alloc_instead_of_core,
33    clippy::exhaustive_enums,
34    clippy::exhaustive_structs,
35    clippy::impl_trait_in_params,
36    clippy::std_instead_of_alloc,
37    clippy::std_instead_of_core,
38    // clippy::missing_inline_in_public_items,
39)]
40
41// Use \ on Windows host to work around https://github.com/rust-lang/rust/issues/75075 / https://github.com/rust-lang/cargo/issues/13919.
42// (Fixed in Rust 1.84: https://github.com/rust-lang/rust/pull/125205)
43#[cfg(not(host_os = "windows"))]
44include!(concat!(env!("OUT_DIR"), "/build-context"));
45#[cfg(host_os = "windows")]
46include!(concat!(env!("OUT_DIR"), "\\build-context"));