From 8befa3d6491e023b3676c07bf71a1680700e3e6e Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 16 Jan 2024 09:02:40 +1000 Subject: [PATCH] Fix detect-targets on android targets (#1576) * Fix detect-targets on android targets By enabling linux fallback on Android. Also add CI regression test for aarch64-linux-android target. Signed-off-by: Jiahao XU * Fix CI: Add job `detect-targets-android-check` as required for merging Signed-off-by: Jiahao XU --------- Signed-off-by: Jiahao XU --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ crates/detect-targets/src/detect.rs | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48012559..86ba6d7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -256,6 +256,34 @@ jobs: --mount src="$PWD/detect-targets",dst=/detect-targets,type=bind \ nixos/nix /detect-targets )" = x86_64-unknown-linux-musl ] + detect-targets-android-check: + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-linux-android + + runs-on: ubuntu-latest + env: + CARGO_BUILD_TARGET: ${{ matrix.target }} + + steps: + - uses: actions/checkout@v4 + + - name: Add ${{ matrix.target }} + run: rustup target add ${{ matrix.target }} + + - uses: Swatinem/rust-cache@v2 + with: + cache-all-crates: true + - name: Build detect-targets + run: | + cargo check --target ${{ matrix.target }} + # Set working directory here, otherwise `cargo-check` would download + # and build quite a few unused dependencies. + working-directory: crates/detect-targets + + # Dummy job to have a stable name for the "all tests pass" requirement tests-pass: name: Tests pass @@ -269,6 +297,7 @@ jobs: - detect-targets-ubuntu-test - detect-targets-more-glibc-test - detect-targets-nix-test + - detect-targets-android-check if: always() # always run even if dependencies fail runs-on: ubuntu-latest steps: diff --git a/crates/detect-targets/src/detect.rs b/crates/detect-targets/src/detect.rs index a85e6e07..a3f4a67c 100644 --- a/crates/detect-targets/src/detect.rs +++ b/crates/detect-targets/src/detect.rs @@ -11,7 +11,7 @@ use tokio::process::Command; use tracing::debug; cfg_if! { - if #[cfg(target_os = "linux")] { + if #[cfg(any(target_os = "linux", target_os = "android"))] { mod linux; } else if #[cfg(target_os = "macos")] { mod macos; @@ -53,7 +53,7 @@ pub async fn detect_targets() -> Vec { let mut targets = vec![target]; targets.extend(windows::detect_alternative_targets(&targets[0])); targets - } else if #[cfg(target_os = "linux")] { + } else if #[cfg(any(target_os = "linux", target_os = "android"))] { // Linux is a bit special, since the result from `guess_host_triple` // might be wrong about whether glibc or musl is used. linux::detect_targets(target).await