From 4db388708fc2494aed5a99909ad1b8f831547d02 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Thu, 16 Jul 2026 15:37:36 +0800 Subject: [PATCH 1/3] fix(shm): drop cfg_aliases macro, hand-roll build.rs cfg logic cfg_aliases!'s macro expansion trips rustc's semicolon_in_expressions_from_macros lint, a hard error on current nightly. No fixed release of cfg_aliases exists on crates.io (0.2.1 is latest). Spell out the equivalent cfg detection manually instead of depending on the macro, and drop the now-unused build-dependency. Extracted from dev/liveliness-query-deadlock (eclipse-zenoh/zenoh#2678), where it was originally bundled by necessity because that PR's own CI run hit this pre-existing, unrelated issue. --- commons/zenoh-shm/Cargo.toml | 3 -- commons/zenoh-shm/build.rs | 61 +++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/commons/zenoh-shm/Cargo.toml b/commons/zenoh-shm/Cargo.toml index d87fefb408..ab8d94d697 100644 --- a/commons/zenoh-shm/Cargo.toml +++ b/commons/zenoh-shm/Cargo.toml @@ -61,6 +61,3 @@ winapi = { workspace = true } [dev-dependencies] libc = { workspace = true } - -[build-dependencies] -cfg_aliases = "0.2.1" diff --git a/commons/zenoh-shm/build.rs b/commons/zenoh-shm/build.rs index 2502b031c0..75aa73ae65 100644 --- a/commons/zenoh-shm/build.rs +++ b/commons/zenoh-shm/build.rs @@ -12,8 +12,6 @@ // ZettaScale Zenoh Team, // -use cfg_aliases::cfg_aliases; - fn main() { // these aliases should at least be included in the same aliases of Nix crate: // ___________________ @@ -24,26 +22,47 @@ fn main() { // | | aliases | | // | |_________| | // |_________________| - cfg_aliases! { - dragonfly: { target_os = "dragonfly" }, - ios: { target_os = "ios" }, - freebsd: { target_os = "freebsd" }, - macos: { target_os = "macos" }, - netbsd: { target_os = "netbsd" }, - openbsd: { target_os = "openbsd" }, - watchos: { target_os = "watchos" }, - tvos: { target_os = "tvos" }, - visionos: { target_os = "visionos" }, + // + // NOTE: hand-rolled instead of using the `cfg_aliases` crate -- its macro + // expansion trips rustc's `semicolon_in_expressions_from_macros` lint, + // which is a hard error on current nightly (no fixed crate release + // exists as of writing). This is equivalent, just spelled out. + let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); - apple_targets: { any(ios, macos, watchos, tvos, visionos) }, - bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) }, + let dragonfly = target_os == "dragonfly"; + let ios = target_os == "ios"; + let freebsd = target_os == "freebsd"; + let macos = target_os == "macos"; + let netbsd = target_os == "netbsd"; + let openbsd = target_os == "openbsd"; + let watchos = target_os == "watchos"; + let tvos = target_os == "tvos"; + let visionos = target_os == "visionos"; + let redox = target_os == "redox"; - // we use this alias to detect platforms that - // don't support advisory file locking on tmpfs - shm_external_lockfile: { any(bsd, target_os = "redox") }, - } + let apple_targets = ios || macos || watchos || tvos || visionos; + let bsd = freebsd || dragonfly || netbsd || openbsd || apple_targets; + // we use this alias to detect platforms that + // don't support advisory file locking on tmpfs + let shm_external_lockfile = bsd || redox; - println!("cargo:rustc-check-cfg=cfg(apple_targets)"); - println!("cargo:rustc-check-cfg=cfg(bsd)"); - println!("cargo:rustc-check-cfg=cfg(shm_external_lockfile)"); + for (name, active) in [ + ("dragonfly", dragonfly), + ("ios", ios), + ("freebsd", freebsd), + ("macos", macos), + ("netbsd", netbsd), + ("openbsd", openbsd), + ("watchos", watchos), + ("tvos", tvos), + ("visionos", visionos), + ("apple_targets", apple_targets), + ("bsd", bsd), + ("shm_external_lockfile", shm_external_lockfile), + ] { + println!("cargo:rustc-check-cfg=cfg({name})"); + if active { + println!("cargo:rustc-cfg={name}"); + } + } } From 8f2b9aa43c0d99a1b6368611b600362de31cf796 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Thu, 16 Jul 2026 16:03:42 +0800 Subject: [PATCH 2/3] fix(shm): drop cfg_aliases dependency entirely Checked actual usage: shm_external_lockfile is the only cfg alias zenoh-shm queries anywhere outside build.rs (9 call sites in posix_shm/cleanup.rs and shm/unix.rs) -- the other aliases (dragonfly, ios, freebsd, macos, ..., apple_targets, bsd) only ever existed as intermediate steps inside the alias graph, never read directly by any code. No need for the cfg_aliases crate (or a patch to it) at all: compute the one boolean the crate actually needs directly from CARGO_CFG_TARGET_OS. Supersedes the earlier hand-rolled 12-alias rewrite -- this is smaller and has zero new dependency surface. --- commons/zenoh-shm/build.rs | 63 +++++++++----------------------------- 1 file changed, 14 insertions(+), 49 deletions(-) diff --git a/commons/zenoh-shm/build.rs b/commons/zenoh-shm/build.rs index 75aa73ae65..ac72e5ec50 100644 --- a/commons/zenoh-shm/build.rs +++ b/commons/zenoh-shm/build.rs @@ -13,56 +13,21 @@ // fn main() { - // these aliases should at least be included in the same aliases of Nix crate: - // ___________________ - // | | - // | Nix aliases | - // | ___________ | - // | | Our | | - // | | aliases | | - // | |_________| | - // |_________________| - // - // NOTE: hand-rolled instead of using the `cfg_aliases` crate -- its macro - // expansion trips rustc's `semicolon_in_expressions_from_macros` lint, - // which is a hard error on current nightly (no fixed crate release - // exists as of writing). This is equivalent, just spelled out. + // `shm_external_lockfile` is the only cfg alias this crate actually + // queries (see src/posix_shm/cleanup.rs, src/shm/unix.rs) -- it marks + // platforms that don't support advisory file locking on tmpfs: the BSD + // family (including all Apple targets, which are BSD-derived) plus + // Redox. Computed directly instead of pulling in the `cfg_aliases` + // crate for a single derived flag. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); + let shm_external_lockfile = matches!( + target_os.as_str(), + "freebsd" | "dragonfly" | "netbsd" | "openbsd" | "ios" | "macos" | "watchos" | "tvos" + | "visionos" | "redox" + ); - let dragonfly = target_os == "dragonfly"; - let ios = target_os == "ios"; - let freebsd = target_os == "freebsd"; - let macos = target_os == "macos"; - let netbsd = target_os == "netbsd"; - let openbsd = target_os == "openbsd"; - let watchos = target_os == "watchos"; - let tvos = target_os == "tvos"; - let visionos = target_os == "visionos"; - let redox = target_os == "redox"; - - let apple_targets = ios || macos || watchos || tvos || visionos; - let bsd = freebsd || dragonfly || netbsd || openbsd || apple_targets; - // we use this alias to detect platforms that - // don't support advisory file locking on tmpfs - let shm_external_lockfile = bsd || redox; - - for (name, active) in [ - ("dragonfly", dragonfly), - ("ios", ios), - ("freebsd", freebsd), - ("macos", macos), - ("netbsd", netbsd), - ("openbsd", openbsd), - ("watchos", watchos), - ("tvos", tvos), - ("visionos", visionos), - ("apple_targets", apple_targets), - ("bsd", bsd), - ("shm_external_lockfile", shm_external_lockfile), - ] { - println!("cargo:rustc-check-cfg=cfg({name})"); - if active { - println!("cargo:rustc-cfg={name}"); - } + println!("cargo:rustc-check-cfg=cfg(shm_external_lockfile)"); + if shm_external_lockfile { + println!("cargo:rustc-cfg=shm_external_lockfile"); } } From 93d122ab1557aaee10cffaaa5cef1e64fe279c92 Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Thu, 16 Jul 2026 16:07:20 +0800 Subject: [PATCH 3/3] style(shm): satisfy rustfmt on build.rs match-pattern wrapping --- commons/zenoh-shm/build.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commons/zenoh-shm/build.rs b/commons/zenoh-shm/build.rs index ac72e5ec50..72158ab769 100644 --- a/commons/zenoh-shm/build.rs +++ b/commons/zenoh-shm/build.rs @@ -22,8 +22,16 @@ fn main() { let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let shm_external_lockfile = matches!( target_os.as_str(), - "freebsd" | "dragonfly" | "netbsd" | "openbsd" | "ios" | "macos" | "watchos" | "tvos" - | "visionos" | "redox" + "freebsd" + | "dragonfly" + | "netbsd" + | "openbsd" + | "ios" + | "macos" + | "watchos" + | "tvos" + | "visionos" + | "redox" ); println!("cargo:rustc-check-cfg=cfg(shm_external_lockfile)");