Skip to content

Commit 4611eb9

Browse files
Add android-riscv64 build to workflows (#256)
The Android NDK supports building for RISC-V as of version r27. Add it to the build workflows here to improve coverage of the RISC-V code. Fixes: #206
1 parent 209b00c commit 4611eb9

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
cmake-android:
7474
strategy:
7575
matrix:
76-
script: [android-arm64-build.sh, android-armv7-build.sh, android-x86-build.sh]
76+
script: [android-arm64-build.sh, android-armv7-build.sh, android-riscv64-build.sh, android-x86-build.sh]
7777
runs-on: ubuntu-latest
7878
timeout-minutes: 40
7979
steps:
@@ -86,7 +86,7 @@ jobs:
8686
id: setup-ndk
8787
uses: nttld/[email protected]
8888
with:
89-
ndk-version: r23b
89+
ndk-version: r27
9090
add-to-path: false
9191
- name: Configure and build
9292
run: scripts/${{ matrix.script }}

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ IF(CPUINFO_SUPPORTED_PLATFORM)
218218
ELSEIF(CPUINFO_TARGET_PROCESSOR MATCHES "^(riscv(32|64))$")
219219
LIST(APPEND CPUINFO_SRCS
220220
src/riscv/uarch.c)
221-
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
221+
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
222222
LIST(APPEND CPUINFO_SRCS
223223
src/riscv/linux/init.c
224224
src/riscv/linux/riscv-hw.c

scripts/android-riscv64-build.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
if [ -z "$ANDROID_NDK" ]
6+
then
7+
echo "ANDROID_NDK not set; please set it to the Android NDK directory"
8+
exit 1
9+
fi
10+
11+
if [ ! -d "$ANDROID_NDK" ]
12+
then
13+
echo "ANDROID_NDK not a directory; did you install it under ${ANDROID_NDK}?"
14+
exit 1
15+
fi
16+
17+
mkdir -p build/android/riscv64
18+
19+
CMAKE_ARGS=()
20+
21+
# CMake-level configuration
22+
CMAKE_ARGS+=("-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake")
23+
CMAKE_ARGS+=("-DCMAKE_BUILD_TYPE=Release")
24+
CMAKE_ARGS+=("-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
25+
26+
# If Ninja is installed, prefer it to Make
27+
if [ -x "$(command -v ninja)" ]
28+
then
29+
CMAKE_ARGS+=("-GNinja")
30+
fi
31+
32+
CMAKE_ARGS+=("-DCPUINFO_LIBRARY_TYPE=static")
33+
# CMakeLists for Google Benchmark is broken on Android
34+
CMAKE_ARGS+=("-DCPUINFO_BUILD_BENCHMARKS=OFF")
35+
CMAKE_ARGS+=("-DCPUINFO_BUILD_TOOLS=ON")
36+
CMAKE_ARGS+=("-DCPUINFO_BUILD_UNIT_TESTS=ON")
37+
CMAKE_ARGS+=("-DCPUINFO_BUILD_MOCK_TESTS=ON")
38+
39+
# Android-specific options
40+
CMAKE_ARGS+=("-DANDROID_NDK=$ANDROID_NDK")
41+
CMAKE_ARGS+=("-DANDROID_ABI=riscv64")
42+
CMAKE_ARGS+=("-DANDROID_PLATFORM=android-35")
43+
CMAKE_ARGS+=("-DANDROID_PIE=ON")
44+
CMAKE_ARGS+=("-DANDROID_STL=c++_static")
45+
CMAKE_ARGS+=("-DANDROID_CPP_FEATURES=exceptions")
46+
47+
# Use-specified CMake arguments go last to allow overridding defaults
48+
CMAKE_ARGS+=($@)
49+
50+
cd build/android/riscv64 && cmake ../../.. \
51+
"${CMAKE_ARGS[@]}"
52+
53+
# Cross-platform parallel build
54+
if [ "$(uname)" == "Darwin" ]
55+
then
56+
cmake --build . -- "-j$(sysctl -n hw.ncpu)"
57+
else
58+
cmake --build . -- "-j$(nproc)"
59+
fi

0 commit comments

Comments
 (0)