Match_cfg! - simplify `cfg(...)` code

#1

https://crates.io/crates/match_cfg

From libc:

match_cfg! {
    #[cfg(windows)] => {
        mod windows;
        pub use windows::*;
    } 
    #[cfg(target_os = "redox")] => {
        mod redox;
        pub use redox::*;
    } 
    #[cfg(all(target_env = "sgx", target_vendor = "fortanix"))] => {
        mod sgx;
        pub use sgx::*;
    // ...
    _ =>  {
        // non-supported targets: empty...
    }

From stdsimd:

#[cfg(any(
    target_arch = "aarch64",
    target_feature = "v7",
    target_feature = "mclass"
))]
mod common;

match_cfg! {
    #[cfg(any(
        target_arch = "aarch64",
        target_feature = "v7",
        target_feature = "mclass"
    ))] => {
        mod common;
        pub use self::common::*;
    }
    _ => {
        mod cp15;
        pub use self::cp15::*;
    }
}
3 Likes

#2

What do you want to tell us? ^^ If you want to improve the code, we all are happy to welcome you to open a PR at the github repo.

Else it would be nice if you could extend your post a little bit :slight_smile:

0 Likes

#3

@gnzlbg is telling you that he made a crate called match_cfg that can be used to in things like stdsimd and libc that involve a lot of target-specific cfg flagging.

1 Like

#4

Can you elaborate on why we’d use match_cfg instead of the older cfg_if?

https://crates.io/crates/cfg_if

4 Likes