Skip to content

Commit

Permalink
Add CMake support for building Android and Catch2 Tests
Browse files Browse the repository at this point in the history
Diffs=
797fb4cbd Add CMake support for building Android and Catch2 Tests (#5468)

Co-authored-by: Umberto Sonnino <[email protected]>
  • Loading branch information
umberto-sonnino and umberto-sonnino committed Jul 7, 2023
1 parent c14480d commit 3b48676
Show file tree
Hide file tree
Showing 47 changed files with 494 additions and 145 deletions.
71 changes: 1 addition & 70 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,17 @@ on:
default: false

jobs:
build-android-so:
strategy:
matrix:
arch: [ "x86", "x86_64", "arm64-v8a", "armeabi-v7a" ]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-west-2
role-to-assume: ${{ secrets.ACTIONS_ROLE }}
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.PAT_GITHUB }}

- name: Update Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '17'

- name: Installing pre-requisites
run: |
set -x
# Install some dependencies & premake5
sudo apt update && sudo apt-get -y install build-essential cmake wget clang g++ libgl1-mesa-dev libvorbis-dev libvpx-dev ninja-build
wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-linux.tar.gz
tar -xf premake-5.0.0-alpha15-linux.tar.gz
mkdir bin
cp premake5 bin/premake5
sudo chmod a+x premake5
sudo mv premake5 /usr/local/bin
- name: Cache NDK
id: cache-ndk
uses: actions/cache@v3
with:
path: |
${{github.workspace}}/android-ndk-r25b
# we are JUST going to cache for this workflow.
# really we could cache flutter way more (based on the flutter version)
key: android-ndk-r25b-linux
- name: Get and Unzip NDK
if: ${{steps.cache-ndk.outputs.cache-hit != 'true'}}
run: |
wget -q https://dl.google.com/android/repository/android-ndk-r25b-linux.zip
unzip android-ndk-r25b-linux
ls
- name: Build rive for ${{ matrix.arch }}
run: |
cd cpp && ./build.rive.for.sh -c -a ${{ matrix.arch }}
env:
NDK_PATH: ${{github.workspace}}/android-ndk-r25b
# NOTE: this is sneaky, we are adding multiple files from the matrix jobs into the same artifact
- uses: actions/upload-artifact@v3
with:
name: android-so
path: kotlin/src/main/jniLibs/*

publish:
name: Release build and publish
needs: build-android-so
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Update Java
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '17'
- uses: actions/download-artifact@v3
with:
name: android-so
path: kotlin/src/main/jniLibs/

# Base64 decodes and pipes the GPG key content into the secret file
- name: Prepare environment
Expand Down
19 changes: 12 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
ehthumbs.db
Thumbs.db

cpp/*.o
cpp/*.so
cpp/build
cpp/deps
cpp/Toolchains
kotlin/src/main/cpp/*.o
kotlin/src/main/cpp/*.so
kotlin/src/main/cpp/build
kotlin/src/main/cpp/deps
kotlin/src/main/cpp/Toolchains
kotlin/src/main/cpp/test/build
kotlin/src/main/cpp/test/build_catch_tests
kotlin/src/main/cpp/test/output
kotlin/src/main/cpp/test/Catch2

*.iml
.gradle
local.properties
.idea
.DS_Store
build
captures
build.pixel.sh
Expand All @@ -25,4 +29,5 @@ build.nexus.sh

.settings
.classpath
kotlin/src/main/jniLibs/*
kotlin/src/main/jniLibs/*
kotlin/.cxx
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7ee5f7d5a9af82205d32bfb979fdaac412b51cad
797fb4cbd547509dac0a34e1039bfad5de8cd80c
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
ndkVersion '25.1.8937393'
}

dependencies {
Expand All @@ -70,6 +71,7 @@ dependencies {
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.2.0-alpha01'
implementation 'androidx.startup:startup-runtime:1.1.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
2 changes: 2 additions & 0 deletions compatibilitytest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ android {
jvmTarget = '1.8'
}
namespace 'app.rive.runtime.compatibilitytest'
ndkVersion '25.1.8937393'
buildToolsVersion '30.0.3'
}

dependencies {
Expand Down
30 changes: 0 additions & 30 deletions cpp/src/bindings/bindings_init.cpp

This file was deleted.

16 changes: 15 additions & 1 deletion kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ apply plugin: 'org.jetbrains.dokka'
android {
compileSdkVersion 33
buildToolsVersion "30.0.3"
ndkVersion "25.1.8937393"

defaultConfig {
minSdkVersion 21
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
externalNativeBuild {
cmake {
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
arguments "-DCMAKE_VERBOSE_MAKEFILE=1", "-DANDROID_ALLOW_UNDEFINED_SYMBOLS=ON",
'-DANDROID_CPP_FEATURES=no-exceptions no-rtti', "-DANDROID_STL=c++_shared"
}
}
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.22.1'
}
}
testOptions {
unitTests.includeAndroidResources = true
}
Expand All @@ -42,7 +56,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.getkeepsafe.relinker:relinker:1.4.4'
implementation 'com.getkeepsafe.relinker:relinker:1.4.5'
implementation 'androidx.startup:startup-runtime:1.1.1'

testImplementation 'junit:junit:4.13.2'
Expand Down
File renamed without changes.
File renamed without changes.
108 changes: 108 additions & 0 deletions kotlin/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
cmake_minimum_required(VERSION 3.18.1)

project(rive-android VERSION 1.0.0 LANGUAGES CXX)

# Compile detail will be in rive-android/kotlin/.cxx/Debug/<hash>/<ABI>/compile_commands.json
# e.g: kotlin/.cxx/Debug/4o1b5h48/arm64-v8a/compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

#set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall -fno-exceptions -fno-rtti")
set(CMAKE_CXX_FLAGS_RELEASE "-Oz")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(RIVE_RUNTIME_DIR "${PROJECT_SOURCE_DIR}/../../../../../runtime")
message("LOOKED FOR: ${RIVE_RUNTIME_DIR}")
message("BUILD TYPE: ${CMAKE_BUILD_TYPE}")


#[[ CMake adds these flags depending on CMAKE_BUILD_TYPE
1. Release: `-O3 -DNDEBUG`
2. Debug: `-O0 -g`
3. RelWithDebInfo: `-O2 -g -DNDEBUG`
4. MinSizeRel: `-Os -DNDEBUG`
]]

add_definitions(-DSK_GL)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SKIA_DIR_NAME "skia_debug")
set(DEBUG_FLAG "-d")
set(CONFIG "debug")
endif ()

if (CMAKE_BUILD_TYPE STREQUAL "Release" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR
CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(SKIA_DIR_NAME "skia")
set(CONFIG "release")
endif ()

message("Skia location: ${SKIA_DIR_NAME}")

# Build dependencies.
execute_process(
COMMAND bash ./build.rive.for.sh -a ${CMAKE_ANDROID_ARCH_ABI} -b ${DEBUG_FLAG}
OUTPUT_FILE ${CMAKE_SOURCE_DIR}/rive_build_${CMAKE_ANDROID_ARCH_ABI}.log
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE SCRIPT_RESULT
OUTPUT_VARIABLE SCRIPT_OUTPUT
)

if(NOT SCRIPT_RESULT EQUAL "0")
message(FATAL_ERROR "Script returned with error: '${SCRIPT_OUTPUT}' - '${SCRIPT_RESULT}'")
endif()
include_directories(
include
${RIVE_RUNTIME_DIR}/include
${RIVE_RUNTIME_DIR}/renderer/library/include
${RIVE_RUNTIME_DIR}/skia/dependencies/${SKIA_DIR_NAME}/
${RIVE_RUNTIME_DIR}/skia/dependencies/${SKIA_DIR_NAME}/include/core
${RIVE_RUNTIME_DIR}/skia/dependencies/${SKIA_DIR_NAME}/include/effects
${RIVE_RUNTIME_DIR}/skia/dependencies/${SKIA_DIR_NAME}/include/gpu
${RIVE_RUNTIME_DIR}/skia/dependencies/${SKIA_DIR_NAME}/include/config
${RIVE_RUNTIME_DIR}/skia/renderer/include
)

file(GLOB SOURCES
src/*.cpp
src/bindings/*.cpp
src/helpers/*.cpp
src/models/*.cpp
)

add_library(rive-android SHARED ${SOURCES})

set(static_libs
rive
rive_skia_renderer
skia
)

foreach (X IN LISTS static_libs)
add_library(${X}-lib STATIC IMPORTED)
set_target_properties(${X}-lib
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/build/${CONFIG}/${CMAKE_ANDROID_ARCH_ABI}/lib${X}.a
)
endforeach ()

target_include_directories(rive-android PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

find_library(log-lib log)
find_library(android-lib android)
find_library(egl-lib EGL)
find_library(gles-lib GLESv3)
find_library(gles-fdsalib GLESv3fdas)

target_link_libraries(rive-android
rive-lib
rive_skia_renderer-lib
skia-lib

${log-lib}
${android-lib}
${egl-lib}
${gles-lib}
# ${gles-fdsalib}
)
11 changes: 8 additions & 3 deletions cpp/Makefile → kotlin/src/main/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ O_FILES = $(patsubst %.cpp,$(ODIR)/%.o,$(notdir $(SRC_FILES)))

DEPS=$(O_FILES) \
$(BUILD_DIR)/librive.a \
$(BUILD_DIR)/libc++_static.a \
$(BUILD_DIR)/libskia.a \
$(BUILD_DIR)/librive_skia_renderer.a \

LDIR=-L$(SYSROOT)/usr/lib
LIBS=-llog -landroid -lEGL -lGLESv3

# Build the .so object.
jni_bridge: $(OBJ_FILES)
$(CXX) -shared $(DEPS) -o $(BUILD_DIR)/libjnirivebridge.so --sysroot=$(SYSROOT) -I$(RIVE_RUNTIME_DIR)/include -I${RIVE_RUNTIME_DIR}/renderer/library/include -I$(INCLUDE) -I$(INCLUDE_CXX) $(LDIR) $(LIBS) $(CXXFLAGS) -static-libstdc++ -static-libgcc -ldl -Wl,--hash-style=both
$(CXX) -shared -o $(BUILD_DIR)/libjnirivebridge.so \
--target=$(TARGET_ARCH) \
--sysroot=$(SYSROOT) \
$(CXXFLAGS) \
-static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Qunused-arguments \
$(DEPS) \
$(LIBS) -latomic -lm

# BUILD all .o files - i.e. the files specified in OBJ_FILES.
# Output all the .o files in ODIR
$(ODIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $< -o $(ODIR)/$(notdir $@) \
-DSK_GL \
-Iinclude \
-I$(RIVE_RUNTIME_DIR)/include \
-I$(RIVE_RUNTIME_DIR)/renderer/library/include \
-I${RIVE_RUNTIME_DIR}/skia/dependencies/$(SKIA_DIR_NAME)/ \
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3b48676

Please sign in to comment.