3 releases (stable)

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

#535 in Build Utils

Download history 40/week @ 2023-12-14 45/week @ 2023-12-21 11/week @ 2023-12-28 20/week @ 2024-01-04 42/week @ 2024-01-11 48/week @ 2024-01-18 45/week @ 2024-01-25 21/week @ 2024-02-01 35/week @ 2024-02-08 50/week @ 2024-02-15 74/week @ 2024-02-22 58/week @ 2024-02-29 111/week @ 2024-03-07 84/week @ 2024-03-14 153/week @ 2024-03-21 120/week @ 2024-03-28

470 downloads per month
Used in 7 crates (2 directly)

MIT license

5KB
142 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
~34K SLoC