File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,29 @@ fn duration_as_days(dur: Duration) -> u64 {
126126}
127127```
128128
129+ Emitting Cargo cfg directives from a build script. Note that this requires
130+ listing ` rustversion ` under ` [build-dependencies] ` in Cargo.toml, not
131+ ` [dependencies] ` .
132+
133+ ``` rust
134+ // build.rs
135+
136+ fn main () {
137+ if rustversion :: cfg! (since (1.36 )) {
138+ println! (" cargo:rustc-cfg=no_std" );
139+ }
140+ }
141+ ```
142+
143+ ``` rust
144+ // src/lib.rs
145+
146+ #![cfg_attr(no_std, no_std)]
147+
148+ #[cfg(no_std)]
149+ extern crate alloc;
150+ ```
151+
129152<br >
130153
131154#### License
Original file line number Diff line number Diff line change 150150//! }
151151//! ```
152152//!
153+ //! Emitting Cargo cfg directives from a build script. Note that this requires
154+ //! listing `rustversion` under `[build-dependencies]` in Cargo.toml, not
155+ //! `[dependencies]`.
156+ //!
157+ //! ```
158+ //! // build.rs
159+ //!
160+ //! fn main() {
161+ //! if rustversion::cfg!(since(1.36)) {
162+ //! println!("cargo:rustc-cfg=no_std");
163+ //! }
164+ //! }
165+ //! ```
166+ //!
167+ //! ```
168+ //! // src/lib.rs
169+ //!
170+ //! #![cfg_attr(no_std, no_std)]
171+ //!
172+ //! #[cfg(no_std)]
173+ //! extern crate alloc;
174+ //! ```
175+ //!
153176//! <br>
154177
155178#![ doc( html_root_url = "https://docs.rs/rustversion/1.0.18" ) ]
You can’t perform that action at this time.
0 commit comments