3 releases (stable)

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

#24 in #directive

Download history 70/week @ 2024-02-26 87/week @ 2024-03-04 77/week @ 2024-03-11 81/week @ 2024-03-18 187/week @ 2024-03-25 103/week @ 2024-04-01 68/week @ 2024-04-08 98/week @ 2024-04-15 176/week @ 2024-04-22 62/week @ 2024-04-29 71/week @ 2024-05-06 66/week @ 2024-05-13 100/week @ 2024-05-20 108/week @ 2024-05-27 74/week @ 2024-06-03 63/week @ 2024-06-10

352 downloads per month
Used in 6 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

~1.5MB
~36K SLoC