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

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

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:

@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

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

https://crates.io/crates/cfg_if

4 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.