-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
build_v8.sh
executable file
·272 lines (243 loc) · 7.44 KB
/
build_v8.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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/sh
#
# Appcelerator Titanium Mobile
# Copyright (c) 2011-2017 by Appcelerator, Inc. All Rights Reserved.
# Licensed under the terms of the Apache Public License
# Please see the LICENSE included with this distribution for details.
#
# Build and bundling script for v8 / NDK toolchain
usage()
{
cat <<EOF
Usage: $0 options
This script builds v8 against the Android NDK.
Options:
-h Show this help message and exit
-s <sdk_dir> The path to the Android SDK. Alternatively, you may set the ANDROID_SDK environment variable
-n <ndk_dir> The path to the Android NDK. Alternatively, you may set the ANDROID_NDK environment variable
-j <num-cpus> The number of processors to use in building (passed on to make)
-m <mode> The v8 build mode (release, debug, all. default: release)
-l <lib-version> Architectures to build for (arm, x64, ia32, arm64, mipsel, x87, all. default: arm)
-t Package a thirdparty tarball for uploading (don't build)
-c Clean the V8 build
-p <api-level> The Android SDK version to support (android-8, android-9, etc.)
EOF
}
NUM_CPUS=1
MODE=release
LIB_VERSION=arm
THIRDPARTY=0
CLEAN=0
PLATFORM_VERSION=android-23
while getopts "hts:cn:j:m:l:p:" OPTION; do
case $OPTION in
h)
usage
exit
;;
n)
NDK_DIR=$OPTARG
;;
m)
MODE=$OPTARG
;;
j)
NUM_CPUS=$OPTARG
;;
t)
THIRDPARTY=1
;;
s)
SDK_DIR=$OPTARG
;;
l)
LIB_VERSION=$OPTARG
;;
c)
CLEAN=1
;;
p)
PLATFORM_VERSION=$OPTARG
;;
?)
usage
exit
;;
esac
done
# NDK
if [ "$NDK_DIR" = "" ]; then
NDK_DIR=$ANDROID_NDK
fi
if [ "$NDK_DIR" = "" ]; then
echo "Error: No Android NDK directory was specified, supply '-n </path/to/ndk>' or set ANDROID_NDK"
usage
exit 1
fi
echo "Building against Android NDK: $NDK_DIR"
# SDK
if [ "$SDK_DIR" = "" ]; then
SDK_DIR=$ANDROID_SDK
fi
if [ "$SDK_DIR" = "" ]; then
echo "Error: No Android SDK directory was specified, supply '-s </path/to/sdk>' or set ANDROID_SDK"
usage
exit 1
fi
echo "Building against Android SDK: $SDK_DIR"
THIS_DIR=$(cd "$(dirname "$0")"; pwd)
BUILD_DIR=$THIS_DIR/build
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
V8_DIR=$THIS_DIR/v8
buildV8()
{
BUILD_MODE=$1
BUILD_LIB_VERSION=$2
BUILDER_NAME=$3
BUILDER_GROUP=$4
echo "Building V8 mode: $BUILD_MODE, lib: $BUILD_LIB_VERSION, arch: $ARCH"
cd "$V8_DIR"
# Build V8
MAKE_TARGET="android_$BUILD_LIB_VERSION.$BUILD_MODE"
tools/dev/v8gen.py gen --no-goma -b "$BUILDER_NAME" -m $BUILDER_GROUP $MAKE_TARGET -- use_goma=false v8_use_snapshot=true v8_enable_embedded_builtins=false v8_use_external_startup_data=false v8_static_library=true v8_enable_i18n_support=false android_sdk_root=\"$SDK_DIR\" android_ndk_root=\"$NDK_DIR\" android_ndk_major_version=19 android_ndk_version=\"r19c\" v8_monolithic=true target_os=\"android\" use_custom_libcxx=false v8_android_log_stdout=false
# Hack one of the toolchain items to fix AR executable used for android
cp -f ../overrides/build/toolchain/android/BUILD.gn "$V8_DIR/build/toolchain/android/BUILD.gn"
cp -f ../overrides/build/config/android/BUILD.gn "$V8_DIR/build/config/android/BUILD.gn"
cp -f ../overrides/build/config/compiler/BUILD.gn "$V8_DIR/build/config/compiler/BUILD.gn"
ninja -v -C out.gn/$MAKE_TARGET -j $NUM_CPUS v8_monolith
# Copy the static libraries to our staging area.
DEST_DIR="$BUILD_DIR/$BUILD_MODE"
mkdir -p "$DEST_DIR/libs/$ARCH" 2>/dev/null || echo
cp "$V8_DIR/out.gn/$MAKE_TARGET/obj/libv8_monolith.a" "$DEST_DIR/libs/$ARCH/libv8_monolith.a"
MKSNAPSHOT_X86="$V8_DIR/out.gn/$MAKE_TARGET/clang_x86/mksnapshot"
if [ -f $MKSNAPSHOT_X86 ]; then
cp $MKSNAPSHOT_X86 "$DEST_DIR/libs/$ARCH/mksnapshot"
fi
MKSNAPSHOT_X64="$V8_DIR/out.gn/$MAKE_TARGET/clang_x64/mksnapshot"
if [ -f $MKSNAPSHOT_X64 ]; then
cp $MKSNAPSHOT_X64 "$DEST_DIR/libs/$ARCH/mksnapshot"
fi
MKSNAPSHOT_ARM="$V8_DIR/out.gn/$MAKE_TARGET/clang_x86_v8_arm/mksnapshot"
if [ -f $MKSNAPSHOT_ARM ]; then
cp $MKSNAPSHOT_ARM "$DEST_DIR/libs/$ARCH/mksnapshot"
fi
MKSNAPSHOT_ARM64="$V8_DIR/out.gn/$MAKE_TARGET/clang_x64_v8_arm64/mksnapshot"
if [ -f $MKSNAPSHOT_ARM64 ]; then
cp $MKSNAPSHOT_ARM64 "$DEST_DIR/libs/$ARCH/mksnapshot"
fi
}
buildThirdparty()
{
BUILD_MODE=$1
# Copied from v8/tools/push-to-trunk.sh
VERSION_FILE=$V8_DIR/include/v8-version.h
MAJOR=$(grep "#define V8_MAJOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
MINOR=$(grep "#define V8_MINOR_VERSION" "$VERSION_FILE" | awk '{print $NF}')
BUILD=$(grep "#define V8_BUILD_NUMBER" "$VERSION_FILE" | awk '{print $NF}')
PATCH=$(grep "#define V8_PATCH_LEVEL" "$VERSION_FILE" | awk '{print $NF}')
cd "$V8_DIR"
V8_VERSION="$MAJOR.$MINOR.$BUILD.$PATCH"
V8_GIT_REVISION=$(git rev-parse HEAD)
V8_GIT_BRANCH=$(git status -s -b | grep \#\# | sed 's/\#\# //' | sed 's/...origin\/.*//')
V8_SVN_REVISION=$(git log -n 1 | grep git-svn-id | perl -ne 's/\s+git-svn-id: [^@]+@([^\s]+) .+/\1/; print')
DEST_DIR="$BUILD_DIR/$BUILD_MODE"
DATE=$(date '+%Y-%m-%d %H:%M:%S')
cat <<EOF > "$DEST_DIR/libv8.json"
{
"version": "$V8_VERSION",
"git_revision": "$V8_GIT_REVISION",
"git_branch": "$V8_GIT_BRANCH",
"svn_revision": "$V8_SVN_REVISION",
"timestamp": "$DATE"
}
EOF
mkdir -p "$DEST_DIR/libs" "$DEST_DIR/include" "$DEST_DIR/include/libplatform" 2>/dev/null
find "$V8_DIR/include" -name '*.h' -exec cp -pv '{}' "$DEST_DIR/include" ';'
find "$V8_DIR/include/libplatform" -name '*.h' -exec cp -pv '{}' "$DEST_DIR/include/libplatform" ';'
cd "$DEST_DIR"
echo "Building libv8-$V8_VERSION-$BUILD_MODE.tar.bz2..."
tar -cvj -f libv8-$V8_VERSION-$BUILD_MODE.tar.bz2 libv8.json libs include
}
if [ "$CLEAN" = "1" ]; then
cd v8 && rm -rf out.gn/
exit;
fi
if [ "$LIB_VERSION" = "all" ]; then
LIB_VERSION="ia32 x64 arm arm64 mipsel x87"
fi
if [ "$MODE" = "all" ]; then
MODE="release debug"
fi
if [ "$THIRDPARTY" = "0" ]; then
for build_lib_version in $LIB_VERSION; do
# Set ARCH for buildToolchain
case $build_lib_version in
arm)
ARCH=arm
BUILDER_NAME="V8 Android Arm - builder"
BUILDER_GROUP="client.v8.ports"
;;
ia32)
ARCH=x86
BUILDER_NAME="V8 Win32 - builder"
BUILDER_GROUP="client.v8"
;;
mipsel)
ARCH=mips
BUILDER_NAME="V8 Mips - builder"
BUILDER_GROUP="client.v8.ports"
;;
arm64)
ARCH=arm64
BUILDER_NAME="V8 Android Arm64 - builder"
BUILDER_GROUP="client.v8.ports"
;;
x64)
ARCH=x86_64
BUILDER_NAME="V8 Win64"
BUILDER_GROUP="client.v8"
;;
x87)
ARCH=x86
;;
*)
echo "Invalid -l"
echo "Please use one of ia32, x64, arm, arm64, mipsel, or x87"
ARCH=null
exit 1
;;
esac
# Verify we have a target platform that works with the selected arch
# TODO Do we need to do this? I think Android NDK scripts do this for us!
REV=`echo ${PLATFORM_VERSION} | sed s/android-//`
case $ARCH in
arm)
if [ $REV -lt 3 ]; then
echo "Cannot build arm with android rev lower than SDK 3; use -p option to specify a different SDK"
exit 1
fi;
;;
x86|mips)
if [ $REV -lt 9 ]; then
echo "Cannot build x86 with android rev lower than SDK 9; use -p option to specify a different SDK"
exit 1
fi;
;;
arm64|x86_64|mips64)
if [ $REV -lt 21 ]; then
echo "Cannot build 64-bit with android rev lower than SDK 21; use -p option to specify a different SDK"
exit 1
fi;
;;
esac
for build_mode in $MODE; do
buildV8 $build_mode $build_lib_version "$BUILDER_NAME" $BUILDER_GROUP
done
done
else
for build_mode in $MODE; do
buildThirdparty $build_mode
done
fi