Skip to content

Commit 33efe92

Browse files
committed
chore: Add native library deploy workflow.
1 parent 2ae6d2f commit 33efe92

13 files changed

+260
-404
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
branches: [master]
77

8-
# Cancel old PR builds when pushing new commits.
8+
# Cancel old builds when pushing new commits.
99
concurrency:
1010
group: build-${{ github.event.pull_request.number || github.ref }}
1111
cancel-in-progress: true

.github/workflows/deploy.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
name: deploy
3+
4+
on:
5+
push:
6+
branches: [master]
7+
pull_request:
8+
branches: [master]
9+
10+
# Cancel old builds when pushing new commits.
11+
concurrency:
12+
group: deploy-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
linux:
17+
name: Linux
18+
strategy:
19+
matrix:
20+
arch: [aarch64, x86_64]
21+
runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
- name: Cache built binaries
26+
id: cache
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
_build
31+
_git
32+
_install
33+
key: ${{ github.job }}-${{ matrix.arch }}
34+
- name: Install dependencies
35+
if: steps.cache.outputs.cache-hit != 'true'
36+
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends
37+
yasm
38+
- name: Build binaries
39+
run: |
40+
if [ -d _install/host ]; then
41+
echo "Not rebuilding dependencies"
42+
touch _install/host/.stamp
43+
touch _install/host/*.stamp
44+
fi
45+
scripts/build-host -j "$(nproc)" \
46+
lib/src/main/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h \
47+
lib/src/main/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h \
48+
lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h
49+
- name: Build host tools tarball
50+
run: tar -zcf _install/host.tar.gz _install/host
51+
- name: Upload artifact
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: ${{ github.job }}-${{ matrix.arch }}
55+
path: _install/host.tar.gz
56+
if-no-files-found: error
57+
58+
android:
59+
name: Android
60+
needs: [linux]
61+
strategy:
62+
matrix:
63+
abi: [arm64-v8a, armeabi-v7a, x86_64, x86]
64+
runs-on: ubuntu-24.04
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
- name: Download artifact
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: linux-x86_64
72+
- name: Extract artifact
73+
run: |
74+
tar -zxf host.tar.gz
75+
rm host.tar.gz
76+
- name: Cache built binaries
77+
id: cache
78+
uses: actions/cache@v4
79+
with:
80+
path: |
81+
_git
82+
_install
83+
key: ${{ github.job }}-${{ matrix.abi }}
84+
- name: Install dependencies
85+
if: steps.cache.outputs.cache-hit != 'true'
86+
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends
87+
yasm
88+
- name: Build Android JNI
89+
run: |
90+
if [ -d _install/*android* ]; then
91+
echo "Not rebuilding dependencies"
92+
touch _install/*android*/.stamp
93+
touch _install/*android*/*.stamp
94+
fi
95+
scripts/build-android.sh ${{ matrix.abi }} -j "$(nproc)"
96+
97+
macos:
98+
name: macOS
99+
strategy:
100+
matrix:
101+
arch: [arm64, x86_64]
102+
runs-on: ${{ matrix.arch == 'x86_64' && 'macos-13' || 'macos-14' }}
103+
steps:
104+
- name: Checkout code
105+
uses: actions/checkout@v4
106+
- name: Cache built binaries
107+
id: cache
108+
uses: actions/cache@v4
109+
with:
110+
path: |
111+
_build
112+
_git
113+
_install
114+
key: ${{ github.job }}-${{ matrix.arch }}
115+
- name: Install dependencies
116+
if: steps.cache.outputs.cache-hit != 'true'
117+
run: brew install autoconf automake libtool yasm
118+
- name: Build binaries
119+
run: |
120+
if [ -d _install/host ]; then
121+
echo "Not rebuilding dependencies"
122+
touch _install/host/.stamp
123+
touch _install/host/*.stamp
124+
fi
125+
scripts/build-host -j "$(sysctl -n hw.logicalcpu)"
126+
- name: Upload artifact
127+
uses: actions/upload-artifact@v4
128+
with:
129+
name: ${{ github.job }}-${{ matrix.arch }}
130+
path: _install/host
131+
if-no-files-found: error

scripts/android.mk

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ PROTOC := $(DESTDIR)/host/bin/protoc
99

1010
export CC := $(TOOLCHAIN)/bin/$(TARGET)$(NDK_API)-clang
1111
export CXX := $(TOOLCHAIN)/bin/$(TARGET)$(NDK_API)-clang++
12-
export LDFLAGS := -llog
1312
export PKG_CONFIG_LIBDIR:= $(PREFIX)/lib/pkgconfig
1413
export PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig
1514
export PATH := $(TOOLCHAIN)/bin:$(PATH)
1615
export TOX4J_PLATFORM := $(TARGET)
1716

18-
protobuf_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared --with-protoc=$(PROTOC)
19-
libsodium_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared
20-
opus_CONFIGURE := --prefix=$(PREFIX) --host=$(TARGET) --with-sysroot=$(SYSROOT) --disable-shared
21-
libvpx_CONFIGURE := --prefix=$(PREFIX) --sdk-path=$(NDK_HOME) --libc=$(SYSROOT) --target=$(VPX_ARCH) --disable-examples --disable-unit-tests --enable-pic
22-
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
23-
tox4j_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -DANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c
17+
protobuf_CONFIGURE := -D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -D WITH_PROTOC=$(PROTOC) -D CMAKE_EXE_LINKER_FLAGS=-llog
18+
libsodium_CONFIGURE := --host=$(TARGET) --with-sysroot=$(SYSROOT)
19+
opus_CONFIGURE := --host=$(TARGET) --with-sysroot=$(SYSROOT)
20+
libvpx_CONFIGURE := --libc=$(SYSROOT) --target=$(VPX_ARCH)
21+
toxcore_CONFIGURE := -D CMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) -D ANDROID_CPU_FEATURES=$(NDK_HOME)/sources/android/cpufeatures/cpu-features.c
22+
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
23+
24+
libvpx_PATCH := \
25+
sed -i -e 's!^AS=as!AS=$(CC) -c!' $(BUILDDIR)/libvpx/*.mk && \
26+
sed -i -e 's!^STRIP=strip!STRIP=$(TOOLCHAIN)/bin/llvm-strip!' $(BUILDDIR)/libvpx/*.mk
2427

2528
build: $(PREFIX)/tox4j.stamp
2629

@@ -31,10 +34,9 @@ $(NDK_HOME):
3134
@$(PRE_RULE)
3235
@mkdir -p $(@D)
3336
# This is put into the root dir, not into $(SRCDIR), because it's huge and
34-
# clutters the Travis CI cache.
37+
# clutters the CI cache.
3538
test -f $(NDK_PACKAGE) || curl -s $(NDK_URL) -o $(NDK_PACKAGE)
36-
7z x $(NDK_PACKAGE) $(foreach x,$(NDK_FILES),'-ir!$(NDK_DIR)/$x')
37-
test -d $@ && find $@ -exec chmod +w {} \; && rm -rf $@
39+
$(SEVEN_ZIP) x -snld $(NDK_PACKAGE)
3840
mv $(NDK_DIR) $@
3941
mkdir -p $(TOOLCHAIN)/bin
4042
ln -f $(CC) $(TOOLCHAIN)/bin/$(TARGET)-gcc

scripts/build-aarch64-linux-android

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ TARGET := aarch64-linux-android
44

55
include scripts/common.mk
66

7-
NDK_FILES := $(NDK_COMMON_FILES) \
8-
platforms/android-21/arch-arm64 \
9-
toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android \
10-
toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-* \
11-
toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-* \
12-
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21
13-
147
NDK_API := 21
15-
NDK_ARCH := arm64
168
VPX_ARCH := arm64-android-gcc
179

1810
include scripts/android.mk

scripts/build-android.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux -o pipefail
4+
5+
GIT_ROOT=$(git rev-parse --show-toplevel)
6+
cd "$GIT_ROOT"
7+
8+
ABI=$1
9+
shift
10+
11+
case $ABI in
12+
arm64-v8a)
13+
SCRIPT_ARCH=aarch64-linux-android
14+
;;
15+
armeabi-v7a)
16+
SCRIPT_ARCH=armv7a-linux-androideabi
17+
;;
18+
x86)
19+
SCRIPT_ARCH=i686-linux-android
20+
;;
21+
x86_64)
22+
SCRIPT_ARCH=x86_64-linux-android
23+
;;
24+
*)
25+
echo "Unknown ABI: $ABI"
26+
exit 1
27+
;;
28+
esac
29+
30+
"scripts/build-$SCRIPT_ARCH" libvpx "$@"
31+
"scripts/build-$SCRIPT_ARCH" "$@"

scripts/build-arm-linux-androideabi

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/make -f
2+
3+
TARGET := armv7a-linux-androideabi
4+
5+
include scripts/common.mk
6+
7+
NDK_API := 21
8+
VPX_ARCH := armv7-android-gcc
9+
10+
include scripts/android.mk
11+
include scripts/dependencies.mk

scripts/build-host

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,40 @@ TOOLCHAIN := $(DESTDIR)/$(TARGET)
99
TOOLCHAIN_FILE := $(TOOLCHAIN)/.stamp
1010
PREFIX := $(TOOLCHAIN)
1111

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

1819
build: $(PREFIX)/tox4j.stamp
1920
./gradlew build
2021

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

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

31-
cpp/src/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h: build
32-
javah -cp target/scala-2.11/classes im.tox.tox4j.impl.jni.ToxCoreJni
33-
mv $(@F) $@
34-
35-
cpp/src/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h: build
36-
javah -cp target/scala-2.11/classes im.tox.tox4j.impl.jni.ToxCryptoJni
37-
mv $(@F) $@
32+
lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h: build
33+
find . -name "ToxCryptoJni.class"
34+
# javah -cp $(PWD)/lib/build/classes/java/main im.tox.tox4j.impl.jni.ToxCryptoJni
35+
# mv $(@F) $@
3836

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

42-
protobuf_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_DISABLE_RTTI=ON -Dprotobuf_BUILD_SHARED_LIBS=OFF
43-
libsodium_CONFIGURE := --prefix=$(PREFIX) --disable-shared
44-
opus_CONFIGURE := --prefix=$(PREFIX) --disable-shared
45-
libvpx_CONFIGURE := --prefix=$(PREFIX) --disable-examples --disable-unit-tests --enable-pic
46-
toxcore_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) -DENABLE_STATIC=ON -DENABLE_SHARED=OFF
47-
tox4j_CONFIGURE := -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX)
40+
protobuf_CONFIGURE :=
41+
libsodium_CONFIGURE :=
42+
opus_CONFIGURE :=
43+
libvpx_CONFIGURE :=
44+
toxcore_CONFIGURE :=
45+
tox4j_CONFIGURE :=
4846

4947
$(TOOLCHAIN):
5048
mkdir -p $@

scripts/build-i686-linux-android

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ TARGET := i686-linux-android
44

55
include scripts/common.mk
66

7-
NDK_FILES := $(NDK_COMMON_FILES) \
8-
platforms/android-9 \
9-
sources/cxx-stl/gnu-libstdc++/4.9/libs/x86 \
10-
toolchains/x86-4.9
11-
12-
NDK_API := 9
13-
NDK_ARCH := x86
7+
NDK_API := 21
148
VPX_ARCH := x86-android-gcc
159

1610
include scripts/android.mk

scripts/build-x86_64-linux-android

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ TARGET := x86_64-linux-android
44

55
include scripts/common.mk
66

7-
NDK_FILES := $(NDK_COMMON_FILES) \
8-
platforms/android-21 \
9-
sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64 \
10-
toolchains/x86_64-4.9
11-
127
NDK_API := 21
13-
NDK_ARCH := x86_64
148
VPX_ARCH := x86_64-android-gcc
159

1610
include scripts/android.mk

0 commit comments

Comments
 (0)