Crate autocfg[−][src]
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. println!("cargo:rerun-if-changed=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.
Structs
AutoCfg |
Helper to detect compiler features for |
Error |
A common error type for the |
Functions
emit |
Writes a config flag for rustc on standard out. |
new |
Create a new |