Skip to content

Commit c5eee4b

Browse files
committed
Make: Test Android cross-compilation in CI
1 parent 71424d5 commit c5eee4b

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

.github/workflows/prerelease.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,16 @@ jobs:
457457
cmake --build build_artifacts --config RelWithDebInfo
458458
459459
# We can't run the produced builds, but we can make sure they exist
460-
- name: Test artifacts presense
460+
- name: Test artifacts presence
461461
run: |
462462
test -e build_artifacts/libusearch_c.so
463463
test -e build_artifacts/libusearch_sqlite.so
464464
465-
test_ubuntu_android_ndk:
466-
name: Android NDK Build
465+
test_android:
466+
name: Android
467467
runs-on: ubuntu-22.04
468468
strategy:
469+
fail-fast: false
469470
matrix:
470471
include:
471472
- processor: armv7a
@@ -478,7 +479,7 @@ jobs:
478479
- uses: actions/checkout@v4
479480
- run: git submodule update --init --recursive
480481

481-
- name: Install NDK ndk
482+
- name: Install NDK
482483
run: |
483484
${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --install "ndk;${{ env.ANDROID_NDK_VERSION }}"
484485
@@ -498,9 +499,8 @@ jobs:
498499
cmake --build build_artifacts --config RelWithDebInfo
499500
500501
# We can't run the produced builds, but we can make sure they exist
501-
- name: Test artifacts presense
502-
run: |
503-
test -e build_artifacts/libusearch_c.so
502+
- name: Test artifacts presence
503+
run: test -e build_artifacts/libusearch_c.so
504504

505505
# Rust
506506
- name: Set up Rust
@@ -521,5 +521,20 @@ jobs:
521521
echo "CARGO_${{ matrix.target }}=${TOOLCHAIN}/llvm-ar" >> ${GITHUB_ENV}
522522
523523
- name: Build Rust
524+
run: cargo build --target ${{ matrix.target }}
525+
526+
# Java
527+
- name: Set up JDK 21
528+
uses: actions/setup-java@v4
529+
with:
530+
java-version: "21"
531+
distribution: "adopt"
532+
533+
# We skip native compilation with Gradle and focus just on the Java part,
534+
# assuming the we won't be able to tun the tests without emulation
535+
- name: Test Java bindings with Android library
524536
run: |
525-
cargo build --target ${{ matrix.target }}
537+
mkdir -p build/libs/usearch/shared/
538+
cp build_artifacts/libusearch_c.so build/libs/usearch/shared/
539+
javac -cp . java/cloud/unum/usearch/*.java
540+
echo "Java compilation successful with Android NDK library"

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,38 @@ cmake -D CMAKE_BUILD_TYPE=Release \
156156
cmake --build build_artifacts --config Release
157157
```
158158

159+
For Android development, you can cross-compile for ARM architectures without requiring the full Android NDK setup.
160+
Here's an example targeting 32-bit ARM (`armeabi-v7a`):
161+
162+
```sh
163+
sudo apt-get update
164+
sudo apt-get install -y clang lld crossbuild-essential-armhf
165+
166+
# Cross-compile for 32-bit ARM (Android compatible)
167+
CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
168+
cmake -B build_artifacts \
169+
-D CMAKE_C_COMPILER=clang \
170+
-D CMAKE_CXX_COMPILER=clang++ \
171+
-D CMAKE_C_COMPILER_TARGET=armv7-linux-gnueabihf \
172+
-D CMAKE_CXX_COMPILER_TARGET=armv7-linux-gnueabihf \
173+
-D CMAKE_SYSTEM_NAME=Linux \
174+
-D CMAKE_SYSTEM_PROCESSOR=armv7 \
175+
-D CMAKE_C_FLAGS="--target=armv7-linux-gnueabihf -march=armv7-a" \
176+
-D CMAKE_CXX_FLAGS="--target=armv7-linux-gnueabihf -march=armv7-a" \
177+
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
178+
-D USEARCH_BUILD_LIB_C=1 \
179+
-D USEARCH_BUILD_TEST_CPP=0 \
180+
-D USEARCH_BUILD_BENCH_CPP=0 \
181+
-D USEARCH_USE_SIMSIMD=0 \
182+
-D USEARCH_USE_FP16LIB=1
183+
184+
cmake --build build_artifacts --config RelWithDebInfo
185+
file build_artifacts/libusearch_c.so # Verify the output
186+
# Should show: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, ...
187+
```
188+
189+
The resulting `libusearch_c.so` can be used in Android projects by placing it in `src/main/jniLibs/armeabi-v7a/` for 32-bit ARM or `arm64-v8a/` for 64-bit ARM.
190+
159191
## Python 3
160192

161193
Python bindings are built using PyBind11 and are available on [PyPi](https://pypi.org/project/usearch/).

0 commit comments

Comments
 (0)