Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 51 additions & 189 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name: Android
Comment thread
oech3 marked this conversation as resolved.
Resolved

# spell-checker:ignore (people) reactivecircus juliangruber
# spell-checker:ignore (shell/tools) TERMUX nextest udevadm pkill cmdline commandlinetools sdkmanager
# spell-checker:ignore (misc) swiftshader playstore noaudio
# spell-checker:ignore (people) reactivecircus
# spell-checker:ignore (shell/tools) udevadm
# spell-checker:ignore (misc) noaudio
env:
Comment thread
oech3 marked this conversation as resolved.
Resolved
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER: "x86_64-linux-android28-clang"
CARGO_INCREMENTAL: "0"
RUST_BACKTRACE: "1"

on:
pull_request:
push:
branches:
- '*'


permissions:
contents: read # to fetch code (actions/checkout)

Expand All @@ -19,200 +21,60 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
TERMUX: v0.118.0
KEY_POSTFIX: nextest+rustc-hash+adb+sshd+upgrade+XGB+inc18
COMMON_EMULATOR_OPTIONS: -no-metrics -no-window -noaudio -no-boot-anim -camera-back none -gpu off
EMULATOR_DISK_SIZE: 12GB
EMULATOR_HEAP_SIZE: 2048M
EMULATOR_BOOT_TIMEOUT: 1200 # 20min

jobs:
test_android:
name: ${{ matrix.test-suite == 'all' && 'Test builds' || 'Checksum and wc tests' }} (API ${{ matrix.api-level }}, ${{ matrix.arch }})
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest] # , macos-latest
cores: [4] # , 6
ram: [4096]
api-level: [28, "37.0"]
target: [google_apis_playstore]
arch: [x86_64] # ,x86 ,arm64-v8a
include:
- api-level: 28
test-suite: all
# Keep full-suite coverage on API 28. API 37 has separate filesystem
# and libc compatibility failures; cover the CPU-feature consumers here.
- api-level: "37.0"
test-suite: cksum-wc
runs-on: ${{ matrix.os }}
env:
EMULATOR_RAM_SIZE: ${{ matrix.ram }}
EMULATOR_CORES: ${{ matrix.cores }}
RUNNER_OS: ${{ matrix.os }}
AVD_CACHE_KEY: "set later due to limitations of github actions not able to concatenate env variables"
test:
name: test
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Concatenate values to environment file
run: |
echo "AVD_CACHE_KEY=${{ matrix.os }}-${{ matrix.cores }}-${{ matrix.ram }}-${{ matrix.api-level }}-${{ matrix.target }}-${{ matrix.arch }}+termux-${{ env.TERMUX }}+${{ env.KEY_POSTFIX }}" >> $GITHUB_ENV
- name: Collect information about runner
if: always()
continue-on-error: true
run: |
hostname
uname -a
free -mh
df -Th
cat /proc/cpuinfo
- name: (Linux) create links from home to data partition
if: ${{ runner.os == 'Linux' }}
continue-on-error: true
run: |
ls -lah /mnt/
sudo mkdir /mnt/data
sudo chmod a+rwx /mnt/data
mkdir /mnt/data/.android && ln -s /mnt/data/.android ~/.android
mkdir /mnt/data/work && ln -s /mnt/data/work ~/work
- name: Enable KVM group perms (linux hardware acceleration)
if: ${{ runner.os == 'Linux' }}
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
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- name: Install Android SDK command-line tools 22.0
run: |
curl --fail --location --retry 3 --output "$RUNNER_TEMP/commandlinetools.zip" \
https://dl.google.com/android/repository/commandlinetools-linux-15859902_latest.zip
unzip -q "$RUNNER_TEMP/commandlinetools.zip" -d "$RUNNER_TEMP/android-tools"
mv "$ANDROID_HOME/cmdline-tools/latest" "$RUNNER_TEMP/android-tools-previous"
mv "$RUNNER_TEMP/android-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --version
- name: Collect information about runner
if: always()
continue-on-error: true
run: |
free -mh
df -Th
- name: Restore AVD cache
uses: actions/cache/restore@v6
id: avd-cache
continue-on-error: true
- uses: dtolnay/rust-toolchain@stable
with:
path: |
~/.android/avd/*
~/.android/avd/*/snapshots/*
~/.android/adb*
~/__rustc_hash__
key: avd-${{ env.AVD_CACHE_KEY }}
- name: Collect information about runner after AVD cache
if: always()
targets: x86_64-linux-android
- uses: Swatinem/rust-cache@v2
Comment thread
oech3 marked this conversation as resolved.
Resolved
- name: Run sccache-cache
id: sccache-setup
uses: mozilla-actions/sccache-action@v0.0.11
continue-on-error: true
- name: Export sccache
if: steps.sccache-setup.outcome == 'success'
run: |
free -mh
df -Th
ls -lah /mnt/data
du -sch /mnt/data
- name: Delete AVD Lockfile when run from cache
if: steps.avd-cache.outputs.cache-hit == 'true'
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
- name: Set up Android NDK
run: |
rm -f \
~/.android/avd/*.avd/*.lock \
~/.android/avd/*/*.lock
- name: Create and cache emulator image
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2.38.0
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
ram-size: ${{ env.EMULATOR_RAM_SIZE }}
heap-size: ${{ env.EMULATOR_HEAP_SIZE }}
disk-size: ${{ env.EMULATOR_DISK_SIZE }}
cores: ${{ env.EMULATOR_CORES }}
force-avd-creation: true
disable-animations: false
emulator-options: ${{ env.COMMON_EMULATOR_OPTIONS }} -no-snapshot-load
emulator-boot-timeout: ${{ env.EMULATOR_BOOT_TIMEOUT }}
script: |
util/android-commands.sh init "${{ matrix.arch }}" "${{ matrix.api-level }}" "${{ env.TERMUX }}"
- name: Save AVD cache
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: |
~/.android/avd/*
~/.android/avd/*/snapshots/*
~/.android/adb*
~/__rustc_hash__
key: avd-${{ env.AVD_CACHE_KEY }}
- uses: juliangruber/read-file-action@v1
id: read_rustc_hash
with:
# ~ expansion didn't work
path: ${{ runner.os == 'Linux' && '/home/runner/__rustc_hash__' || '/Users/runner/__rustc_hash__' }}
trim: true
- name: Restore rust cache
id: rust-cache
uses: actions/cache/restore@v6
with:
path: ~/__rust_cache__
# The version vX at the end of the key is just a development version to avoid conflicts in
# the github cache during the development of this workflow
key: ${{ matrix.arch }}_${{ matrix.target}}_${{ steps.read_rustc_hash.outputs.content }}_${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}_v3
- name: Collect information about runner resources
if: always()
continue-on-error: true
echo "${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
- name: prepare testing
run: |
free -mh
df -Th
- name: Build and Test
set -euo pipefail
# FIXME: some ls::* depends on unask 022
cargo test --target x86_64-linux-android --no-run --features feat_os_unix_android --message-format=json \
| jq -rs '
[ .[] | select(.executable != null) | .executable | select(test("/coreutils$") | not) ]
| unique
| .[]
' | sed 's#^.*$#adb push & /data/local/tmp/tester\nadb shell "cd /data/local/tmp \&\& umask 022 \&\& TERM=xterm-256color \&\& /data/local/tmp/tester"#' > tests.sh
cat tests.sh
- name: Enable KVM (hardware acceleration)
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
- name: tests
uses: reactivecircus/android-emulator-runner@v2.38.0
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
ram-size: ${{ env.EMULATOR_RAM_SIZE }}
heap-size: ${{ env.EMULATOR_HEAP_SIZE }}
disk-size: ${{ env.EMULATOR_DISK_SIZE }}
cores: ${{ env.EMULATOR_CORES }}
force-avd-creation: false
disable-animations: false
emulator-options: ${{ env.COMMON_EMULATOR_OPTIONS }} -no-snapshot-save -snapshot ${{ env.AVD_CACHE_KEY }}
emulator-boot-timeout: ${{ env.EMULATOR_BOOT_TIMEOUT }}
# This is not a usual script. Every line is executed in a separate shell with `sh -c`. If
# one of the lines returns with error the whole script is failed (like running a script with
# set -e) and in consequences the other lines (shells) are not executed.
api-level: 28
disable-animations: true
emulator-options: -no-metrics -no-window -noaudio -no-boot-anim -camera-back none -gpu off
target: default
arch: x86_64
script: |
timeout --verbose --kill-after=30s 10m util/android-commands.sh sync_host
util/android-commands.sh build
util/android-commands.sh tests "${{ matrix.test-suite }}"
if [ "${{ steps.rust-cache.outputs.cache-hit }}" != 'true' ]; then util/android-commands.sh sync_image; fi; exit 0
- name: Collect information about runner resources
if: always()
continue-on-error: true
run: |
free -mh
df -Th
- name: Save rust cache
if: steps.rust-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: ~/__rust_cache__
key: ${{ matrix.arch }}_${{ matrix.target}}_${{ steps.read_rustc_hash.outputs.content }}_${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}_v3
- name: archive any output (error screenshots)
if: always()
uses: actions/upload-artifact@v7
with:
name: test_output_${{ env.AVD_CACHE_KEY }}
path: output
- name: Collect information about runner resources
if: always()
continue-on-error: true
run: |
free -mh
df -Th
adb root
adb shell setenforce 0
adb shell "mkdir -p /data/data/com.termux/files/usr/bin && ln -svf /system/bin/sh /data/data/com.termux/files/usr/bin/sh" # needed for test_stat
adb unroot
adb push tests/fixtures/. /data/local/tmp/tests/fixtures/
adb push target/x86_64-linux-android/debug/coreutils /data/local/tmp/coreutils
sh -e ./tests.sh
18 changes: 3 additions & 15 deletions src/uucore/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,6 @@ fn embed_locale_file(
Ok(())
}

/// Higher-level helper to embed locale files for a component with a path pattern.
///
/// This eliminates the repetitive `for_each_locale` + `embed_locale_file` pattern.
///
/// # Errors
///
/// Returns an error if `for_each_locale` fails, which typically happens if
/// reading a locale file or writing to the `embedded_file` fails.
/// Check if we are cross-compiling for WASI (build.rs runs on the host,
/// so `#[cfg(target_os = "wasi")]` does not work here).
fn is_wasi_target() -> bool {
env::var("CARGO_CFG_TARGET_OS").is_ok_and(|os| os == "wasi")
}

/// For WASI/WASM builds, embed ALL available .ftl files in a locale
/// directory so the playground can switch languages at runtime.
fn embed_all_locales_for_component<F>(
Expand Down Expand Up @@ -456,7 +442,9 @@ fn embed_component_locales<F>(
where
F: Fn(&str) -> PathBuf,
{
if is_wasi_target() {
// we want to embedded locales on some targets to make publishing easier.
// cfg does not work for cross-building.
if env::var("CARGO_CFG_TARGET_OS").is_ok_and(|os| os == "wasi" || os == "android") {
return embed_all_locales_for_component(embedded_file, component_name, &path_builder);
}

Expand Down
15 changes: 8 additions & 7 deletions src/uucore/src/lib/mods/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,12 @@ fn create_english_bundle_from_embedded(
}
}

/// Create a bundle from embedded locale files for any locale on WASI.
/// Create a bundle from embedded locale files for any locale on platforms
/// to make publishing binaries easier.
/// Resources are cached per key, so it can be called for multiple locales
/// in the same process.
#[cfg(target_os = "wasi")]
fn create_wasi_bundle_from_embedded(
#[cfg(any(target_os = "android", target_os = "wasi"))]
fn create_bundle_from_embedded(
locale: &LanguageIdentifier,
util_name: &str,
) -> Result<FluentBundle<&'static FluentResource>, LocalizationError> {
Expand Down Expand Up @@ -642,19 +643,19 @@ pub fn setup_localization(p: &str) -> Result<(), LocalizationError> {
let default_locale = LanguageIdentifier::from_str(DEFAULT_LOCALE)
.expect("Default locale should always be valid");

#[cfg(target_os = "wasi")]
#[cfg(any(target_os = "android", target_os = "wasi"))]
let localizer = {
let english_bundle = create_wasi_bundle_from_embedded(&default_locale, p)?;
let english_bundle = create_bundle_from_embedded(&default_locale, p)?;
if locale == default_locale {
Localizer::new(english_bundle)
} else if let Ok(localized) = create_wasi_bundle_from_embedded(&locale, p) {
} else if let Ok(localized) = create_bundle_from_embedded(&locale, p) {
Localizer::new(localized).with_fallback(english_bundle)
} else {
Localizer::new(english_bundle)
}
};

#[cfg(not(target_os = "wasi"))]
#[cfg(not(any(target_os = "android", target_os = "wasi")))]
let localizer = {
let english_bundle = create_english_bundle_from_embedded(&default_locale, p)?;
Localizer::new(english_bundle)
Expand Down
4 changes: 4 additions & 0 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9274,6 +9274,10 @@ fn test_cp_preserve_xattr_failure_keeps_the_rest() {
#[uutests::wasi_ignore(NoPermissionBits)]
#[test]
#[cfg(not(windows))]
#[cfg_attr(
target_os = "android",
ignore = "different result between adb and termux"
)]
fn test_cp_preserve_directory_permissions_by_default() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,7 @@ fn test_non_utf8_env_vars() {

#[test]
#[cfg(unix)]
#[cfg_attr(target_os = "android", ignore = "different SIGPIPE handling on adb")]
fn test_ignore_signal_pipe_broken_pipe_regression() {
// Test that --ignore-signal=PIPE properly ignores SIGPIPE in child processes.
// When SIGPIPE is ignored, processes should handle broken pipes gracefully
Expand Down
1 change: 1 addition & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ fn test_install_and_strip_with_program() {

#[cfg(all(unix, feature = "chmod"))]
#[test]
#[cfg_attr(target_os = "android", ignore = "printf ... | grep fails")]
fn test_install_and_strip_with_program_hyphen() {
let scene = TestScenario::new(util_name!());

Expand Down
3 changes: 3 additions & 0 deletions tests/by-util/test_od.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ fn test_hex32() {

// Regression: 16-bit IEEE half should print with canonical precision (no spurious digits)
#[test]
#[cfg_attr(target_os = "android", ignore = "failed with cross build")]
fn test_float16_compact() {
let input: [u8; 4] = [0x3c, 0x00, 0x3c, 0x00]; // two times 1.0 in big-endian half
new_ucmd!()
Expand Down Expand Up @@ -331,6 +332,7 @@ fn test_tf_explicit_float_still_uses_4_bytes() {
}

#[test]
#[cfg_attr(target_os = "android", ignore = "failed with cross build")]
fn test_f16() {
let input: [u8; 14] = [
0x00, 0x3c, // 0x3C00 1.0
Expand Down Expand Up @@ -358,6 +360,7 @@ fn test_f16() {
}

#[test]
#[cfg_attr(target_os = "android", ignore = "failed with cross build")]
fn test_fh() {
let input: [u8; 14] = [
0x00, 0x3c, // 0x3C00 1.0
Expand Down
Loading
Loading