From 22b4c4be2c0bb9e37ac892b4e5d016f209dd0bad Mon Sep 17 00:00:00 2001 From: KKRainbow <443152178@qq.com> Date: Thu, 5 Mar 2026 00:06:21 +0800 Subject: [PATCH] fix: guard `macos-ne` feature with `target_os = "macos"` in cfg expressions (#1962) All 13 occurrences of `any(target_os = "ios", feature = "macos-ne")` are replaced with `any(target_os = "ios", all(target_os = "macos", feature = "macos-ne"))`. Previously, enabling `macos-ne` on non-macOS platforms (e.g. `--all-features` on Linux) would incorrectly compile macOS/mobile-specific code paths, causing build failures or wrong runtime behavior. Co-authored-by: Claude Opus 4.6 (1M context) --- easytier/src/connector/mod.rs | 5 ++++- easytier/src/gateway/tcp_proxy.rs | 5 ++++- easytier/src/instance/instance.rs | 13 ++++++++----- easytier/src/instance/virtual_nic.rs | 11 +++++++---- easytier/src/launcher.rs | 4 ++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/easytier/src/connector/mod.rs b/easytier/src/connector/mod.rs index 8f8d08da..113498d5 100644 --- a/easytier/src/connector/mod.rs +++ b/easytier/src/connector/mod.rs @@ -36,7 +36,10 @@ async fn set_bind_addr_for_peer_connector( ) { if cfg!(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any( + target_os = "ios", + all(target_os = "macos", feature = "macos-ne") + ), target_env = "ohos" )) { return; diff --git a/easytier/src/gateway/tcp_proxy.rs b/easytier/src/gateway/tcp_proxy.rs index fffe4733..74c9ed2a 100644 --- a/easytier/src/gateway/tcp_proxy.rs +++ b/easytier/src/gateway/tcp_proxy.rs @@ -539,7 +539,10 @@ impl TcpProxy { || self.global_ctx.no_tun() || cfg!(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any( + target_os = "ios", + all(target_os = "macos", feature = "macos-ne") + ), target_env = "ohos" )) { diff --git a/easytier/src/instance/instance.rs b/easytier/src/instance/instance.rs index 4dde5102..b9ccb44f 100644 --- a/easytier/src/instance/instance.rs +++ b/easytier/src/instance/instance.rs @@ -115,7 +115,10 @@ impl IpProxy { tracing::error!("start icmp proxy failed: {:?}", e); if cfg!(not(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any( + target_os = "ios", + all(target_os = "macos", feature = "macos-ne") + ), target_env = "ohos" ))) { // android, ios and ohos not support icmp proxy @@ -805,7 +808,7 @@ impl Instance { #[cfg(all( not(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" )), feature = "tun" @@ -853,7 +856,7 @@ impl Instance { #[cfg(all( not(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" )), feature = "tun" @@ -947,7 +950,7 @@ impl Instance { #[cfg(not(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" )))] if !self.global_ctx.config.get_flags().no_tun { @@ -1463,7 +1466,7 @@ impl Instance { #[cfg(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" ))] pub async fn setup_nic_ctx_for_mobile( diff --git a/easytier/src/instance/virtual_nic.rs b/easytier/src/instance/virtual_nic.rs index f516d493..d7238a11 100644 --- a/easytier/src/instance/virtual_nic.rs +++ b/easytier/src/instance/virtual_nic.rs @@ -577,7 +577,7 @@ impl VirtualNic { #[cfg(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" ))] pub async fn create_dev_for_mobile( @@ -588,7 +588,7 @@ impl VirtualNic { let mut config = Configuration::default(); config.layer(Layer::L3); - #[cfg(any(target_os = "ios", feature = "macos-ne"))] + #[cfg(any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")))] config.platform_config(|config| { // disable packet information so we can process the header by ourselves, see tun2 impl for more details config.packet_information(false); @@ -598,7 +598,10 @@ impl VirtualNic { config.close_fd_on_drop(false); config.up(); - let has_packet_info = cfg!(any(target_os = "ios", feature = "macos-ne")); + let has_packet_info = cfg!(any( + target_os = "ios", + all(target_os = "macos", feature = "macos-ne") + )); let dev = tun::create(&config)?; let dev = AsyncDevice::new(dev)?; let (a, b) = BiLock::new(dev); @@ -1174,7 +1177,7 @@ impl NicCtx { #[cfg(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" ))] pub async fn run_for_mobile(&mut self, tun_fd: std::os::fd::RawFd) -> Result<(), Error> { diff --git a/easytier/src/launcher.rs b/easytier/src/launcher.rs index 222c4ffa..2abfe5f8 100644 --- a/easytier/src/launcher.rs +++ b/easytier/src/launcher.rs @@ -95,7 +95,7 @@ impl EasyTierLauncher { #[cfg(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" ))] async fn run_routine_for_mobile( @@ -158,7 +158,7 @@ impl EasyTierLauncher { #[cfg(any( target_os = "android", - any(target_os = "ios", feature = "macos-ne"), + any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")), target_env = "ohos" ))] Self::run_routine_for_mobile(&instance, &data, &mut tasks).await;