chore: use cfg_aliases for mobile (#2033)

This commit is contained in:
Luna Yao
2026-03-30 10:38:39 +02:00
committed by GitHub
parent 1dff388717
commit 55a0e5952c
5 changed files with 24 additions and 49 deletions
+3 -1
View File
@@ -50,6 +50,8 @@ time = "0.3"
toml = "0.8.12" toml = "0.8.12"
chrono = { version = "0.4.37", features = ["serde"] } chrono = { version = "0.4.37", features = ["serde"] }
cfg-if = "1.0"
itertools = "0.14.0" itertools = "0.14.0"
strum = { version = "0.27.2", features = ["derive"] } strum = { version = "0.27.2", features = ["derive"] }
@@ -250,7 +252,6 @@ shellexpand = "3.1.1"
# for fake tcp # for fake tcp
flume = { version = "0.12", optional = true } flume = { version = "0.12", optional = true }
cfg-if = "1.0"
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "freebsd"))'.dependencies] [target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "freebsd"))'.dependencies]
machine-uid = "0.5.3" machine-uid = "0.5.3"
@@ -313,6 +314,7 @@ jemalloc-sys = { package = "tikv-jemalloc-sys", version = "0.6.0", features = [
], optional = true } ], optional = true }
[build-dependencies] [build-dependencies]
cfg_aliases = "0.2.1"
tonic-build = "0.12" tonic-build = "0.12"
globwalk = "0.8.1" globwalk = "0.8.1"
regex = "1" regex = "1"
+13 -2
View File
@@ -1,9 +1,9 @@
use cfg_aliases::cfg_aliases;
use prost_wkt_build::{FileDescriptorSet, Message as _};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::io::Cursor; use std::io::Cursor;
use std::{env, path::PathBuf}; use std::{env, path::PathBuf};
use prost_wkt_build::{FileDescriptorSet, Message as _};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
struct WindowsBuild {} struct WindowsBuild {}
@@ -130,6 +130,17 @@ fn check_locale() {
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
cfg_aliases! {
mobile: {
any(
target_os = "android",
target_os = "ios",
all(target_os = "macos", feature = "macos-ne"),
target_env = "ohos"
)
}
}
// enable thunk-rs when target os is windows and arch is x86_64 or i686 // enable thunk-rs when target os is windows and arch is x86_64 or i686
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
if !std::env::var("TARGET") if !std::env::var("TARGET")
+4 -26
View File
@@ -808,14 +808,7 @@ impl Instance {
continue; continue;
} }
#[cfg(all( #[cfg(all(not(mobile), feature = "tun"))]
not(any(
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
)),
feature = "tun"
))]
{ {
let mut new_nic_ctx = NicCtx::new( let mut new_nic_ctx = NicCtx::new(
global_ctx_c.clone(), global_ctx_c.clone(),
@@ -856,14 +849,7 @@ impl Instance {
}); });
} }
#[cfg(all( #[cfg(all(not(mobile), feature = "tun"))]
not(any(
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
)),
feature = "tun"
))]
fn check_for_static_ip(&self, first_round_output: oneshot::Sender<Result<(), Error>>) { fn check_for_static_ip(&self, first_round_output: oneshot::Sender<Result<(), Error>>) {
let ipv4_addr = self.global_ctx.get_ipv4(); let ipv4_addr = self.global_ctx.get_ipv4();
let ipv6_addr = self.global_ctx.get_ipv6(); let ipv6_addr = self.global_ctx.get_ipv6();
@@ -951,11 +937,7 @@ impl Instance {
{ {
Self::clear_nic_ctx(self.nic_ctx.clone(), self.peer_packet_receiver.clone()).await; Self::clear_nic_ctx(self.nic_ctx.clone(), self.peer_packet_receiver.clone()).await;
#[cfg(not(any( #[cfg(not(mobile))]
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
)))]
if !self.global_ctx.config.get_flags().no_tun { if !self.global_ctx.config.get_flags().no_tun {
let (output_tx, output_rx) = oneshot::channel(); let (output_tx, output_rx) = oneshot::channel();
self.check_for_static_ip(output_tx); self.check_for_static_ip(output_tx);
@@ -1475,11 +1457,7 @@ impl Instance {
self.peer_packet_receiver.clone() self.peer_packet_receiver.clone()
} }
#[cfg(any( #[cfg(mobile)]
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
))]
pub async fn setup_nic_ctx_for_mobile( pub async fn setup_nic_ctx_for_mobile(
nic_ctx: ArcNicCtx, nic_ctx: ArcNicCtx,
global_ctx: ArcGlobalCtx, global_ctx: ArcGlobalCtx,
+2 -10
View File
@@ -575,11 +575,7 @@ impl VirtualNic {
Ok(tun::create(&config)?) Ok(tun::create(&config)?)
} }
#[cfg(any( #[cfg(mobile)]
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
))]
pub async fn create_dev_for_mobile( pub async fn create_dev_for_mobile(
&mut self, &mut self,
tun_fd: std::os::fd::RawFd, tun_fd: std::os::fd::RawFd,
@@ -1175,11 +1171,7 @@ impl NicCtx {
Ok(()) Ok(())
} }
#[cfg(any( #[cfg(mobile)]
target_os = "android",
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> { pub async fn run_for_mobile(&mut self, tun_fd: std::os::fd::RawFd) -> Result<(), Error> {
let tunnel = { let tunnel = {
let mut nic = self.nic.lock().await; let mut nic = self.nic.lock().await;
+2 -10
View File
@@ -93,11 +93,7 @@ impl EasyTierLauncher {
} }
} }
#[cfg(any( #[cfg(mobile)]
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
))]
async fn run_routine_for_mobile( async fn run_routine_for_mobile(
instance: &Instance, instance: &Instance,
data: &EasyTierData, data: &EasyTierData,
@@ -156,11 +152,7 @@ impl EasyTierLauncher {
} }
}); });
#[cfg(any( #[cfg(mobile)]
target_os = "android",
any(target_os = "ios", all(target_os = "macos", feature = "macos-ne")),
target_env = "ohos"
))]
Self::run_routine_for_mobile(&instance, &data, &mut tasks).await; Self::run_routine_for_mobile(&instance, &data, &mut tasks).await;
instance.run().await?; instance.run().await?;