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