Skip to content

Commit

Permalink
Clean builds properly
Browse files Browse the repository at this point in the history
- Restore the clean task calling our script
- Renamed our script to `clean_all.sh`
- Refactor the script to clean up all our dependencies properly
- Clean step in `build.rive.for.sh` is a nicer now and doesn't fail if skia has been downloaded rather than cloned

Diffs=
b553c8916 Clean builds properly (#5685)

Co-authored-by: Umberto Sonnino <[email protected]>
  • Loading branch information
umberto-sonnino and umberto-sonnino committed Jul 31, 2023
1 parent c0a2cee commit 335a161
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7add054b0f4a87922eb60719b654446e962749a3
b553c8916c51b0816d04a4586657d9580e4208ad
15 changes: 8 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,23 @@ changes are introduced, we need to build new `.so` files for different architect

The Android NDK builds `.so` files
for [different architectures](https://developer.android.com/ndk/guides/abis). <br />
The current NDK version we're using is stored in [.ndk_version](./cpp/.ndk_version). Rive is
The current NDK version we're using is stored in [.ndk_version](./kotlin/src/main/cpp/.ndk_version). Rive is
constantly making use of the latest clang features, so please ensure your NDK is up to
date. ([How to install a specific NDK version](https://developer.android.com/studio/projects/install-ndk#specific-version)) <br />
We also need to rebuild new `.so` files (located in `/kotlin/src/main/jniLibs/`) when pulling in
latest changes from `rive-cpp`:
Make sure you're rebuilding the native libraries when pulling in the latest changes from `rive-cpp`:

```bash
cd cpp/
cd kotlin/src/main/cpp/

# Add NDK_PATH variable to your .zshenv
NDK_VERSION=$(tr <.ndk_version -d " \t\n\r")
echo 'export NDK_PATH=~/Library/Android/sdk/ndk/${NDK_VERSION}' >> ~/.zshenv
source ~/.zshenv

# Builds .so files for each architecture
./build.all.sh
# After the script above completes successfully, you may see 4 new .so files. Make sure these are committed as a code change
# Back to the top of the repo
cd -
# Make sure everything still builds
./gradlew assembleDebug
# After the script above completes successfully, commit your changes
git add .
```
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ allprojects {
}
}

task cleanDeps(type: Exec) {
workingDir './cpp'
commandLine './build.clean.sh'
tasks.register('cleanDeps', Exec) {
workingDir './kotlin/src/main/cpp'
commandLine './clean_all.sh'
}

task clean(type: Delete) {
// dependsOn(cleanDeps)
tasks.register('clean', Delete) {
dependsOn(cleanDeps)
delete rootProject.buildDir
}

Expand Down
8 changes: 5 additions & 3 deletions kotlin/src/main/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ $(ODIR)/%.o: $(SRC_DIR)/%.cpp

clean:
rm -rf $(ODIR)
rm -f $(BUILD_DIR)/libc++_static.a
rm -f $(BUILD_DIR)/libjnirivebridge.so
rm -f $(BUILD_DIR)/librive_harfbuzz.a
rm -f $(BUILD_DIR)/librive_pls_renderer.a
rm -f $(BUILD_DIR)/librive_sheenbidi.a
rm -f $(BUILD_DIR)/librive_skia_renderer.a
rm -f $(BUILD_DIR)/librive.a
rm -f $(BUILD_DIR)/libskia.a
rm -f $(BUILD_DIR)/librive_skia_renderer.a
rm -f $(BUILD_DIR)/librive_pls_renderer.a
rm -f $(BUILD_DIR)/libc++_static.a

7 changes: 0 additions & 7 deletions kotlin/src/main/cpp/build.all.sh

This file was deleted.

8 changes: 0 additions & 8 deletions kotlin/src/main/cpp/build.clean.sh

This file was deleted.

44 changes: 27 additions & 17 deletions kotlin/src/main/cpp/build.rive.for.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

set -ex

ARCH_X86=x86
Expand Down Expand Up @@ -123,25 +122,32 @@ export MAKE_SKIA_FILE="make_skia_android.sh"
API=21
SKIA_ARCH=

buildFor() {
if ${NEEDS_CLEAN}; then
echo "Cleaning everything!"
# Skia
pushd "$RIVE_RUNTIME_DIR"/skia/dependencies/"$SKIA_DIR_NAME"
# Cleans the build for the specified architecture
cleanFor() {
echo "Cleaning everything!"
# Skia
pushd "$RIVE_RUNTIME_DIR"/skia/dependencies/"$SKIA_DIR_NAME"
if [ -d ./bin ]; then
# Skia clone: let's clean the build
bin/gn clean ./out/"$CONFIG"/"$SKIA_ARCH"
popd
# PLS
pushd "$RIVE_RUNTIME_DIR"/../pls/out
make config=$CONFIG clean
popd
# rive_skia_renderer
pushd "$RIVE_RUNTIME_DIR"/skia/renderer
./build.sh -p android."$SKIA_ARCH" clean
popd
# Android lib
make clean
else
# Skia download.
rm archive_contents
fi
popd
# PLS
pushd "$RIVE_RUNTIME_DIR"/../pls/out
make config=$CONFIG clean
popd
# rive_skia_renderer
pushd "$RIVE_RUNTIME_DIR"/skia/renderer
./build.sh -p android."$SKIA_ARCH" clean
popd
# Android lib
make clean
}

buildFor() {
# Build skia
pushd "$RIVE_RUNTIME_DIR"/skia/dependencies
./make_skia_android.sh "$SKIA_ARCH" "$CONFIG"
Expand Down Expand Up @@ -226,4 +232,8 @@ else
usage
fi

if ${NEEDS_CLEAN}; then
cleanFor
exit 1
fi
buildFor
53 changes: 53 additions & 0 deletions kotlin/src/main/cpp/clean_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
set -ex

SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
if [ "$PWD" != "$SCRIPT_HOME" ]; then
echo "Error: This script must be called from its own directory: $SCRIPT_HOME" >&2
exit 1
fi

RUNTIME_ANDROID_HOME=$PWD/../../../..

if [ -z "${RIVE_RUNTIME_DIR}" ]; then
echo "RIVE_RUNTIME_DIR is not set"
if [ -d "${RUNTIME_ANDROID_HOME}/submodules/rive-cpp" ]; then
export RIVE_RUNTIME_DIR="$RUNTIME_ANDROID_HOME/submodules/rive-cpp"
else
export RIVE_RUNTIME_DIR="$RUNTIME_ANDROID_HOME/../runtime"
fi
else
echo "RIVE_RUNTIME_DIR already set: $RIVE_RUNTIME_DIR"
fi

# Android Studio build things.
rm -rf "$RUNTIME_ANDROID_HOME"/kotlin/build/
rm -rf "$RUNTIME_ANDROID_HOME"/kotlin/.cxx/
rm -rf "$RUNTIME_ANDROID_HOME"/kotlin/src/main/cpp/build

# librive
rm -rf ./build
pushd "$RIVE_RUNTIME_DIR"
./build.sh clean
rm -rf ./build/android
popd

# Rive Renderer
pushd "$RIVE_RUNTIME_DIR"/skia/renderer/
./build.sh clean
rm -rf ./build/android
popd

# PLS
pushd "$RIVE_RUNTIME_DIR"/../pls/out
make clean
rm -rf ./android
rm -rf ./dependencies
rm -rf ./obj
popd

# Skia
pushd "$RIVE_RUNTIME_DIR"/skia/dependencies/
rm -rf ./skia/out
rm -rf ./skia_debug/out
popd

0 comments on commit 335a161

Please sign in to comment.