README.OpenSource
1[
2 {
3 "Name": "autocfg",
4 "License": "Apache License V2.0, MIT",
5 "License File": "LICENSE-APACHE, LICENSE-MIT",
6 "Version Number": "1.1.0",
7 "Owner": "fangting12@huawei.com",
8 "Upstream URL": "https://github.com/cuviper/autocfg",
9 "Description": "A library that generates Rust code based on compile-time configuration options."
10 }
11]
12
README.md
1autocfg
2=======
3
4[](https://crates.io/crates/autocfg)
5[](https://docs.rs/autocfg)
6
7
8
9A Rust library for build scripts to automatically configure code based on
10compiler support. Code snippets are dynamically tested to see if the `rustc`
11will accept them, rather than hard-coding specific version support.
12
13
14## Usage
15
16Add this to your `Cargo.toml`:
17
18```toml
19[build-dependencies]
20autocfg = "1"
21```
22
23Then use it in your `build.rs` script to detect compiler features. For
24example, to test for 128-bit integer support, it might look like:
25
26```rust
27extern crate autocfg;
28
29fn main() {
30 let ac = autocfg::new();
31 ac.emit_has_type("i128");
32
33 // (optional) We don't need to rerun for anything external.
34 autocfg::rerun_path("build.rs");
35}
36```
37
38If the type test succeeds, this will write a `cargo:rustc-cfg=has_i128` line
39for Cargo, which translates to Rust arguments `--cfg has_i128`. Then in the
40rest of your Rust code, you can add `#[cfg(has_i128)]` conditions on code that
41should only be used when the compiler supports it.
42
43
44## Release Notes
45
46- 1.1.0 (2022-02-07)
47 - Use `CARGO_ENCODED_RUSTFLAGS` when it is set.
48
49- 1.0.1 (2020-08-20)
50 - Apply `RUSTFLAGS` for more `--target` scenarios, by @adamreichold.
51
52- 1.0.0 (2020-01-08)
53 - Release 1.0! (no breaking changes)
54 - Add `probe_expression` and `emit_expression_cfg` to test arbitrary expressions.
55 - Add `probe_constant` and `emit_constant_cfg` to test arbitrary constant expressions.
56
57- 0.1.7 (2019-10-20)
58 - Apply `RUSTFLAGS` when probing `$TARGET != $HOST`, mainly for sysroot, by @roblabla.
59
60- 0.1.6 (2019-08-19)
61 - Add `probe`/`emit_sysroot_crate`, by @leo60228.
62
63- 0.1.5 (2019-07-16)
64 - Mask some warnings from newer rustc.
65
66- 0.1.4 (2019-05-22)
67 - Relax `std`/`no_std` probing to a warning instead of an error.
68 - Improve `rustc` bootstrap compatibility.
69
70- 0.1.3 (2019-05-21)
71 - Auto-detects if `#![no_std]` is needed for the `$TARGET`.
72
73- 0.1.2 (2019-01-16)
74 - Add `rerun_env(ENV)` to print `cargo:rerun-if-env-changed=ENV`.
75 - Add `rerun_path(PATH)` to print `cargo:rerun-if-changed=PATH`.
76
77
78## Minimum Rust version policy
79
80This crate's minimum supported `rustc` version is `1.0.0`. Compatibility is
81its entire reason for existence, so this crate will be extremely conservative
82about raising this requirement. If this is ever deemed necessary, it will be
83treated as a major breaking change for semver purposes.
84
85
86## License
87
88This project is licensed under either of
89
90 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
91 http://www.apache.org/licenses/LICENSE-2.0)
92 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
93 http://opensource.org/licenses/MIT)
94
95at your option.
96