-
Notifications
You must be signed in to change notification settings - Fork 53
/
build-h3.sh
executable file
·149 lines (122 loc) · 4.46 KB
/
build-h3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
#
# Copyright 2018 Uber Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Arguments: [git-remote] [git-ref] [use-docker] [remove-images]
# git-remote - The git remote to pull from. An existing cloned repository
# will not be deleted if a new remote is specified.
# git-ref - Specific git ref of H3 to build.
# use-docker - "true" to perform cross compilation via Docker, "false" to
# skip that step.
# remove-images - If use-docker is true and this argument is true, Docker
# cross compilation images will be removed after each step
#
# This script downloads H3, builds H3 and the H3-Java native library, and
# cross compiles via Docker.
#
# This script expects to be run from the project's base directory (where
# pom.xml is) as part of the Maven build process.
set -ex
GIT_REMOTE=$1
GIT_REVISION=$2
USE_DOCKER=$3
REMOVE_IMAGES=$4
echo Downloading H3 from "$GIT_REMOTE"
mkdir -p target
pushd target
if [ ! -d "h3" ]; then
git clone "$GIT_REMOTE" h3
fi
pushd h3
git fetch origin --tags
echo Using revision "$GIT_REVISION"
git checkout "$GIT_REVISION"
popd # h3
#
# Now that H3 is downloaded, build H3-Java's native library for this platform.
#
mkdir -p h3-java-build
pushd h3-java-build
mkdir -p build
pushd build
cmake -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
../../h3
cmake --build . --target h3 --config Release
cmake --build . --target binding-functions --config Release
H3_BUILD_ROOT="$(pwd)"
popd # build
cmake -DUSE_NATIVE_JNI=ON \
-DBUILD_SHARED_LIBS=ON \
"-DH3_BUILD_ROOT=$H3_BUILD_ROOT" \
-DCMAKE_BUILD_TYPE=Release \
../../src/main/c/h3-java
cmake --build . --target h3-java --config Release
popd # h3-java-build
cp h3-java-build/build/binding-functions .
popd # target
# Copy the built artifact for this platform.
case "$(uname -sm)" in
"Linux x86_64") LIBRARY_DIR=linux-x64 ;;
"Linux i386") LIBRARY_DIR=linux-x86 ;;
"Linux i486") LIBRARY_DIR=linux-x86 ;;
"Linux i586") LIBRARY_DIR=linux-x86 ;;
"Linux i686") LIBRARY_DIR=linux-x86 ;;
"Linux i786") LIBRARY_DIR=linux-x86 ;;
"Linux i886") LIBRARY_DIR=linux-x86 ;;
"Darwin x86_64") LIBRARY_DIR=darwin-x64 ;;
"FreeBSD amd64") LIBRARY_DIR=freebsd-x64 ;;
# TODO: Detect others
*) LIBRARY_DIR="" ;;
esac
mkdir -p src/main/resources/$LIBRARY_DIR
cp target/h3-java-build/lib/libh3-java* src/main/resources/$LIBRARY_DIR
#
# Now that H3 is downloaded, build H3-Java's native library for other platforms.
#
if ! $USE_DOCKER; then
echo Docker disabled, skipping cross compilation.
exit 0
fi
if ! command -v docker; then
echo Docker not found, skipping cross compilation.
exit 0
fi
# linux-armv6 excluded because of build failure
for image in android-arm android-arm64 linux-arm64 linux-armv5 linux-armv7 linux-mipsel linux-mips linux-s390x \
linux-ppc64le linux-x64 linux-x86 windows-x64 windows-x86; do
# Setup for using dockcross
BUILD_ROOT=target/h3-java-build-$image
mkdir -p $BUILD_ROOT
docker pull dockcross/$image
docker run --rm dockcross/$image > $BUILD_ROOT/dockcross
chmod +x $BUILD_ROOT/dockcross
# Perform the actual build inside Docker
$BUILD_ROOT/dockcross --args "-v $JAVA_HOME:/java" src/main/c/h3-java/build-h3-docker.sh "$BUILD_ROOT"
# Copy the built artifact into the source tree so it can be included in the
# built JAR.
OUTPUT_ROOT=src/main/resources/$image
mkdir -p $OUTPUT_ROOT
if [ -e $BUILD_ROOT/lib/libh3-java.so ]; then cp $BUILD_ROOT/lib/libh3-java.so $OUTPUT_ROOT ; fi
if [ -e $BUILD_ROOT/lib/libh3-java.dylib ]; then cp $BUILD_ROOT/lib/libh3-java.dylib $OUTPUT_ROOT ; fi
if [ -e $BUILD_ROOT/lib/libh3-java.dll ]; then cp $BUILD_ROOT/lib/libh3-java.dll $OUTPUT_ROOT ; fi
if $REMOVE_IMAGES; then
docker rmi dockcross/$image
rm $BUILD_ROOT/dockcross
fi
echo Current disk usage:
df -h
done