fix(shm): fail loudly if CARGO_CFG_TARGET_OS is unset - #2683
Merged
fuzzypixelz merged 1 commit intoJul 16, 2026
Conversation
unwrap_or_default() would silently compute shm_external_lockfile as false on a missing var, misconfiguring BSD/Redox builds with no diagnostic. CARGO_CFG_TARGET_OS is always set by Cargo when running build scripts normally; expect() surfaces a nonstandard invocation immediately instead of masking it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2683 +/- ##
=======================================
Coverage 74.31% 74.31%
=======================================
Files 414 414
Lines 62301 62301
=======================================
+ Hits 46299 46300 +1
+ Misses 16002 16001 -1 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #2680. That PR replaced
commons/zenoh-shm/build.rs'scfg_aliases!macro with a directCARGO_CFG_TARGET_OScheck, usingunwrap_or_default()on the env var lookup. Review feedback pointed out thatCARGO_CFG_TARGET_OSis always set by Cargo when it runs a build script normally, so silently falling back to an empty string on a missing/unexpected value would misconfigureshm_external_lockfileasfalsewith no diagnostic — the wrong failure mode for a build-time invariant that should never actually be violated under normal use.Key Changes
commons/zenoh-shm/build.rs: replace.unwrap_or_default()with.expect(...)on theCARGO_CFG_TARGET_OSlookup, so a nonstandard invocation fails loudly at build time instead of silently misconfiguring BSD/Redox platform detection.🏷️ Label-Based Checklist
Based on the labels applied to this PR, please complete these additional requirements:
Labels:
bug🐛 Bug Fix Requirements
Since this PR is labeled as a bug fix, please ensure:
unwrap_or_default()onCARGO_CFG_TARGET_OSsilently computesshm_external_lockfile = falseif the var is ever missing, instead of surfacing the problem.CARGO_CFG_TARGET_OS) has no reliable way to reproduce under normalcargo build, since Cargo always sets it. The fix is a defensive assertion, not a fix for an observed failure.cargo build/cargo testacross the matrix exercise the build script on every job; a passing build confirmsexpect()doesn't fire under normal Cargo invocation).cfg..unwrap_or_default()→.expect(...)) incommons/zenoh-shm/build.rs; no other files touched.grep -rn "unwrap_or_default\|unwrap_or(" commons/zenoh-shm/build.rsconfirms this was the only such fallback in the file; no other silent-default pattern exists there.Why this matters: Bugs without tests often reoccur.
Instructions:
- [ ]to- [x])This checklist updates automatically when labels change, but preserves your checked boxes.