Skip to content

Commit a0dc80d

Browse files
CopilotStebalien
andauthored
Add Android CI target (#367)
Co-authored-by: Steven Allen <[email protected]>
1 parent 4ad1ae6 commit a0dc80d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ env:
1111
CARGO_TARGET_WASM32_WASIP2_RUNNER: "/home/runner/.wasmtime/bin/wasmtime --dir /tmp/"
1212
RUSTFLAGS: "-D warnings"
1313
RUSTDOCFLAGS: "-D warnings"
14+
NDK_VERSION: "r26d"
15+
ANDROID_VERSION: "12.0.0"
1416

1517
name: CI
1618
jobs:
@@ -44,6 +46,15 @@ jobs:
4446
- name: "MacOS"
4547
os: macos-latest
4648
target: aarch64-apple-darwin
49+
- name: "Android"
50+
os: ubuntu-latest
51+
target: x86_64-linux-android
52+
exclude:
53+
- rust-version: "1.63"
54+
platform:
55+
name: "Android"
56+
os: ubuntu-latest
57+
target: x86_64-linux-android
4758
include:
4859
- rust-version: "nightly"
4960
test-flags: --tests
@@ -75,10 +86,50 @@ jobs:
7586
- name: Install Wasmtime
7687
if: ${{ startsWith(matrix.platform.target, 'wasm32-wasi') }}
7788
run: curl https://wasmtime.dev/install.sh -sSf | bash
89+
- name: Setup Android Environment
90+
if: ${{ contains(matrix.platform.target, 'android') }}
91+
run: |
92+
NDK_URL="https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip"
93+
NDK_DIR="${HOME}/android-ndk-${NDK_VERSION}"
94+
95+
# Download and extract NDK
96+
echo "Downloading NDK from $NDK_URL"
97+
wget -q "$NDK_URL" -O android-ndk.zip
98+
unzip -q android-ndk.zip -d "$HOME"
99+
100+
# Set ANDROID_NDK_ROOT environment variable
101+
echo "ANDROID_NDK_ROOT=$NDK_DIR" >> $GITHUB_ENV
102+
103+
# Setup & start redroid container
104+
sudo apt-get install -y linux-modules-extra-$(uname -r) android-tools-adb
105+
sudo modprobe binder_linux devices=binder,hwbinder,vndbinder
106+
107+
docker run -itd --rm --privileged \
108+
--mount "type=bind,src=$(pwd),dst=/data/host$(pwd),ro" \
109+
--mount "type=bind,src=/tmp,dst=/data/host/tmp,ro" \
110+
--mount "type=bind,src=$(pwd)/.github/workflows/run-on-host.sh,dst=/system/xbin/run-on-host,ro" \
111+
--name redroid-test \
112+
-p 5555:5555 \
113+
redroid/redroid:${ANDROID_VERSION}_64only-latest
114+
115+
# Start ADB server and connect to our redroid container
116+
adb start-server
117+
timeout 60 bash -c 'until adb connect localhost:5555; do sleep 2; done'
118+
119+
# Configure Android environment
120+
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER=adb -s localhost:5555 shell run-on-host" >> $GITHUB_ENV
121+
echo "CC_X86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV
122+
echo "AR_x86_64_linux_android=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" >> $GITHUB_ENV
123+
echo "CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android34-clang" >> $GITHUB_ENV
124+
echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_RUSTFLAGS=-C link-arg=-Wl,--as-needed" >> $GITHUB_ENV
78125
- name: Build
79126
run: cargo build --target ${{ matrix.platform.target }} ${{ matrix.rust-version == 'nightly' && '--features nightly' || '' }}
80127
- name: Test
81128
run: cargo test --target ${{ matrix.platform.target }} ${{ matrix.rust-version == 'nightly' && '--features nightly' || '' }} ${{ matrix.test-flags }}
129+
- name: Stop the redroid container
130+
if: ${{ contains(matrix.platform.target, 'android') }}
131+
run: |
132+
docker stop redroid-test || true
82133
wasm:
83134
name: WASM Test Build
84135
runs-on: ubuntu-latest

.github/workflows/run-on-host.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/system/bin/sh
2+
3+
CMD="$1"
4+
shift
5+
6+
cd /data/local/tmp || exit 1
7+
exec "/data/host$CMD" "$@"

0 commit comments

Comments
 (0)