fix(shm): drop cfg_aliases macro, hand-roll build.rs cfg logic#2680
Conversation
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#2678), where it was originally bundled by necessity because that PR's own CI run hit this pre-existing, unrelated issue.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2680 +/- ##
==========================================
+ Coverage 74.09% 74.30% +0.21%
==========================================
Files 414 414
Lines 62296 62301 +5
==========================================
+ Hits 46157 46292 +135
+ Misses 16139 16009 -130 ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
Removes the cfg_aliases build-dependency from commons/zenoh-shm and replaces the cfg_aliases! { ... } build-time alias graph with a small, direct CARGO_CFG_TARGET_OS-based computation to emit only the shm_external_lockfile cfg flag. This unblocks nightly builds affected by the macro expansion lint becoming a hard error.
Changes:
- Replaced
cfg_aliases!usage incommons/zenoh-shm/build.rswith a directCARGO_CFG_TARGET_OSmatch to compute and emitshm_external_lockfile. - Removed the
cfg_aliases = "0.2.1"build-dependency fromcommons/zenoh-shm/Cargo.toml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| commons/zenoh-shm/build.rs | Hand-rolls build-time cfg emission for shm_external_lockfile without cfg_aliases. |
| commons/zenoh-shm/Cargo.toml | Drops the now-unused cfg_aliases build-dependency section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 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(); |
There was a problem hiding this comment.
@YuanYuYuan this is a fair comment, even if CARGO_CFG_TARGET_OS should be present.
There was a problem hiding this comment.
Sorry, I missed this since it doesn't show up in the GitHub mobile app. I will address it.
Summary
commons/zenoh-shm/build.rsused thecfg_aliases!macro (cratecfg_aliases, pinned to0.2.1, latest on crates.io) to compute a small set of target-platform boolean flags at build time. That macro's expansion trips rustc'ssemicolon_in_expressions_from_macroslint, which recently became a hard compile error on current nightly. A 3-line upstream fix exists (katharostech/cfg_aliases#15) but is unreleased. This breaks every nightly CI job (Generate documentation,Coverage (ubuntu-latest, nightly)) onmainand every open PR.Checking actual usage shows
shm_external_lockfileis the only alias ever read outsidebuild.rs(9 call sites insrc/posix_shm/cleanup.rsandsrc/shm/unix.rs) — every other alias the macro produced was only an intermediate step in its own alias graph, never queried by any code. So this PR drops thecfg_aliasesdependency entirely and computes that one boolean directly fromCARGO_CFG_TARGET_OS, no macro, no crate dependency needed. The resultingshm_external_lockfileflag is identical to what the macro produced today (the BSD family, including all Apple targets, plus Redox).Originally discovered as part of #2678, extracted here since it's an unrelated, pre-existing issue affecting the whole repo.
Key Changes
commons/zenoh-shm/build.rs: replacecfg_aliases! { ... }with a directCARGO_CFG_TARGET_OSmatch computing onlyshm_external_lockfile. Also drops thecargo:rustc-check-cfg=cfg(apple_targets)/cfg(bsd)declarations —cfg_aliases!mechanically emitscargo:rustc-cfg=...for every alias name in its block, including intermediate composite ones likeapple_targets/bsd, not just the finalshm_external_lockfile, so those two declarations existed only to describe those extra emissions. Neither is ever read via#[cfg(...)]anywhere in the crate (grep -rn "apple_targets\|\bbsd\b" commons/zenoh-shm/srcis empty), and the new script no longer emits them as flags at all — they're just local booleans folded directly into the onematches!— so there's nothing left to declare.commons/zenoh-shm/Cargo.toml: remove the now-unusedcfg_aliasesbuild-dependency.🏷️ Label-Based Checklist
Based on the labels applied to this PR, please complete these additional requirements:
Labels:
bug,dependencies🐛 Bug Fix Requirements
Since this PR is labeled as a bug fix, please ensure:
cfg_aliases!'s macro expansion trips rustc'ssemicolon_in_expressions_from_macroslint, now a hard error on current nightly, with no released crate fix available.Generate documentation,Coverage (ubuntu-latest, nightly)) themselves, which already fail onmain/any PR without this fix (confirmed on fix(liveliness): decouple send_interest replay from calling thread #2678 before this fix was extracted from it) and are expected to pass once this PR merges.Generate documentationandCoverage (ubuntu-latest, nightly)are the jobs to watch.commons/zenoh-shm/build.rs) plus removing the now-unused dependency line incommons/zenoh-shm/Cargo.toml; no other files changed, no workspace-root manifest changes.grep -rln "cfg_aliases" --include="Cargo.toml" .thatcommons/zenoh-shmwas the only crate in this workspace depending oncfg_aliasesdirectly; no other crate is affected. Also confirmed viagrep -rn "shm_external_lockfile\|apple_targets\|\bbsd\b" commons/zenoh-shm/srcthatshm_external_lockfileis the only one of the macro's aliases ever read outsidebuild.rs.Why this matters: Bugs without tests often reoccur.
📦 Dependency Updates
Since this PR removes a dependency (not a version bump or a new dependency):
cfg_aliases) is removed entirely, not upgraded; there's no new changelog to review.cargo build/testdirectly in this session, so CI is the sole verification mechanism.Cargo.lock's existingcfg_aliases 0.1.1entry is an unrelated transitive build-dependency of a different external crate, untouched by this change.cfg_aliases, dropped) in exactly one crate (commons/zenoh-shm).Best practice: Keep dependency updates focused and test thoroughly.
Instructions:
- [ ]to- [x])This checklist updates automatically when labels change, but preserves your checked boxes.