Skip to content

Commit cecbb0d

Browse files
Build native library for Snappy 1.1.9 (#380)
* Fix dependency * Add checkout step * Remove tty option * Fix compiler prefixes * Fix arm compiler names * Reorder for debug * Fix * Update dockcross-arm-android * Remove system include * Fix strip path * Update native libraries --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent a794389 commit cecbb0d

File tree

15 files changed

+114
-34
lines changed

15 files changed

+114
-34
lines changed

.github/workflows/build-native.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jobs:
88
name: Build native libraries
99
runs-on: ubuntu-latest
1010
steps:
11+
- uses: actions/checkout@v3
1112
- name: Build native libraries
1213
run: make clean-native native-all
1314
env:
@@ -20,7 +21,7 @@ jobs:
2021
push:
2122
name: Push new native libraries to branch
2223
runs-on: ubuntu-latest
23-
needs: [check, build]
24+
needs: [build]
2425
steps:
2526
- uses: actions/checkout@v3
2627
- name: Download native libraries

Makefile

+9-9
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ native: jni-header snappy-header $(NATIVE_DLL)
146146
native-nocmake: jni-header $(NATIVE_DLL)
147147
snappy: native $(TARGET)/$(snappy-jar-version).jar
148148

149-
native-all: native mac64 win32 win64 native-arm linux32 linux64 linux-ppc64le
149+
native-all: native native-arm mac64 win32 win64 linux32 linux64 linux-ppc64le
150150

151151
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
152152
@mkdir -p $(@D)
@@ -175,25 +175,25 @@ mac32: jni-header
175175
$(MAKE) native OS_NAME=Mac OS_ARCH=x86
176176

177177
mac64: jni-header
178-
docker run -it $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86_64
178+
docker run -i $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86_64
179179

180180
linux32: jni-header
181-
docker run $(DOCKER_RUN_OPTS) -ti -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86'
181+
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86'
182182

183183
linux64: jni-header
184-
docker run $(DOCKER_RUN_OPTS) -ti -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86_64'
184+
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86_64'
185185

186186
freebsd64:
187187
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64
188188

189189
# For ARM
190-
native-arm: linux-arm linux-armv6 linux-armv7 linux-android-arm linux-arm64
190+
native-arm: linux-arm64 linux-android-arm linux-arm linux-armv6 linux-armv7
191191

192192
linux-arm: jni-header
193193
./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'
194194

195195
linux-armv6: jni-header
196-
./docker/dockcross-armv6 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=arm-linux-gnueabihf- OS_NAME=Linux OS_ARCH=armv6'
196+
./docker/dockcross-armv6 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=armv6-unknown-linux-gnueabihf- OS_NAME=Linux OS_ARCH=armv6'
197197

198198
linux-armv7: jni-header
199199
./docker/dockcross-armv7 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/armv7-unknown-linux-gnueabi/bin/armv7-unknown-linux-gnueabi- OS_NAME=Linux OS_ARCH=armv7'
@@ -202,13 +202,13 @@ linux-android-arm: jni-header
202202
./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'
203203

204204
linux-ppc64le: jni-header
205-
./docker/dockcross-ppc64le -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64le-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64le'
205+
./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'
206206

207207
linux-ppc64: jni-header
208-
./docker/dockcross-ppc64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64'
208+
./docker/dockcross-ppc64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64'
209209

210210
linux-arm64: jni-header
211-
./docker/dockcross-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=/usr/xcc/aarch64-unknown-linux-gnueabi/bin/aarch64-unknown-linux-gnueabi- OS_NAME=Linux OS_ARCH=aarch64'
211+
./docker/dockcross-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=aarch64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=aarch64'
212212

213213
javadoc:
214214
$(SBT) doc

Makefile.common

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ Linux-armv7_LIBNAME := libsnappyjava.so
228228
Linux-armv7_SNAPPY_FLAGS:=
229229

230230
Linux-android-arm_CXX := $(CROSS_PREFIX)g++
231-
Linux-android-arm_STRIP := $(CROSS_PREFIX)strip
232-
Linux-android-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -isystem /usr/arm-linux-androideabi/include/c++/4.9.x -std=c++11
231+
Linux-android-arm_STRIP := $(CROSS_ROOT)/bin/llvm-strip
232+
Linux-android-arm_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -std=c++11
233233
Linux-android-arm_LINKFLAGS := -shared -static-libgcc
234234
Linux-android-arm_LIBNAME := libsnappyjava.so
235235
Linux-android-arm_SNAPPY_FLAGS:=

docker/dockcross-android-arm

+101-22
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
DEFAULT_DOCKCROSS_IMAGE=dockcross/android-arm
3+
DEFAULT_DOCKCROSS_IMAGE=dockcross/android-arm:20230116-670f7f7
44

55
#------------------------------------------------------------------------------
66
# Helpers
77
#
88
err() {
9-
echo -e >&2 ERROR: $@\\n
9+
echo -e >&2 "ERROR: $*\n"
1010
}
1111

1212
die() {
13-
err $@
13+
err "$*"
1414
exit 1
1515
}
1616

@@ -22,28 +22,39 @@ has() {
2222
type -t $kind:$name | grep -q function
2323
}
2424

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+
2536
#------------------------------------------------------------------------------
2637
# Command handlers
2738
#
2839
command:update-image() {
29-
docker pull $FINAL_IMAGE
40+
$OCI_EXE pull $FINAL_IMAGE
3041
}
3142

3243
help:update-image() {
33-
echo Pull the latest $FINAL_IMAGE .
44+
echo "Pull the latest $FINAL_IMAGE ."
3445
}
3546

3647
command:update-script() {
37-
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
38-
echo $0 is up to date
48+
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
49+
echo "$0 is up to date"
3950
else
40-
echo -n Updating $0 '... '
41-
docker run $FINAL_IMAGE > $0 && echo ok
51+
echo -n "Updating $0 ... "
52+
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
4253
fi
4354
}
4455

45-
help:update-image() {
46-
echo Update $0 from $FINAL_IMAGE .
56+
help:update-script() {
57+
echo "Update $0 from $FINAL_IMAGE ."
4758
}
4859

4960
command:update() {
@@ -52,7 +63,7 @@ command:update() {
5263
}
5364

5465
help:update() {
55-
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
66+
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
5667
}
5768

5869
command:help() {
@@ -98,6 +109,7 @@ while [[ $# != 0 ]]; do
98109
case $1 in
99110

100111
--)
112+
shift
101113
break
102114
;;
103115

@@ -171,29 +183,96 @@ fi
171183
# Set the docker run extra args (if any)
172184
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
173185

174-
# If we are not running via boot2docker
175-
if [ -z $DOCKER_HOST ]; then
176-
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
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 ;
177236
fi
178237

179238
#------------------------------------------------------------------------------
180239
# Now, finally, run the command in a container
181240
#
182-
docker run --rm \
183-
-v $PWD:/work \
184-
$USER_IDS \
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+
--platform linux/amd64 \
246+
-v "$HOST_PWD":/work \
247+
$HOST_VOLUMES \
248+
"${USER_IDS[@]}" \
185249
$FINAL_ARGS \
186250
$FINAL_IMAGE "$@"
251+
run_exit_code=$?
252+
253+
# Attempt to delete container
254+
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
255+
rm_exit_code=$?
256+
if [[ $rm_exit_code != 0 ]]; then
257+
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
258+
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
259+
else
260+
echo "$rm_output"
261+
exit $rm_exit_code
262+
fi
263+
fi
264+
265+
exit $run_exit_code
187266

188267
################################################################################
189268
#
190269
# This image is not intended to be run manually.
191270
#
192271
# To create a dockcross helper script for the
193-
# dockcross/linux-armv7 image, run:
272+
# dockcross/android-arm:20230116-670f7f7 image, run:
194273
#
195-
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
196-
# chmod +x dockcross-linux-armv7
274+
# docker run --rm dockcross/android-arm:20230116-670f7f7 > dockcross-android-arm-20230116-670f7f7
275+
# chmod +x dockcross-android-arm-20230116-670f7f7
197276
#
198277
# You may then wish to move the dockcross script to your PATH.
199278
#
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)