Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions commons/zenoh-shm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,3 @@ winapi = { workspace = true }

[dev-dependencies]
libc = { workspace = true }

[build-dependencies]
cfg_aliases = "0.2.1"
54 changes: 23 additions & 31 deletions commons/zenoh-shm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,30 @@
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//

use cfg_aliases::cfg_aliases;

fn main() {
// these aliases should at least be included in the same aliases of Nix crate:
// ___________________
// | |
// | Nix aliases |
// | ___________ |
// | | Our | |
// | | 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" },

apple_targets: { any(ios, macos, watchos, tvos, visionos) },
bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) },
// `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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YuanYuYuan this is a fair comment, even if CARGO_CFG_TARGET_OS should be present.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this since it doesn't show up in the GitHub mobile app. I will address it.

let shm_external_lockfile = matches!(
target_os.as_str(),
"freebsd"
| "dragonfly"
| "netbsd"
| "openbsd"
| "ios"
| "macos"
| "watchos"
| "tvos"
| "visionos"
| "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") },
}

println!("cargo:rustc-check-cfg=cfg(apple_targets)");
println!("cargo:rustc-check-cfg=cfg(bsd)");
println!("cargo:rustc-check-cfg=cfg(shm_external_lockfile)");
if shm_external_lockfile {
println!("cargo:rustc-cfg=shm_external_lockfile");
}
}
Loading