Repository navigation
Expand file tree
/
Copy pathbuild-h3.sh
More file actions
executable file
·243 lines (201 loc) · 7.57 KB
/
Copy pathbuild-h3.sh
File metadata and controls
executable file
·243 lines (201 loc) · 7.57 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/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] [github-artifacts] [github-artifacts-ref]
# 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.
# system-prune - If use-docker is true and this argument is true, Docker
# system prune will be run after each step
# (i.e. for disk space constrained environments like CI)
# dockcross-tag - Tag name for dockcross
# dockcross-only - When set, build only a specific architecture with dockcross.
# github-artifacts - When set, all build artifacts are retrieved from Github
# Actions artifacts rather than built locally (overrides
# all other settings.)
# github-artifacts-run - When set, assume the artifacts have already been
# downloaded.
#
# 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
SYSTEM_PRUNE=$4
DOCKCROSS_TAG=$5
DOCKCROSS_ONLY=$6
GITHUB_ARTIFACTS=$7
GITHUB_ARTIFACTS_RUN=$8
if $GITHUB_ARTIFACTS; then
src/main/c/h3-java/pull-from-github.sh "$GITHUB_ARTIFACTS_RUN"
# The build of the library below is still needed for the binding-functions file
fi
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
if $GITHUB_ARTIFACTS; then
# Nothing more is needed than the binding-functions to stop now.
exit 0
fi
# 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 ;;
"Linux aarch64") LIBRARY_DIR=linux-arm64 ;;
"Darwin x86_64") LIBRARY_DIR=darwin-x64 ;;
"Darwin arm64") LIBRARY_DIR=darwin-arm64 ;;
"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
# Cross compile from Mac arm64 to Mac x64
if [ "$(uname -sm)" == "Darwin arm64" ]; then
pushd target
mkdir -p h3-java-build-mac-x64
pushd h3-java-build-mac-x64
mkdir -p build
pushd build
cmake -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
../../h3
cmake --build . --target h3 --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 \
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
../../src/main/c/h3-java
cmake --build . --target h3-java --config Release
popd # h3-java-build
popd # target
mkdir -p src/main/resources/darwin-x64
cp target/h3-java-build-mac-x64/lib/libh3-java* src/main/resources/darwin-x64
fi
#
# 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
# Needed for older versions of dockcross
UPGRADE_CMAKE=false
CMAKE_ROOT=target/cmake-3.23.2-linux-x86_64
mkdir -p $CMAKE_ROOT
DOCKCROSS_IMAGES="android-arm android-arm64 linux-arm64 linux-armv5 linux-armv7 linux-s390x linux-ppc64le linux-x64 linux-x86 windows-static-x64 windows-static-x86"
if ! [ -z $DOCKCROSS_ONLY ]; then
DOCKCROSS_IMAGES=$DOCKCROSS_ONLY
echo Building only: $DOCKCROSS_IMAGES
fi
# linux-armv6 excluded because of build failure
# linux-mips excluded due to manifest error
for image in $DOCKCROSS_IMAGES; do
# Setup for using dockcross
BUILD_ROOT=target/h3-java-build-$image
mkdir -p $BUILD_ROOT
docker pull dockcross/$image:$DOCKCROSS_TAG
docker run --rm dockcross/$image:$DOCKCROSS_TAG > $BUILD_ROOT/dockcross
chmod +x $BUILD_ROOT/dockcross
SPECIAL_ANDROID_FLAGS=""
if [ "$image" = "android-arm" ]; then
SPECIAL_ANDROID_FLAGS="-DH3_JAVA_ANDROID=ON"
fi
if [ "$image" = "android-arm64" ]; then
SPECIAL_ANDROID_FLAGS="-DH3_JAVA_ANDROID=ON"
fi
# 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" "$UPGRADE_CMAKE" "$CMAKE_ROOT" "$SPECIAL_ANDROID_FLAGS"
if [[ "$image" == android-* ]]; then
$BUILD_ROOT/dockcross readelf -d "$BUILD_ROOT/lib/libh3-java.so" |
grep -q 'Shared library: \[libm.so\]'
fi
# Copy the built artifact into the source tree so it can be included in the
# built JAR.
OUTPUT_ROOT=src/main/resources/$image
if [ "$image" = "windows-static-x64" ]; then
OUTPUT_ROOT=src/main/resources/windows-x64
fi
if [ "$image" = "windows-static-x86" ]; then
OUTPUT_ROOT=src/main/resources/windows-x86
fi
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 $SYSTEM_PRUNE; then
# Aggressively try to free more disk space.
# If this turns out to be more trouble, split running for different architectures
# into different jobs.
docker system prune --force --all
docker system df
rm $BUILD_ROOT/dockcross
fi
echo Current disk usage:
df -h
done