From 1d1cb0e5968f5c06db0a2fda2cb6891a6fdcf62a Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 12 Mar 2025 14:19:33 +0200 Subject: [PATCH 1/3] fix: Simplify Android build WIP --- .github/workflows/check.yml | 126 ++++++++++++++++++------------------ build.rs | 16 +---- 2 files changed, 65 insertions(+), 77 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 08ae7ba2..01ea8856 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -431,66 +431,66 @@ jobs: # emulator-arch: arm64-v8 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - repository: mozilla/neqo - sparse-checkout: | - .github/actions/rust - path: neqo - persist-credentials: false - - - uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 - with: - distribution: zulu - java-version: 23 - - - uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2 - - run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}" - - - uses: ./neqo/.github/actions/rust - with: - version: stable - targets: ${{ matrix.target }} - tools: cargo-ndk - token: ${{ secrets.GITHUB_TOKEN }} - - - run: cargo ndk -t ${{ matrix.target }} test --no-run - - - env: - TARGET: ${{ matrix.target }} - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - cat <<'EOF' > /tmp/rust-android-run-tests-on-emulator.sh - #!/bin/bash - set -e - adb shell ip addr show - export GITHUB_ACTIONS=1 - adb wait-for-device - while [ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]; do sleep 1; done - any_failures=0 - for test in $(find target/$TARGET/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do - adb push "$test" /data/local/tmp/ - adb shell chmod +x /data/local/tmp/$(basename "$test") - # See https://unix.stackexchange.com/a/451140/409256 - adb shell "API_LEVEL=$API_LEVEL /data/local/tmp/$(basename "$test") || echo _FAIL_" 2>&1 | tee output - grep _FAIL_ output && any_failures=1 - done - exit $any_failures - EOF - chmod a+x /tmp/rust-android-run-tests-on-emulator.sh - - - uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # v2.33.0 - with: - api-level: ${{ env.API_LEVEL }} - arch: ${{ matrix.emulator-arch == 'arm64-v8' && 'arm64-v8a' || matrix.emulator-arch }} - ndk: ${{ env.NDK_VERSION }} - emulator-boot-timeout: 120 - script: /tmp/rust-android-run-tests-on-emulator.sh - env: - TARGET: ${{ matrix.target }} + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: mozilla/neqo + sparse-checkout: | + .github/actions/rust + path: neqo + persist-credentials: false + + - uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 + with: + distribution: zulu + java-version: 23 + + - uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2 + - run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}" + + - uses: ./neqo/.github/actions/rust + with: + version: stable + targets: ${{ matrix.target }} + tools: cargo-ndk + token: ${{ secrets.GITHUB_TOKEN }} + + - run: cargo ndk --bindgen -t ${{ matrix.target }} test --no-run + + - env: + TARGET: ${{ matrix.target }} + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + cat <<'EOF' > /tmp/rust-android-run-tests-on-emulator.sh + #!/bin/bash + set -e + adb shell ip addr show + export GITHUB_ACTIONS=1 + adb wait-for-device + while [ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]; do sleep 1; done + any_failures=0 + for test in $(find target/$TARGET/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do + adb push "$test" /data/local/tmp/ + adb shell chmod +x /data/local/tmp/$(basename "$test") + # See https://unix.stackexchange.com/a/451140/409256 + adb shell "API_LEVEL=$API_LEVEL /data/local/tmp/$(basename "$test") || echo _FAIL_" 2>&1 | tee output + grep _FAIL_ output && any_failures=1 + done + exit $any_failures + EOF + chmod a+x /tmp/rust-android-run-tests-on-emulator.sh + + - uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # v2.33.0 + with: + api-level: ${{ env.API_LEVEL }} + arch: ${{ matrix.emulator-arch == 'arm64-v8' && 'arm64-v8a' || matrix.emulator-arch }} + ndk: ${{ env.NDK_VERSION }} + emulator-boot-timeout: 120 + script: /tmp/rust-android-run-tests-on-emulator.sh + env: + TARGET: ${{ matrix.target }} diff --git a/build.rs b/build.rs index acb1ed7e..54e79871 100644 --- a/build.rs +++ b/build.rs @@ -11,7 +11,7 @@ use std::env; const BINDINGS: &str = "bindings.rs"; #[cfg(feature = "gecko")] -fn clang_args(_target_os: &str) -> Vec { +fn clang_args() -> Vec { use mozbuild::{config::BINDGEN_SYSTEM_FLAGS, TOPOBJDIR}; let mut flags: Vec = BINDGEN_SYSTEM_FLAGS.iter().map(|s| s.to_string()).collect(); @@ -29,18 +29,6 @@ fn clang_args(_target_os: &str) -> Vec { flags } -#[cfg(not(feature = "gecko"))] -fn clang_args(target_os: &str) -> Vec { - match target_os { - "android" => { - let sysroot = - env::var("CARGO_NDK_SYSROOT_PATH").expect("CARGO_NDK_SYSROOT_PATH was not set"); - vec![format!("--sysroot={sysroot}")] - } - _ => Vec::new(), - } -} - fn bindgen() { let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set"); @@ -72,7 +60,7 @@ fn bindgen() { }; let bindings = bindings - .clang_args(clang_args(&target_os)) + .clang_args(clang_args()) // Tell cargo to invalidate the built crate whenever any of the // included header files changed. .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) From 1736dcd768fae52b85b0ddc5b2b367aa01156f6f Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 12 Mar 2025 14:25:47 +0200 Subject: [PATCH 2/3] Again --- build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.rs b/build.rs index 54e79871..a6498195 100644 --- a/build.rs +++ b/build.rs @@ -29,6 +29,11 @@ fn clang_args() -> Vec { flags } +#[cfg(not(feature = "gecko"))] +const fn clang_args() -> Vec { + Vec::new() +} + fn bindgen() { let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS was not set"); From a3b504fc17666fe8cc7b283b06a1c7137b79a332 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Wed, 12 Mar 2025 14:32:20 +0200 Subject: [PATCH 3/3] Minimize diff --- .github/workflows/check.yml | 126 ++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 01ea8856..5e1040a4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -431,66 +431,66 @@ jobs: # emulator-arch: arm64-v8 steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: false - - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - repository: mozilla/neqo - sparse-checkout: | - .github/actions/rust - path: neqo - persist-credentials: false - - - uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 - with: - distribution: zulu - java-version: 23 - - - uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2 - - run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}" - - - uses: ./neqo/.github/actions/rust - with: - version: stable - targets: ${{ matrix.target }} - tools: cargo-ndk - token: ${{ secrets.GITHUB_TOKEN }} - - - run: cargo ndk --bindgen -t ${{ matrix.target }} test --no-run - - - env: - TARGET: ${{ matrix.target }} - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - cat <<'EOF' > /tmp/rust-android-run-tests-on-emulator.sh - #!/bin/bash - set -e - adb shell ip addr show - export GITHUB_ACTIONS=1 - adb wait-for-device - while [ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]; do sleep 1; done - any_failures=0 - for test in $(find target/$TARGET/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do - adb push "$test" /data/local/tmp/ - adb shell chmod +x /data/local/tmp/$(basename "$test") - # See https://unix.stackexchange.com/a/451140/409256 - adb shell "API_LEVEL=$API_LEVEL /data/local/tmp/$(basename "$test") || echo _FAIL_" 2>&1 | tee output - grep _FAIL_ output && any_failures=1 - done - exit $any_failures - EOF - chmod a+x /tmp/rust-android-run-tests-on-emulator.sh - - - uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # v2.33.0 - with: - api-level: ${{ env.API_LEVEL }} - arch: ${{ matrix.emulator-arch == 'arm64-v8' && 'arm64-v8a' || matrix.emulator-arch }} - ndk: ${{ env.NDK_VERSION }} - emulator-boot-timeout: 120 - script: /tmp/rust-android-run-tests-on-emulator.sh - env: - TARGET: ${{ matrix.target }} + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: mozilla/neqo + sparse-checkout: | + .github/actions/rust + path: neqo + persist-credentials: false + + - uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 + with: + distribution: zulu + java-version: 23 + + - uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2 + - run: sdkmanager --install "ndk;${{ env.NDK_VERSION }}" + + - uses: ./neqo/.github/actions/rust + with: + version: stable + targets: ${{ matrix.target }} + tools: cargo-ndk + token: ${{ secrets.GITHUB_TOKEN }} + + - run: cargo ndk --bindgen -t ${{ matrix.target }} test --no-run + + - env: + TARGET: ${{ matrix.target }} + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + cat <<'EOF' > /tmp/rust-android-run-tests-on-emulator.sh + #!/bin/bash + set -e + adb shell ip addr show + export GITHUB_ACTIONS=1 + adb wait-for-device + while [ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]; do sleep 1; done + any_failures=0 + for test in $(find target/$TARGET/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do + adb push "$test" /data/local/tmp/ + adb shell chmod +x /data/local/tmp/$(basename "$test") + # See https://unix.stackexchange.com/a/451140/409256 + adb shell "API_LEVEL=$API_LEVEL /data/local/tmp/$(basename "$test") || echo _FAIL_" 2>&1 | tee output + grep _FAIL_ output && any_failures=1 + done + exit $any_failures + EOF + chmod a+x /tmp/rust-android-run-tests-on-emulator.sh + + - uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # v2.33.0 + with: + api-level: ${{ env.API_LEVEL }} + arch: ${{ matrix.emulator-arch == 'arm64-v8' && 'arm64-v8a' || matrix.emulator-arch }} + ndk: ${{ env.NDK_VERSION }} + emulator-boot-timeout: 120 + script: /tmp/rust-android-run-tests-on-emulator.sh + env: + TARGET: ${{ matrix.target }}