3 releases (stable)

1.1.0 Jan 13, 2022
1.0.0 Oct 20, 2021
0.1.0 Sep 26, 2021

#21 in #directive

Download history 117/week @ 2024-08-26 101/week @ 2024-09-02 87/week @ 2024-09-09 86/week @ 2024-09-16 139/week @ 2024-09-23 99/week @ 2024-09-30 60/week @ 2024-10-07 109/week @ 2024-10-14 131/week @ 2024-10-21 94/week @ 2024-10-28 133/week @ 2024-11-04 66/week @ 2024-11-11 102/week @ 2024-11-18 142/week @ 2024-11-25 168/week @ 2024-12-02 170/week @ 2024-12-09

596 downloads per month
Used in 11 crates (via build_cfg)

MIT license

11KB
240 lines

crates.io

build_cfg

Test cfg directives at build time!

Currently, cfg directives do not work "correctly" in a build script. This is because the build script must be compiled for the host machine to execute. Therefore, it is always compiled to target the native environment.

This means that we can't conditionally compile stuff in our build scripts depending on the target platform we pass in with --target. This crate aims to solve this problem by collecting and evaluating cfg directives at runtime during the build script.

Example

#[macro_use]
extern crate build_cfg;

#[build_cfg_main]
fn main() {
    if build_cfg!(all(target_os = "windows", target_pointer_width = "64")) {
        println!("Building for Windows 64-bit");
    } else {
        println!("Not building for Windows 64-bit");
    }
}

Dependencies

~270–710KB
~16K SLoC