15 releases (6 stable)

Uses old Rust 2015

1.4.0 Sep 27, 2024
1.3.0 May 3, 2024
1.2.0 Mar 25, 2024
1.1.0 Feb 7, 2022
0.0.1 May 30, 2018

#10 in Build Utils

Download history 3308001/week @ 2024-08-01 3631427/week @ 2024-08-08 3434001/week @ 2024-08-15 3629140/week @ 2024-08-22 3358226/week @ 2024-08-29 3834429/week @ 2024-09-05 3514492/week @ 2024-09-12 3435073/week @ 2024-09-19 4207513/week @ 2024-09-26 4686725/week @ 2024-10-03 4826908/week @ 2024-10-10 4549721/week @ 2024-10-17 3804196/week @ 2024-10-24 3724970/week @ 2024-10-31 3790421/week @ 2024-11-07 3371329/week @ 2024-11-14

15,388,688 downloads per month
Used in 71,932 crates (68 directly)

Apache-2.0 OR MIT

35KB
512 lines

autocfg

autocfg crate autocfg documentation minimum rustc 1.0 build status

A Rust library for build scripts to automatically configure code based on compiler support. Code snippets are dynamically tested to see if the rustc will accept them, rather than hard-coding specific version support.

Usage

Add this to your Cargo.toml:

[build-dependencies]
autocfg = "1"

Then use it in your build.rs script to detect compiler features. For example, to test for 128-bit integer support, it might look like:

extern crate autocfg;

fn main() {
    let ac = autocfg::new();
    ac.emit_has_type("i128");

    // (optional) We don't need to rerun for anything external.
    autocfg::rerun_path("build.rs");
}

If the type test succeeds, this will write a cargo:rustc-cfg=has_i128 line for Cargo, which translates to Rust arguments --cfg has_i128. Then in the rest of your Rust code, you can add #[cfg(has_i128)] conditions on code that should only be used when the compiler supports it.

Release Notes

  • 1.4.0 (2024-09-26)

    • Add emit_possibility for Rust 1.80's checked cfgs, and call that automatically for methods that conditionally emit, by @Techcable.
  • 1.3.0 (2024-05-03)

    • Add probe_raw for direct control of the code that will be test-compiled.
    • Use wrappers when querying the rustc version information too.
  • 1.2.0 (2024-03-25)

    • Add no_std and set_no_std to control the use of #![no_std] in probes.
    • Use RUSTC_WRAPPER and RUSTC_WORKSPACE_WRAPPER when they are set.
  • 1.1.0 (2022-02-07)

    • Use CARGO_ENCODED_RUSTFLAGS when it is set.
  • 1.0.1 (2020-08-20)

    • Apply RUSTFLAGS for more --target scenarios, by @adamreichold.
  • 1.0.0 (2020-01-08)

    • 🎉 Release 1.0! 🎉 (no breaking changes)
    • Add probe_expression and emit_expression_cfg to test arbitrary expressions.
    • Add probe_constant and emit_constant_cfg to test arbitrary constant expressions.
  • 0.1.7 (2019-10-20)

    • Apply RUSTFLAGS when probing $TARGET != $HOST, mainly for sysroot, by @roblabla.
  • 0.1.6 (2019-08-19)

    • Add probe/emit_sysroot_crate, by @leo60228.
  • 0.1.5 (2019-07-16)

    • Mask some warnings from newer rustc.
  • 0.1.4 (2019-05-22)

    • Relax std/no_std probing to a warning instead of an error.
    • Improve rustc bootstrap compatibility.
  • 0.1.3 (2019-05-21)

    • Auto-detects if #![no_std] is needed for the $TARGET.
  • 0.1.2 (2019-01-16)

    • Add rerun_env(ENV) to print cargo:rerun-if-env-changed=ENV.
    • Add rerun_path(PATH) to print cargo:rerun-if-changed=PATH.

Minimum Rust version policy

This crate's minimum supported rustc version is 1.0.0. Compatibility is its entire reason for existence, so this crate will be extremely conservative about raising this requirement. If this is ever deemed necessary, it will be treated as a major breaking change for semver purposes.

License

This project is licensed under either of

at your option.

No runtime deps