#rustc #build #autoconf

build autocfg

Automatic cfg for Rust compiler features

4 releases

0.1.2 Jan 17, 2019
0.1.1 Oct 12, 2018
0.1.0 Oct 12, 2018
0.0.1 May 30, 2018

#7 in Build Utils

Download history 70136/week @ 2019-01-20 65987/week @ 2019-01-27 66066/week @ 2019-02-03 75967/week @ 2019-02-10 75099/week @ 2019-02-17 81912/week @ 2019-02-24 79122/week @ 2019-03-03 81695/week @ 2019-03-10 81688/week @ 2019-03-17 76746/week @ 2019-03-24 83836/week @ 2019-03-31 86256/week @ 2019-04-07 82679/week @ 2019-04-14 84728/week @ 2019-04-21 80006/week @ 2019-04-28

70,783 downloads per month
Used in 5,888 crates (8 directly)

Apache-2.0/MIT

18KB
297 lines

autocfg

autocfg crate autocfg documentation minimum rustc 1.0 Travis 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 = "0.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(file!());
}

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

  • 0.1.2 (2018-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