From 5b1b6951a0b204ef8cef7d32fe436a2b6e424b6d Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Mon, 25 Mar 2024 17:59:52 +0800 Subject: [PATCH] docs: document we don't alias for ONLY 1 OS[skip ci] (#2346) --- CONVENTIONS.md | 6 +++++- build.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 51afae1ce4..5615da4b33 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -47,9 +47,13 @@ When creating newtypes, we use Rust's `CamelCase` type naming convention. ## cfg gates When creating operating-system-specific functionality, we gate it by -`#[cfg(target_os = ...)]`. If more than one operating system is affected, we +`#[cfg(target_os = ...)]`. If **MORE THAN ONE operating system** is affected, we prefer to use the cfg aliases defined in build.rs, like `#[cfg(bsd)]`. +Please **DO NOT** use cfg aliases for **ONLY ONE** system as [they are bad][mismatched_target_os]. + +[mismatched_target_os]: https://rust-lang.github.io/rust-clippy/master/index.html#/mismatched_target_os + ## Bitflags Many C functions have flags parameters that are combined from constants using diff --git a/build.rs b/build.rs index 4535af1f04..ecadc04f5d 100644 --- a/build.rs +++ b/build.rs @@ -15,6 +15,8 @@ fn main() { watchos: { target_os = "watchos" }, tvos: { target_os = "tvos" }, + + // cfg aliases we would like to use apple_targets: { any(ios, macos, watchos, tvos) }, bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) }, linux_android: { any(android, linux) },