From 0cec9f636f5222bb0320ca9fc946bb19f35c7ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 4 Oct 2023 16:41:12 +0100 Subject: [PATCH] don't build tokio-tun on non-linux targets --- common/wireguard/Cargo.toml | 2 ++ common/wireguard/src/lib.rs | 2 ++ gateway/Cargo.toml | 2 ++ gateway/src/node/mod.rs | 12 +++++++++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/common/wireguard/Cargo.toml b/common/wireguard/Cargo.toml index 961be993c5..fe7bc887f0 100644 --- a/common/wireguard/Cargo.toml +++ b/common/wireguard/Cargo.toml @@ -27,4 +27,6 @@ nym-task = { path = "../task" } tap.workspace = true thiserror.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "net", "io-util"] } + +[target.'cfg(target_os = "linux")'.dependencies] tokio-tun = "0.9.0" diff --git a/common/wireguard/src/lib.rs b/common/wireguard/src/lib.rs index 870da2da04..7afbef2e3b 100644 --- a/common/wireguard/src/lib.rs +++ b/common/wireguard/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(target_os = "linux")] + use std::{ net::{Ipv4Addr, SocketAddr}, sync::Arc, diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 7439ab8336..bb4a8e9c69 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -62,6 +62,8 @@ nym-statistics-common = { path = "../common/statistics" } nym-task = { path = "../common/task" } nym-types = { path = "../common/types" } nym-validator-client = { path = "../common/client-libs/validator-client" } + +[target.'cfg(target_os = "linux")'.dependencies] nym-wireguard = { path = "../common/wireguard", optional = true } [build-dependencies] diff --git a/gateway/src/node/mod.rs b/gateway/src/node/mod.rs index 6a59b1e3e7..8d03935e93 100644 --- a/gateway/src/node/mod.rs +++ b/gateway/src/node/mod.rs @@ -370,11 +370,17 @@ impl Gateway { // Once this is a bit more mature, make this a commandline flag instead of a compile time // flag #[cfg(feature = "wireguard")] - if let Err(err) = nym_wireguard::start_wireguard(shutdown.subscribe()).await { - // that's a nasty workaround, but anyhow errors are generally nicer, especially on exit - bail!("{err}") + { + #[cfg(target_os = "linux")] + if let Err(err) = nym_wireguard::start_wireguard(shutdown.subscribe()).await { + // that's a nasty workaround, but anyhow errors are generally nicer, especially on exit + bail!("{err}") + } + #[cfg(not(target_os = "linux"))] + panic!("wireguard is not supported on this platform") } + info!("Finished nym gateway startup procedure - it should now be able to receive mix and client traffic!"); if let Err(err) = Self::wait_for_interrupt(shutdown).await {