Skip to content

Commit fd50402

Browse files
Feature: Android arm64 support (#442)
* Feature: Support Linux android-arm64(aarch64) * Add dockcross script * Add native lib * Add --no-cache for CI * Revert "Add --no-cache for CI" This reverts commit 0f2f05b. * Add docker clean process * Update native libraries --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ad2e2d7 commit fd50402

File tree

6 files changed

+302
-3
lines changed

6 files changed

+302
-3
lines changed

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,17 @@ native: jni-header snappy-header $(NATIVE_DLL)
149149
native-nocmake: jni-header $(NATIVE_DLL)
150150
snappy: native $(TARGET)/$(snappy-jar-version).jar
151151

152-
native-all: native native-arm mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x
152+
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x
153+
154+
ifdef CI
155+
# Clean docker images within CI to avoid no space left error
156+
DOCKER_POST_PROCESS:=docker system prune --all --force --volumes
157+
else
158+
DOCKER_POST_PROCESS:=
159+
endif
160+
161+
clean-docker:
162+
$(DOCKER_POST_PROCESS)
153163

154164
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
155165
@mkdir -p $(@D)
@@ -167,6 +177,7 @@ test: $(NATIVE_DLL)
167177

168178
DOCKER_RUN_OPTS:=--rm
169179

180+
170181
win32: jni-header
171182
./docker/dockcross-windows-x86 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native snappy-header native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86 SNAPPY_CMAKE_OPTS="-DHAVE_SYS_UIO_H=0"'
172183

@@ -190,7 +201,7 @@ freebsd64:
190201
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64
191202

192203
# For ARM
193-
native-arm: linux-arm64 linux-android-arm linux-arm linux-armv6 linux-armv7
204+
native-arm: linux-arm64 linux-android-arm linux-android-aarch64 linux-arm linux-armv6 linux-armv7
194205

195206
linux-arm: jni-header
196207
./docker/dockcross-armv5 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/armv5-unknown-linux-gnueabi/bin//armv5-unknown-linux-gnueabi- OS_NAME=Linux OS_ARCH=arm'
@@ -204,6 +215,9 @@ linux-armv7: jni-header
204215
linux-android-arm: jni-header
205216
./docker/dockcross-android-arm -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/arm-linux-androideabi/bin/arm-linux-androideabi- OS_NAME=Linux OS_ARCH=android-arm'
206217

218+
linux-android-aarch64: jni-header
219+
./docker/dockcross-android-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=android-aarch64'
220+
207221
linux-ppc64le: jni-header
208222
./docker/dockcross-ppc64le -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64le-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64le'
209223

Makefile.common

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ endif
5050

5151
# os=Default is meant to be generic unix/linux
5252

53-
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-aarch64 Linux-ppc Linux-ppc64 Linux-ppc64le Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 Mac-aarch64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64 Linux-riscv Linux-riscv64
53+
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-android-aarch64 Linux-aarch64 Linux-ppc Linux-ppc64 Linux-ppc64le Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 Mac-aarch64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64 Linux-riscv Linux-riscv64
5454
os_arch := $(OS_NAME)-$(OS_ARCH)
5555
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
5656

@@ -234,6 +234,13 @@ Linux-android-arm_LINKFLAGS := -shared -static-libgcc
234234
Linux-android-arm_LIBNAME := libsnappyjava.so
235235
Linux-android-arm_SNAPPY_FLAGS:=
236236

237+
Linux-android-aarch64_CXX := ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-g++
238+
Linux-android-aarch64_STRIP := ${CROSS_ROOT}/bin/llvm-strip
239+
Linux-android-aarch64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
240+
Linux-android-aarch64_LINKFLAGS := -shared -static-libgcc
241+
Linux-android-aarch64_LIBNAME := libsnappyjava.so
242+
Linux-android-aarch64_SNAPPY_FLAGS:=
243+
237244
Linux-aarch64_CXX := $(CROSS_PREFIX)g++
238245
Linux-aarch64_STRIP := $(CROSS_PREFIX)strip
239246
Linux-aarch64_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11

docker/dockcross-android-arm64

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
#!/usr/bin/env bash
2+
3+
DEFAULT_DOCKCROSS_IMAGE=dockcross/android-arm64:20230421-a0eaff4
4+
5+
#------------------------------------------------------------------------------
6+
# Helpers
7+
#
8+
err() {
9+
echo -e >&2 "ERROR: $*\n"
10+
}
11+
12+
die() {
13+
err "$*"
14+
exit 1
15+
}
16+
17+
has() {
18+
# eg. has command update
19+
local kind=$1
20+
local name=$2
21+
22+
type -t $kind:$name | grep -q function
23+
}
24+
25+
# If OCI_EXE is not already set, search for a container executor (OCI stands for "Open Container Initiative")
26+
if [ -z "$OCI_EXE" ]; then
27+
if which podman >/dev/null 2>/dev/null; then
28+
OCI_EXE=podman
29+
elif which docker >/dev/null 2>/dev/null; then
30+
OCI_EXE=docker
31+
else
32+
die "Cannot find a container executor. Search for docker and podman."
33+
fi
34+
fi
35+
36+
#------------------------------------------------------------------------------
37+
# Command handlers
38+
#
39+
command:update-image() {
40+
$OCI_EXE pull $FINAL_IMAGE
41+
}
42+
43+
help:update-image() {
44+
echo "Pull the latest $FINAL_IMAGE ."
45+
}
46+
47+
command:update-script() {
48+
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
49+
echo "$0 is up to date"
50+
else
51+
echo -n "Updating $0 ... "
52+
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
53+
fi
54+
}
55+
56+
help:update-script() {
57+
echo "Update $0 from $FINAL_IMAGE ."
58+
}
59+
60+
command:update() {
61+
command:update-image
62+
command:update-script
63+
}
64+
65+
help:update() {
66+
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
67+
}
68+
69+
command:help() {
70+
if [[ $# != 0 ]]; then
71+
if ! has command $1; then
72+
err \"$1\" is not an dockcross command
73+
command:help
74+
elif ! has help $1; then
75+
err No help found for \"$1\"
76+
else
77+
help:$1
78+
fi
79+
else
80+
cat >&2 <<ENDHELP
81+
Usage: dockcross [options] [--] command [args]
82+
83+
By default, run the given *command* in an dockcross Docker container.
84+
85+
The *options* can be one of:
86+
87+
--args|-a Extra args to the *docker run* command
88+
--image|-i Docker cross-compiler image to use
89+
--config|-c Bash script to source before running this script
90+
91+
92+
Additionally, there are special update commands:
93+
94+
update-image
95+
update-script
96+
update
97+
98+
For update command help use: $0 help <command>
99+
ENDHELP
100+
exit 1
101+
fi
102+
}
103+
104+
#------------------------------------------------------------------------------
105+
# Option processing
106+
#
107+
special_update_command=''
108+
while [[ $# != 0 ]]; do
109+
case $1 in
110+
111+
--)
112+
shift
113+
break
114+
;;
115+
116+
--args|-a)
117+
ARG_ARGS="$2"
118+
shift 2
119+
;;
120+
121+
--config|-c)
122+
ARG_CONFIG="$2"
123+
shift 2
124+
;;
125+
126+
--image|-i)
127+
ARG_IMAGE="$2"
128+
shift 2
129+
;;
130+
update|update-image|update-script)
131+
special_update_command=$1
132+
break
133+
;;
134+
-*)
135+
err Unknown option \"$1\"
136+
command:help
137+
exit
138+
;;
139+
140+
*)
141+
break
142+
;;
143+
144+
esac
145+
done
146+
147+
# The precedence for options is:
148+
# 1. command-line arguments
149+
# 2. environment variables
150+
# 3. defaults
151+
152+
# Source the config file if it exists
153+
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
154+
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
155+
156+
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
157+
158+
# Set the docker image
159+
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
160+
161+
# Handle special update command
162+
if [ "$special_update_command" != "" ]; then
163+
case $special_update_command in
164+
165+
update)
166+
command:update
167+
exit $?
168+
;;
169+
170+
update-image)
171+
command:update-image
172+
exit $?
173+
;;
174+
175+
update-script)
176+
command:update-script
177+
exit $?
178+
;;
179+
180+
esac
181+
fi
182+
183+
# Set the docker run extra args (if any)
184+
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
185+
186+
# Bash on Ubuntu on Windows
187+
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
188+
# MSYS, Git Bash, etc.
189+
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
190+
# CYGWIN
191+
CYGWIN=$([ -e /proc/version ] && grep -l CYGWIN /proc/version || echo "")
192+
193+
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" -a "$OCI_EXE" != "podman" ]; then
194+
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
195+
fi
196+
197+
# Change the PWD when working in Docker on Windows
198+
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
199+
WSL_ROOT="/mnt/"
200+
CFG_FILE=/etc/wsl.conf
201+
if [ -f "$CFG_FILE" ]; then
202+
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
203+
eval "$CFG_CONTENT"
204+
if [ -n "$root" ]; then
205+
WSL_ROOT=$root
206+
fi
207+
fi
208+
HOST_PWD=`pwd -P`
209+
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
210+
elif [ -n "$MSYS" ]; then
211+
HOST_PWD=$PWD
212+
HOST_PWD=${HOST_PWD/\//}
213+
HOST_PWD=${HOST_PWD/\//:\/}
214+
elif [ -n "$CYGWIN" ]; then
215+
for f in pwd readlink cygpath ; do
216+
test -n "$(type "${f}" )" || { echo >&2 "Missing functionality (${f}) (in cygwin)." ; exit 1 ; } ;
217+
done ;
218+
HOST_PWD="$( cygpath -w "$( readlink -f "$( pwd ;)" ; )" ; )" ;
219+
else
220+
HOST_PWD=$PWD
221+
[ -L $HOST_PWD ] && HOST_PWD=$(readlink $HOST_PWD)
222+
fi
223+
224+
# Mount Additional Volumes
225+
if [ -z "$SSH_DIR" ]; then
226+
SSH_DIR="$HOME/.ssh"
227+
fi
228+
229+
HOST_VOLUMES=
230+
if [ -e "$SSH_DIR" -a -z "$MSYS" ]; then
231+
if test -n "${CYGWIN}" ; then
232+
HOST_VOLUMES+="-v $(cygpath -w ${SSH_DIR} ; ):/home/$(id -un)/.ssh" ;
233+
else
234+
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" ;
235+
fi ;
236+
fi
237+
238+
#------------------------------------------------------------------------------
239+
# Now, finally, run the command in a container
240+
#
241+
TTY_ARGS=
242+
tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti
243+
CONTAINER_NAME=dockcross_$RANDOM
244+
$OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME \
245+
-v "$HOST_PWD":/work \
246+
$HOST_VOLUMES \
247+
"${USER_IDS[@]}" \
248+
$FINAL_ARGS \
249+
$FINAL_IMAGE "$@"
250+
run_exit_code=$?
251+
252+
# Attempt to delete container
253+
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
254+
rm_exit_code=$?
255+
if [[ $rm_exit_code != 0 ]]; then
256+
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
257+
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
258+
else
259+
echo "$rm_output"
260+
exit $rm_exit_code
261+
fi
262+
fi
263+
264+
exit $run_exit_code
265+
266+
################################################################################
267+
#
268+
# This image is not intended to be run manually.
269+
#
270+
# To create a dockcross helper script for the
271+
# dockcross/android-arm64:20230421-a0eaff4 image, run:
272+
#
273+
# docker run --rm dockcross/android-arm64:20230421-a0eaff4 > dockcross-android-arm64-20230421-a0eaff4
274+
# chmod +x dockcross-android-arm64-20230421-a0eaff4
275+
#
276+
# You may then wish to move the dockcross script to your PATH.
277+
#
278+
################################################################################
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)