Skip to content

Commit

Permalink
android ci (#52)
Browse files Browse the repository at this point in the history
* android ci

* on

* arm names

* can't shutdown

* no arm for now

* google_apis

* try 29

* additional setup

* another cflags

* asm in arch dir

* woops

* fixes

* cache?

* target cc

* cleanup
  • Loading branch information
neonphog authored Sep 21, 2023
1 parent 8d0e743 commit da9a8fd
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 28 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Android Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: macos-latest
strategy:
matrix:
#android-arch: ["arm64-v8a", "x86_64"]
android-arch: ["x86_64"]
android-api-level: [29]
android-ndk-version: ["26.0.10792818"]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Go Toolchain
uses: actions/setup-go@v3
with:
go-version: '=1.18.0'

- name: Rust Toolchain
run: |
rustup toolchain install stable --profile minimal --no-self-update
#rustup target add aarch64-linux-android
rustup target add x86_64-linux-android
- name: Rust Cache
uses: Swatinem/rust-cache@v2

- name: Avd Cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.android-api-level }}

- name: Avd Snapshot
if: steps.avd-cache.outputs.cache-hit != 'true'
env:
ANDROID_API_LEVEL: ${{ matrix.android-api-level }}
ANDROID_NDK_VERSION: ${{ matrix.android-ndk-version }}
ANDROID_ARCH: ${{ matrix.android-arch }}
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.android-api-level }}
ndk: ${{ matrix.android-ndk-version }}
arch: ${{ matrix.android-arch }}
target: google_apis
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Build and Run Tests
env:
ANDROID_API_LEVEL: ${{ matrix.android-api-level }}
ANDROID_NDK_VERSION: ${{ matrix.android-ndk-version }}
ANDROID_ARCH: ${{ matrix.android-arch }}
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.android-api-level }}
ndk: ${{ matrix.android-ndk-version }}
arch: ${{ matrix.android-arch }}
target: google_apis
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./android-build-tests.bash && ./android-run-tests.bash
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/output-*
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ members = [
"crates/tx5-go-pion-turn",
]

[profile.release]
strip = true

[workspace.dependencies]
base64 = "0.13.0"
bytes = "1.4.0"
Expand All @@ -28,6 +31,7 @@ lair_keystore_api = "0.3.0"
libc = "0.2.141"
libloading = "0.8.0"
once_cell = "1.17.1"
openssl-sys = { version = "0.9.90", features = [ "vendored" ] }
opentelemetry_api = { version = "=0.20.0-beta.1", features = [ "metrics" ], package = "ts_opentelemetry_api" }
ouroboros = "0.15.6"
parking_lot = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ tool_clippy: tool_rust
tool_readme: tool_rust
@if ! (cargo rdme --version); \
then \
cargo install cargo-rdme --version 1.4.0; \
cargo install cargo-rdme --version 1.4.0 --locked; \
else \
echo "# Makefile # readme ok"; \
fi;
47 changes: 47 additions & 0 deletions android-build-tests.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -eEuxo pipefail

if [[ "${ANDROID_API_LEVEL:-x}" == "x" ]]; then
echo "ANDROID_API_LEVEL required"
exit 127
fi

if [[ "${ANDROID_NDK_VERSION:-x}" == "x" ]]; then
echo "ANDROID_NDK_VERSION required"
exit 127
fi

if [[ "${ANDROID_ARCH:-x}" == "x" ]]; then
echo "ANDROID_ARCH required"
exit 127
else
if [[ "${ANDROID_ARCH}" == "arm64-v8a" ]]; then
export ANDROID_ARCH="aarch64"
fi
fi


if [[ "${ANDROID_SDK_ROOT:-x}" == "x" ]]; then
echo "ANDROID_SDK_ROOT required"
exit 127
fi

_ndk_root=(${ANDROID_SDK_ROOT}/ndk/${ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/*)

# This workaround may be needed if upgrading android api level
#cat << EOF > ${_ndk_root}/lib/clang/17/lib/linux/${ANDROID_ARCH}/libgcc.a
#INPUT(-lunwind)
#EOF

export PKG_CONFIG_SYSROOT_DIR="${_ndk_root}/sysroot"
export TARGET_CC="${_ndk_root}/bin/${ANDROID_ARCH}-linux-android${ANDROID_API_LEVEL}-clang"
export TARGET_CFLAGS="-I${_ndk_root}/sysroot/usr/include -I${_ndk_root}/sysroot/usr/include/${ANDROID_ARCH}-linux-android"
export TARGET_AR="${_ndk_root}/bin/llvm-ar"
export TARGET_RANLIB="${_ndk_root}/bin/llvm-ranlib"
export CGO_CFLAGS="-I${_ndk_root}/sysroot/usr/include -I${_ndk_root}/sysroot/usr/include/${ANDROID_ARCH}-linux-android"

cargo test --no-run --release --target ${ANDROID_ARCH}-linux-android --config target.${ANDROID_ARCH}-linux-android.linker="\"${_ndk_root}/bin/${ANDROID_ARCH}-linux-android34-clang\"" --config target.${ANDROID_ARCH}-linux-android.ar="\"${_ndk_root}/bin/llvm-ar\"" 2>&1 | tee output-cargo-test
cat output-cargo-test | grep Executable | sed -E 's/[^(]*\(([^)]*)\)/\1/' > output-test-executables
echo "BUILD TESTS:"
cat output-test-executables
8 changes: 8 additions & 0 deletions android-run-tests.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -eEuxo pipefail

for i in $(cat output-test-executables); do
adb push $i /data/local/tmp/$(basename $i)
adb shell /data/local/tmp/$(basename $i)
done
1 change: 1 addition & 0 deletions crates/tx5-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bytes = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
influxive = { workspace = true }
openssl-sys = { workspace = true }
opentelemetry_api = { workspace = true }
rand = { workspace = true }
serde = { workspace = true }
Expand Down
87 changes: 68 additions & 19 deletions crates/tx5-go-pion-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ fn go_build() {

let mut lib_path = out_dir.clone();

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos"))]
lib_path.push("go-pion-webrtc.dylib");
#[cfg(target_os = "windows")]
lib_path.push("go-pion-webrtc.dll");
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "windows"
)))]
lib_path.push("go-pion-webrtc.so");
let tgt_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();

match tgt_os.as_str() {
"macos" | "ios" | "tvos" => {
lib_path.push("go-pion-webrtc.dylib");
}
"windows" => {
lib_path.push("go-pion-webrtc.dll");
}
_ => {
lib_path.push("go-pion-webrtc.so");
}
}

let mut cache = out_dir.clone();
cache.push("go-build");
Expand Down Expand Up @@ -101,14 +103,61 @@ fn go_build() {
let mut cmd = Command::new("go");

// add some cross-compilation translators:
#[cfg(target_arch = "arm")]
cmd.env("GOARCH", "arm");
#[cfg(target_arch = "aarch64")]
cmd.env("GOARCH", "arm64");
#[cfg(target_arch = "x86_64")]
cmd.env("GOARCH", "amd64");
#[cfg(target_arch = "x86")]
cmd.env("GOARCH", "386");
match std::env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"arm" => {
cmd.env("GOARCH", "arm");
}
"aarch64" => {
cmd.env("GOARCH", "arm64");
}
"x86_64" => {
cmd.env("GOARCH", "amd64");
}
"x86" => {
cmd.env("GOARCH", "386");
}
_ => (),
}

// and for the os
match tgt_os.as_str() {
"windows" => {
cmd.env("GOOS", "windows");
}
"macos" => {
cmd.env("GOOS", "darwin");
}
"ios" => {
cmd.env("GOOS", "ios");
}
"linux" => {
cmd.env("GOOS", "linux");
}
"android" => {
cmd.env("GOOS", "android");
}
"dragonfly" => {
cmd.env("GOOS", "dragonfly");
}
"freebsd" => {
cmd.env("GOOS", "freebsd");
}
"openbsd" => {
cmd.env("GOOS", "openbsd");
}
"netbsd" => {
cmd.env("GOOS", "netbsd");
}
_ => (),
}

if tgt_os == "android" {
let linker = std::env::var("RUSTC_LINKER").unwrap();
println!("cargo:warning=LINKER: {linker:?}");
cmd.env("CC_FOR_TARGET", &linker);
cmd.env("CC", &linker);
cmd.env("CGO_ENABLED", "1");
}

// grr, clippy, the debug symbols belong in one arg
#[allow(clippy::suspicious_command_arg_space)]
Expand Down
64 changes: 56 additions & 8 deletions crates/tx5-go-pion-turn/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,62 @@ fn go_build(path: &std::path::Path) {
let mut cmd = Command::new("go");

// add some cross-compilation translators:
#[cfg(target_arch = "arm")]
cmd.env("GOARCH", "arm");
#[cfg(target_arch = "aarch64")]
cmd.env("GOARCH", "arm64");
#[cfg(target_arch = "x86_64")]
cmd.env("GOARCH", "amd64");
#[cfg(target_arch = "x86")]
cmd.env("GOARCH", "386");
match std::env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
"arm" => {
cmd.env("GOARCH", "arm");
}
"aarch64" => {
cmd.env("GOARCH", "arm64");
}
"x86_64" => {
cmd.env("GOARCH", "amd64");
}
"x86" => {
cmd.env("GOARCH", "386");
}
_ => (),
}

// and for the os
let tgt_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
match tgt_os.as_str() {
"windows" => {
cmd.env("GOOS", "windows");
}
"macos" => {
cmd.env("GOOS", "darwin");
}
"ios" => {
cmd.env("GOOS", "ios");
}
"linux" => {
cmd.env("GOOS", "linux");
}
"android" => {
cmd.env("GOOS", "android");
}
"dragonfly" => {
cmd.env("GOOS", "dragonfly");
}
"freebsd" => {
cmd.env("GOOS", "freebsd");
}
"openbsd" => {
cmd.env("GOOS", "openbsd");
}
"netbsd" => {
cmd.env("GOOS", "netbsd");
}
_ => (),
}

if tgt_os == "android" {
let linker = std::env::var("RUSTC_LINKER").unwrap();
println!("cargo:warning=LINKER: {linker:?}");
cmd.env("CC_FOR_TARGET", &linker);
cmd.env("CC", &linker);
cmd.env("CGO_ENABLED", "1");
}

// grr, clippy, the debug symbols belong in one arg
#[allow(clippy::suspicious_command_arg_space)]
Expand Down
1 change: 1 addition & 0 deletions crates/tx5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ webrtc = { workspace = true, optional = true }
criterion = { workspace = true }
influxive-child-svc = { workspace = true }
influxive = { workspace = true }
openssl-sys = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true, features = [ "macros", "rt", "rt-multi-thread", "sync" ] }
tracing-subscriber = { workspace = true }
Expand Down

0 comments on commit da9a8fd

Please sign in to comment.