[][src]Crate autocfg

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.

Structs

AutoCfg

Helper to detect compiler features for cfg output in build scripts.

Error

A common error type for the autocfg crate.

Functions

emit

Writes a config flag for rustc on standard out.

new

Create a new AutoCfg instance.

rerun_env

Writes a line telling Cargo to rerun the build script if the environment variable var changes.

rerun_path

Writes a line telling Cargo to rerun the build script if path changes.