From 5976d30832a2a48f2d23527efea4a766bc44759c Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 2 Jun 2024 18:15:21 -0400 Subject: [PATCH] revert fix --- dev-setup/setup_macos.sh | 10 +------ scripts/new_android_sim.sh | 15 +++++------ veilid-core/build.rs | 27 ++++++++++++++++++- .../veilid_core_android_tests/build.gradle | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/dev-setup/setup_macos.sh b/dev-setup/setup_macos.sh index 6ebb5b99..e69f2619 100755 --- a/dev-setup/setup_macos.sh +++ b/dev-setup/setup_macos.sh @@ -33,16 +33,8 @@ while true; do # ensure Android SDK packages are installed $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager build-tools\;34.0.0 ndk\;26.3.11579264 cmake\;3.22.1 platform-tools platforms\;android-34 - # ensure ANDROID_NDK_HOME is defined and exists - ANDROID_NDK_HOME="$ANDROID_HOME/ndk/26.3.11579264" - if [ -d "$ANDROID_NDK_HOME" ]; then - echo '[X] Android NDK is defined and exists' - else - echo 'Android NDK is not defined or does not exist' - exit 1 - fi - # ensure ndk is installed + ANDROID_NDK_HOME="$ANDROID_HOME/ndk/26.3.11579264" if [ -f "$ANDROID_NDK_HOME/ndk-build" ]; then echo '[X] Android NDK is installed at the location $ANDROID_NDK_HOME' else diff --git a/scripts/new_android_sim.sh b/scripts/new_android_sim.sh index a5478299..0d62dfd2 100755 --- a/scripts/new_android_sim.sh +++ b/scripts/new_android_sim.sh @@ -1,6 +1,6 @@ #!/bin/bash -UNAME_M=`uname -m` +UNAME_M=${1-$(uname -m)} if [[ "$UNAME_M" == "arm64" ]]; then ANDROID_ABI=arm64-v8a elif [[ "$UNAME_M" == "x86_64" ]]; then @@ -14,16 +14,13 @@ AVD_TAG="google_atd" AVD_IMAGE="system-images;android-30;$AVD_TAG;$ANDROID_ABI" AVD_DEVICE="Nexus 10" -SDKMANAGER=$ANDROID_HOME/tools/bin/sdkmanager -AVDMANAGER=$ANDROID_HOME/tools/bin/avdmanager +SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager +AVDMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager if ! command -v $SDKMANAGER; then - SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager - AVDMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/avdmanager - if ! command -v $SDKMANAGER; then - echo "Can't find 'sdkmanager' in the usual places." - exit - fi + echo "Can't find 'sdkmanager' in the usual places." + exit fi + EMULATOR=$ANDROID_HOME/emulator/emulator if ! command -v $EMULATOR; then echo "Can't find 'emulator' in the usual places." diff --git a/veilid-core/build.rs b/veilid-core/build.rs index 8fc00540..b4cdfdde 100644 --- a/veilid-core/build.rs +++ b/veilid-core/build.rs @@ -1,9 +1,10 @@ +use glob::glob; use sha2::{Digest, Sha256}; use std::fs::OpenOptions; use std::io::BufRead; use std::io::Write; use std::{ - io, + env, io, path::Path, process::{Command, Stdio}, }; @@ -167,6 +168,28 @@ fn do_capnp_build() { append_hash_and_desired_capnp_version_hash("proto/veilid.capnp", "proto/veilid_capnp.rs"); } +// Fix for missing __extenddftf2 on Android x86_64 Emulator +fn fix_android_emulator() { + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + if target_arch == "x86_64" && target_os == "android" { + let missing_library = "clang_rt.builtins-x86_64-android"; + let android_home = env::var("ANDROID_HOME") + .or(env::var("ANDROID_SDK_ROOT")) + .expect("ANDROID_HOME or ANDROID_SDK_ROOT not set"); + let lib_path = glob(&format!( + "{android_home}/ndk/26.3.11579264/**/lib{missing_library}.a" + )) + .expect("failed to glob") + .next() + .expect("Need libclang_rt.builtins-x86_64-android.a") + .unwrap(); + let lib_dir = lib_path.parent().unwrap(); + println!("cargo:rustc-link-search={}", lib_dir.display()); + println!("cargo:rustc-link-lib=static={missing_library}"); + } +} + fn main() { if std::env::var("DOCS_RS").is_ok() || std::env::var("CARGO_CFG_DOC").is_ok() @@ -179,4 +202,6 @@ fn main() { println!("cargo:warning=rebuilding proto/veilid_capnp.rs because it has changed from the last generation of proto/veilid.capnp"); do_capnp_build(); } + + fix_android_emulator(); } diff --git a/veilid-core/src/tests/android/veilid_core_android_tests/build.gradle b/veilid-core/src/tests/android/veilid_core_android_tests/build.gradle index ffb3ba0e..cab50d59 100644 --- a/veilid-core/src/tests/android/veilid_core_android_tests/build.gradle +++ b/veilid-core/src/tests/android/veilid_core_android_tests/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' + classpath 'com.android.tools.build:gradle:7.4.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files