diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs index f89394a688b6..1310450aa919 100644 --- a/mullvad-daemon/build.rs +++ b/mullvad-daemon/build.rs @@ -29,13 +29,10 @@ fn main() { } res.compile().expect("Unable to generate windows resources"); } - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set"); - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if let "linux" | "windows" | "macos" = target_os.as_str() { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } fn commit_date() -> String { diff --git a/mullvad-management-interface/build.rs b/mullvad-management-interface/build.rs index 569d3379cc78..09f8601a83e3 100644 --- a/mullvad-management-interface/build.rs +++ b/mullvad-management-interface/build.rs @@ -1,11 +1,7 @@ fn main() { tonic_build::compile_protos("proto/management_interface.proto").unwrap(); - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set"); - - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if let "linux" | "windows" | "macos" = target_os.as_str() { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } diff --git a/mullvad-management-interface/src/client.rs b/mullvad-management-interface/src/client.rs index b0876093fa2a..3b2cabc33ea7 100644 --- a/mullvad-management-interface/src/client.rs +++ b/mullvad-management-interface/src/client.rs @@ -3,7 +3,7 @@ use crate::types; #[cfg(not(target_os = "android"))] use futures::{Stream, StreamExt}; -#[cfg(daita)] +#[cfg(all(daita, not(target_os = "android")))] use mullvad_types::wireguard::DaitaSettings; use mullvad_types::{ access_method::AccessMethodSetting, diff --git a/mullvad-relay-selector/build.rs b/mullvad-relay-selector/build.rs index 678311e004e4..810204ba1032 100644 --- a/mullvad-relay-selector/build.rs +++ b/mullvad-relay-selector/build.rs @@ -1,9 +1,5 @@ fn main() { - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set"); - - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if let "linux" | "windows" | "macos" = target_os.as_str() { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } diff --git a/mullvad-types/build.rs b/mullvad-types/build.rs index 678311e004e4..810204ba1032 100644 --- a/mullvad-types/build.rs +++ b/mullvad-types/build.rs @@ -1,9 +1,5 @@ fn main() { - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set"); - - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if let "linux" | "windows" | "macos" = target_os.as_str() { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } diff --git a/talpid-types/build.rs b/talpid-types/build.rs index 678311e004e4..810204ba1032 100644 --- a/talpid-types/build.rs +++ b/talpid-types/build.rs @@ -1,9 +1,5 @@ fn main() { - let target_os = std::env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set"); - - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if let "linux" | "windows" | "macos" = target_os.as_str() { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } diff --git a/talpid-wireguard/build.rs b/talpid-wireguard/build.rs index 1eb322606160..7d38f75118d2 100644 --- a/talpid-wireguard/build.rs +++ b/talpid-wireguard/build.rs @@ -14,11 +14,9 @@ fn add_wireguard_go_cfg(target_os: &str) { println!("cargo::rustc-cfg=wireguard_go"); } - // Enable DAITA by default on desktop + // Enable DAITA by default on desktop and android println!("cargo::rustc-check-cfg=cfg(daita)"); - if matches!(target_os, "linux" | "macos" | "windows") { - println!(r#"cargo::rustc-cfg=daita"#); - } + println!(r#"cargo::rustc-cfg=daita"#); } fn declare_libs_dir(base: &str) { diff --git a/wireguard-go-rs/Cargo.toml b/wireguard-go-rs/Cargo.toml index 062c80de34d2..e8a97ad12b0e 100644 --- a/wireguard-go-rs/Cargo.toml +++ b/wireguard-go-rs/Cargo.toml @@ -12,7 +12,7 @@ thiserror.workspace = true log.workspace = true zeroize = "1.8.1" -[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] +[target.'cfg(not(target_os = "windows"))'.dependencies] # The app does not depend on maybenot-ffi itself, but adds it as a dependency to expose FFI symbols to wireguard-go. # This is done, instead of using the makefile in wireguard-go to build maybenot-ffi into its archive, to prevent # name clashes induced by link-time optimization. diff --git a/wireguard-go-rs/build.rs b/wireguard-go-rs/build.rs index da981770d0bf..5c7feebb6bf9 100644 --- a/wireguard-go-rs/build.rs +++ b/wireguard-go-rs/build.rs @@ -20,7 +20,7 @@ fn main() -> anyhow::Result<()> { match target_os.as_str() { "linux" => build_static_lib(Os::Linux, true)?, "macos" => build_static_lib(Os::MacOs, true)?, - "android" => build_android_dynamic_lib(false)?, + "android" => build_android_dynamic_lib(true)?, // building wireguard-go-rs for windows is not implemented _ => {} } @@ -192,7 +192,12 @@ fn build_android_dynamic_lib(daita: bool) -> anyhow::Result<()> { .env("ANDROID_ARCH_NAME", android_arch_name(target)) .env("GOPATH", &go_path) // Note: -w -s results in a stripped binary - .env("LDFLAGS", format!("-L{out_dir} -w -s")); + .env("LDFLAGS", format!("-L{out_dir} -w -s")) + // Note: the build container overrides CARGO_TARGET_DIR, which will cause problems + // since we will spawn another cargo process as part of building maybenot (which we + // link into libwg). A work around is to simply override the overridden value, and we + // do this by pointing to a target folder in our temporary build folder. + .env("CARGO_TARGET_DIR", tmp_build_dir.join("target")); exec(build_command)?; diff --git a/wireguard-go-rs/libwg/Android.mk b/wireguard-go-rs/libwg/Android.mk index 9cb87b24717b..f847aa66d276 100644 --- a/wireguard-go-rs/libwg/Android.mk +++ b/wireguard-go-rs/libwg/Android.mk @@ -29,11 +29,15 @@ GOBUILDVERSION := 1.21.3 GOBUILDTARBALL := https://go.dev/dl/go$(GOBUILDVERSION).$(GOBUILDOS)-$(GOBUILDARCH).tar.gz GOBUILDVERSION_NEEDED := go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDARCH) + $(DESTDIR)/libwg.so: mkdir -p $(DESTDIR) - go get -tags "linux android" + # Build libmaybenot + make --directory wireguard-go libmaybenot.a LIBDEST="$(DESTDIR)" TARGET="$(TARGET)" CARGO_TARGET_DIR="$(CARGO_TARGET_DIR)" + # Build wireguard-go + go get -tags "linux android daita" chmod -fR +w "$(GOPATH)/pkg/mod" - go build -tags "linux android" -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared + go build -tags "linux android daita" -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared rm -f $(DESTDIR)/libwg.h