Skip to content

Commit

Permalink
wip add build system support for daita on android
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Aug 23, 2024
1 parent 095f6e4 commit 901109f
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 37 deletions.
7 changes: 2 additions & 5 deletions mullvad-daemon/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions mullvad-management-interface/build.rs
Original file line number Diff line number Diff line change
@@ -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"#);
}
2 changes: 1 addition & 1 deletion mullvad-management-interface/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions mullvad-relay-selector/build.rs
Original file line number Diff line number Diff line change
@@ -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"#);
}
8 changes: 2 additions & 6 deletions mullvad-types/build.rs
Original file line number Diff line number Diff line change
@@ -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"#);
}
8 changes: 2 additions & 6 deletions talpid-types/build.rs
Original file line number Diff line number Diff line change
@@ -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"#);
}
6 changes: 2 additions & 4 deletions talpid-wireguard/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion wireguard-go-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions wireguard-go-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ fn build_android_dynamic_lib() -> anyhow::Result<()> {
println!("cargo::rustc-link-search={}", lib_dir.display());
println!("cargo::rustc-link-lib=dylib=wg");

// Enable daita
println!(r#"cargo::rustc-cfg=daita"#);

Ok(())
}

Expand Down
7 changes: 6 additions & 1 deletion wireguard-go-rs/libwg/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,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
CARGO_TARGET_DIR="$(DESTDIR)/../tmp/" make --directory wireguard-go libmaybenot.a LIBDEST="$(DESTDIR)" TARGET="$(RUST_TARGET_TRIPLE)"
# Build wireguard-go
go get -tags "linux android daita"
chmod -fR +w "$(GOPATH)/pkg/mod"
# TODO: Adding the daita tag below seem to cause the build to fail.
go build -tags "linux android" -ldflags="-X main.socketDirectory=/data/data/$(ANDROID_PACKAGE_NAME)/cache/wireguard" -v -o "$@" -buildmode c-shared
rm -f $(DESTDIR)/libwg.h

Expand Down
3 changes: 2 additions & 1 deletion wireguard-go-rs/libwg/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ for arch in ${ARCHITECTURES:-armv7 aarch64 x86_64 i686}; do
# Build Wireguard-Go
pwd
make -f Android.mk clean
make -f Android.mk
export BUILD_DIR=$(realpath -s "../../build/")
LDFLAGS="-L$BUILD_DIR/lib/$RUST_TARGET_TRIPLE" make -f Android.mk

# Strip and copy the library to `android/build/extraJni/$ANDROID_ABI` to be able to build the APK
UNSTRIPPED_LIB_PATH="../../build/lib/$RUST_TARGET_TRIPLE/libwg.so"
Expand Down

0 comments on commit 901109f

Please sign in to comment.