Skip to content

chore: Add native library deploy workflow. #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
branches: [master]

# Cancel old PR builds when pushing new commits.
# Cancel old builds when pushing new commits.
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
Expand Down
131 changes: 131 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
name: deploy

on:
push:
branches: [master]
pull_request:
branches: [master]

# Cancel old builds when pushing new commits.
concurrency:
group: deploy-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
linux:
name: Linux
strategy:
matrix:
arch: [aarch64, x86_64]
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache built binaries
id: cache
uses: actions/cache@v4
with:
path: |
_build
_git
_install
key: ${{ github.job }}-${{ matrix.arch }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends
yasm
- name: Build binaries
run: |
if [ -d _install/host ]; then
echo "Not rebuilding dependencies"
touch _install/host/.stamp
touch _install/host/*.stamp
fi
scripts/build-host -j "$(nproc)" \
lib/src/main/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h \
lib/src/main/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h \
lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h
- name: Build host tools tarball
run: tar -zcf _install/host.tar.gz _install/host
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.job }}-${{ matrix.arch }}
path: _install/host.tar.gz
if-no-files-found: error

android:
name: Android
needs: [linux]
strategy:
matrix:
abi: [arm64-v8a, armeabi-v7a, x86_64, x86]
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: linux-x86_64
- name: Extract artifact
run: |
tar -zxf host.tar.gz
rm host.tar.gz
- name: Cache built binaries
id: cache
uses: actions/cache@v4
with:
path: |
_git
_install
key: ${{ github.job }}-${{ matrix.abi }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends
yasm
- name: Build Android JNI
run: |
if [ -d _install/*android* ]; then
echo "Not rebuilding dependencies"
touch _install/*android*/.stamp
touch _install/*android*/*.stamp
fi
scripts/build-android.sh ${{ matrix.abi }} -j "$(nproc)"

macos:
name: macOS
strategy:
matrix:
arch: [arm64, x86_64]
runs-on: ${{ matrix.arch == 'x86_64' && 'macos-13' || 'macos-14' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache built binaries
id: cache
uses: actions/cache@v4
with:
path: |
_build
_git
_install
key: ${{ github.job }}-${{ matrix.arch }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: brew install autoconf automake libtool yasm
- name: Build binaries
run: |
if [ -d _install/host ]; then
echo "Not rebuilding dependencies"
touch _install/host/.stamp
touch _install/host/*.stamp
fi
scripts/build-host -j "$(sysctl -n hw.logicalcpu)"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.job }}-${{ matrix.arch }}
path: _install/host
if-no-files-found: error
22 changes: 12 additions & 10 deletions scripts/android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ PROTOC := $(DESTDIR)/host/bin/protoc

export CC := $(TOOLCHAIN)/bin/$(TARGET)$(NDK_API)-clang
export CXX := $(TOOLCHAIN)/bin/$(TARGET)$(NDK_API)-clang++
export LDFLAGS := -llog
export PKG_CONFIG_LIBDIR:= $(PREFIX)/lib/pkgconfig
export PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig
export PATH := $(TOOLCHAIN)/bin:$(PATH)
export TOX4J_PLATFORM := $(TARGET)

protobuf_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared --with-protoc=$(PROTOC)
libsodium_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared
opus_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared
libvpx_CONFIGURE := --prefix=$(PREFIX) --sdk-path=$(NDK_HOME) --libc=$(SYSROOT) --target=$(VPX_ARCH) --disable-examples --disable-unit-tests --enable-pic
toxcore_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -DANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c -DENABLE_STATIC=ON -DENABLE_SHARED=OFF
tox4j_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -DANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c
protobuf_CONFIGURE := -D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -D WITH_PROTOC=$(PROTOC) -D CMAKE_EXE_LINKER_FLAGS=-llog
libsodium_CONFIGURE := --host=$(TARGET) --with-sysroot=$(SYSROOT)
opus_CONFIGURE := --host=$(TARGET) --with-sysroot=$(SYSROOT)
libvpx_CONFIGURE := --libc=$(SYSROOT) --target=$(VPX_ARCH)
toxcore_CONFIGURE := -D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -D ANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c
tox4j_CONFIGURE := -D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -D ANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c -D protobuf_DIR=$(PREFIX)/lib/cmake/protobuf -D absl_DIR=$(PREFIX)/lib/cmake/absl -D utf8_range_DIR=$(PREFIX)/lib/cmake/utf8_range

libvpx_PATCH := \
sed -i -e 's!^AS=as!AS=$(CC) -c!' $(BUILDDIR)/libvpx/*.mk && \
sed -i -e 's!^STRIP=strip!STRIP=$(TOOLCHAIN)/bin/llvm-strip!' $(BUILDDIR)/libvpx/*.mk

build: $(PREFIX)/tox4j.stamp

Expand All @@ -31,10 +34,9 @@ $(NDK_HOME):
@$(PRE_RULE)
@mkdir -p $(@D)
# This is put into the root dir, not into $(SRCDIR), because it's huge and
# clutters the Travis CI cache.
# clutters the CI cache.
test -f $(NDK_PACKAGE) || curl -s $(NDK_URL) -o $(NDK_PACKAGE)
7z x $(NDK_PACKAGE) $(foreach x,$(NDK_FILES),'-ir!$(NDK_DIR)/$x')
test -d $@ && find $@ -exec chmod +w {} \; && rm -rf $@
$(SEVEN_ZIP) x -snld $(NDK_PACKAGE)
mv $(NDK_DIR) $@
mkdir -p $(TOOLCHAIN)/bin
ln -f $(CC) $(TOOLCHAIN)/bin/$(TARGET)-gcc
Expand Down
8 changes: 0 additions & 8 deletions scripts/build-aarch64-linux-android
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ TARGET := aarch64-linux-android

include scripts/common.mk

NDK_FILES := $(NDK_COMMON_FILES) \
platforms/android-21/arch-arm64 \
toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android \
toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-* \
toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-* \
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21

NDK_API := 21
NDK_ARCH := arm64
VPX_ARCH := arm64-android-gcc

include scripts/android.mk
Expand Down
31 changes: 31 additions & 0 deletions scripts/build-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -eux -o pipefail

GIT_ROOT=$(git rev-parse --show-toplevel)
cd "$GIT_ROOT"

ABI=$1
shift

case $ABI in
arm64-v8a)
SCRIPT_ARCH=aarch64-linux-android
;;
armeabi-v7a)
SCRIPT_ARCH=armv7a-linux-androideabi
;;
x86)
SCRIPT_ARCH=i686-linux-android
;;
x86_64)
SCRIPT_ARCH=x86_64-linux-android
;;
*)
echo "Unknown ABI: $ABI"
exit 1
;;
esac

"scripts/build-$SCRIPT_ARCH" libvpx "$@"
"scripts/build-$SCRIPT_ARCH" "$@"
17 changes: 0 additions & 17 deletions scripts/build-arm-linux-androideabi

This file was deleted.

11 changes: 11 additions & 0 deletions scripts/build-armv7a-linux-androideabi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/make -f

TARGET := armv7a-linux-androideabi

include scripts/common.mk

NDK_API := 21
VPX_ARCH := armv7-android-gcc

include scripts/android.mk
include scripts/dependencies.mk
50 changes: 24 additions & 26 deletions scripts/build-host
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,40 @@ TOOLCHAIN := $(DESTDIR)/$(TARGET)
TOOLCHAIN_FILE := $(TOOLCHAIN)/.stamp
PREFIX := $(TOOLCHAIN)

export CC := $(shell which clang || which gcc)
export CXX := $(shell which clang++ || which g++)
export PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig
export TOX4J_PLATFORM := $(shell perl -e 'print $$^O')-$(shell uname -m)
export LD_LIBRARY_PATH := $(PREFIX)/lib
export CC := $(shell which clang || which gcc)
export CXX := $(shell which clang++ || which g++)
export PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig
export TOX4J_PLATFORM := $(shell perl -e 'print $$^O')-$(shell uname -m)
export LD_LIBRARY_PATH := $(PREFIX)/lib
export DYLD_LIBRARY_PATH := $(PREFIX)/lib

build: $(PREFIX)/tox4j.stamp
./gradlew build

test: build
$(MAKE) -C _build/$(TARGET)/tox4j test
$(MAKE) -f scripts/build-host regenerate
git diff --exit-code
sbt -Djava.library.path=$(PREFIX)/lib "coverage" "test" "coverageReport"
lib/src/main/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h: build
find . -name "ToxAvJni.class"
# javah -cp $(PWD)/lib/build/classes/java/main im.tox.tox4j.impl.jni.ToxAvJni
# mv $(@F) $@

cpp/src/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h: build
javah -cp target/scala-2.11/classes im.tox.tox4j.impl.jni.ToxAvJni
mv $(@F) $@
lib/src/main/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h: build
find . -name "ToxCoreJni.class"
# javah -cp $(PWD)/lib/build/classes/java/main im.tox.tox4j.impl.jni.ToxCoreJni
# mv $(@F) $@

cpp/src/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h: build
javah -cp target/scala-2.11/classes im.tox.tox4j.impl.jni.ToxCoreJni
mv $(@F) $@

cpp/src/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h: build
javah -cp target/scala-2.11/classes im.tox.tox4j.impl.jni.ToxCryptoJni
mv $(@F) $@
lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h: build
find . -name "ToxCryptoJni.class"
# javah -cp $(PWD)/lib/build/classes/java/main im.tox.tox4j.impl.jni.ToxCryptoJni
# mv $(@F) $@

%.run: ; $*
regenerate: $(foreach i,$(wildcard bin/Jni*),$i.run) $(wildcard cpp/src/*/generated/*.h)

protobuf_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_DISABLE_RTTI=ON -Dprotobuf_BUILD_SHARED_LIBS=OFF
libsodium_CONFIGURE := --prefix=$(PREFIX) --disable-shared
opus_CONFIGURE := --prefix=$(PREFIX) --disable-shared
libvpx_CONFIGURE := --prefix=$(PREFIX) --disable-examples --disable-unit-tests --enable-pic
toxcore_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -DENABLE_STATIC=ON -DENABLE_SHARED=OFF
tox4j_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX)
protobuf_CONFIGURE :=
libsodium_CONFIGURE :=
opus_CONFIGURE :=
libvpx_CONFIGURE :=
toxcore_CONFIGURE :=
tox4j_CONFIGURE :=

$(TOOLCHAIN):
mkdir -p $@
Expand Down
8 changes: 1 addition & 7 deletions scripts/build-i686-linux-android
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ TARGET := i686-linux-android

include scripts/common.mk

NDK_FILES := $(NDK_COMMON_FILES) \
platforms/android-9 \
sources/cxx-stl/gnu-libstdc++/4.9/libs/x86 \
toolchains/x86-4.9

NDK_API := 9
NDK_ARCH := x86
NDK_API := 21
VPX_ARCH := x86-android-gcc

include scripts/android.mk
Expand Down
6 changes: 0 additions & 6 deletions scripts/build-x86_64-linux-android
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ TARGET := x86_64-linux-android

include scripts/common.mk

NDK_FILES := $(NDK_COMMON_FILES) \
platforms/android-21 \
sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64 \
toolchains/x86_64-4.9

NDK_API := 21
NDK_ARCH := x86_64
VPX_ARCH := x86_64-android-gcc

include scripts/android.mk
Expand Down
20 changes: 9 additions & 11 deletions scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ DESTDIR := $(CURDIR)/_install
BUILDDIR := $(CURDIR)/_build/$(TARGET)

export CFLAGS := -O3 -pipe
export CXXFLAGS := -O3 -pipe
export CXXFLAGS := -O3 -pipe -std=c++20
export LDFLAGS :=

export PATH := $(DESTDIR)/host/bin:$(PATH)

# Android NDK
NDK_DIR := android-ndk-r21
NDK_PACKAGE := $(NDK_DIR)-$(shell perl -e 'print $$^O')-x86_64.zip
NDK_DIR := android-ndk-r27c
ifeq ($(shell uname -s),Darwin)
NDK_PACKAGE := $(NDK_DIR)-darwin.dmg
SEVEN_ZIP := 7zz
else
NDK_PACKAGE := $(NDK_DIR)-linux.zip
SEVEN_ZIP := 7z
endif
NDK_URL := http://dl.google.com/android/repository/$(NDK_PACKAGE)

NDK_COMMON_FILES := \
sources/android/cpufeatures \
toolchains/llvm/prebuilt/linux-x86_64/bin/clang \
toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ \
toolchains/llvm/prebuilt/linux-x86_64/lib/lib64 \
toolchains/llvm/prebuilt/linux-x86_64/lib64 \
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
Loading
Loading