Skip to content

Commit 72463dc

Browse files
authored
chore: V8 build cleanup (#200)
* chore: update xcode project to recommended settings & remove duplicates * feat: add fetch/patch script for v8 This still requires depot_tools to be on your PATH. * feat: improved/cleaned up v8 build script
1 parent 3b4ecf1 commit 72463dc

File tree

11 files changed

+200
-3933
lines changed

11 files changed

+200
-3933
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ node_modules/
4242
package-lock.json
4343
*.pyc
4444
v8
45+
v8_build
4546
.npmrc
4647

4748
llvm/
4849

4950
# v8 build files...
50-
.gclient_entries
51-
.gclient
51+
.gclient*
5252
.cipd/

build_v8_source.sh

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,96 @@
11
#!/bin/bash
22
set -e
3+
source "$(dirname "$0")/build_utils.sh"
34

45
pushd v8
56

67
ARCH_ARR=(x64-simulator arm64-simulator arm64-device)
7-
MODULES=(v8_base_without_compiler v8_compiler v8_libplatform v8_libbase v8_bigint v8_snapshot v8_heap_base v8_heap_base_headers torque_generated_initializers torque_generated_definitions)
8+
MODULES=(
9+
cppgc_base
10+
torque_generated_definitions
11+
torque_generated_initializers
12+
v8_base_without_compiler
13+
v8_bigint
14+
v8_compiler
15+
v8_heap_base
16+
v8_heap_base_headers
17+
v8_libbase
18+
v8_libplatform
19+
v8_snapshot
20+
)
21+
GN_ARGS_BASE="
22+
treat_warnings_as_errors=false
23+
24+
icu_use_data_file=false
25+
use_custom_libcxx=false
26+
use_xcode_clang=true
27+
28+
is_component_build=false
29+
is_debug=false
30+
31+
enable_ios_bitcode=false
32+
ios_deployment_target=12
33+
ios_enable_code_signing=false
34+
target_os=\"ios\"
35+
36+
v8_control_flow_integrity=false
37+
v8_monolithic=true
38+
v8_static_library=true
39+
v8_use_external_startup_data=false
40+
41+
v8_enable_sandbox=false
42+
v8_enable_debugging_features=false
43+
v8_enable_i18n_support=false
44+
v8_enable_lite_mode=true
45+
v8_enable_pointer_compression=false
46+
v8_enable_v8_checks=false
47+
v8_enable_webassembly=false
48+
"
49+
# is_official_build=true
50+
# clang_base_path=\"/Applications/Xcode-14.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr\"
51+
52+
# GN_ARGS_BASE = "$GN_ARGS_BASE v8_embedder_string=\"-nativescript\""
53+
54+
DIST="../v8_build"
55+
mkdir -p $DIST
56+
57+
58+
function archiveLib() {
59+
MODULE=$1
60+
OBJECTS=$2
61+
ARCH=$3
62+
MODULE_DEST=$DIST/$ARCH/_lib/$MODULE.a
63+
checkpoint "Archiving $MODULE"
64+
echo "MODULE= $MODULE"
65+
echo "OBJECTS= $OBJECTS"
66+
echo "ARCH= $ARCH"
67+
echo "MODULE_DEST= $MODULE_DEST"
68+
ar r $MODULE_DEST $OBJECTS || echo "Failed to archive $MODULE..."
69+
echo ""
70+
echo "Archiving $MODULE done."
71+
72+
checkpoint "Stripping $MODULE"
73+
strip $MODULE_DEST || echo "Failed to strip $MODULE..."
74+
}
875

976
for CURRENT_ARCH in ${ARCH_ARR[@]}
1077
do
78+
mkdir -p "$DIST/$CURRENT_ARCH/_lib"
1179
OUTFOLDER=out.gn/$CURRENT_ARCH-release
1280
ARCH_PARTS=(${CURRENT_ARCH//-/ })
1381
TARGET_ENV=${ARCH_PARTS[1]}
14-
echo "Building for $OUTFOLDER ($TARGET_ENV)"
82+
checkpoint "Building V8 for $OUTFOLDER ($TARGET_ENV)"
1583
ARCH=${ARCH_PARTS[0]}
16-
gn gen $OUTFOLDER --args="v8_enable_webassembly=false treat_warnings_as_errors=false v8_enable_pointer_compression=false is_official_build=true use_custom_libcxx=false is_component_build=false symbol_level=0 v8_enable_v8_checks=false v8_enable_debugging_features=false is_debug=false v8_use_external_startup_data=false use_xcode_clang=true enable_ios_bitcode=true v8_enable_i18n_support=false target_environment=\"$TARGET_ENV\" target_cpu=\"$ARCH\" v8_target_cpu=\"$ARCH\" target_os=\"ios\" ios_deployment_target=\"9.0\""
17-
ninja -C $OUTFOLDER ${MODULES[@]} inspector
84+
# gn args --list $OUTFOLDER
85+
gn gen $OUTFOLDER --args="${GN_ARGS_BASE} target_environment=\"$TARGET_ENV\" target_cpu=\"$ARCH\" v8_target_cpu=\"$ARCH\""
86+
# exit 0;
87+
echo "Started building v8: $(date)"
88+
ninja $@ -C $OUTFOLDER ${MODULES[@]} inspector
89+
echo "Finished building v8: $(date)"
1890

1991
for MODULE in ${MODULES[@]}
2092
do
21-
ar r $OUTFOLDER/obj/$MODULE/lib$MODULE.a $OUTFOLDER/obj/$MODULE/*.o
93+
archiveLib "lib$MODULE" "$OUTFOLDER/obj/$MODULE/*.o" $CURRENT_ARCH
2294
done
2395

2496
# Those libraries are needed if we set v8_enable_i18n_support=true
@@ -27,49 +99,36 @@ do
2799
# OBJECTS="$OBJECTS $OUTFOLDER/obj/third_party/icu/icui18n/*.o"
28100
# OBJECTS="$OBJECTS $OUTFOLDER/obj/v8_crash_keys/*.o"
29101

30-
# ar r $OUTFOLDER/libv8.a $OBJECTS
31-
done
32-
33-
DIST="./dist"
34-
mkdir -p $DIST
35-
for MODULE in ${MODULES[@]}
36-
do
37-
for CURRENT_ARCH in ${ARCH_ARR[@]}
38-
do
39-
mkdir -p "$DIST/$CURRENT_ARCH"
40-
OUTFOLDER=out.gn/$CURRENT_ARCH-release
41-
cp "$OUTFOLDER/obj/$MODULE/lib$MODULE.a" "$DIST/$CURRENT_ARCH"
42-
done
102+
# archiveLib "libv8" "$OBJECTS" $CURRENT_ARCH
43103
done
44104

45105
for CURRENT_ARCH in ${ARCH_ARR[@]}
46106
do
47-
mkdir -p "$DIST/$CURRENT_ARCH"
48-
OUTFOLDER=out.gn/$CURRENT_ARCH-release
49-
ar r $OUTFOLDER/obj/third_party/inspector_protocol/libinspector_protocol.a $OUTFOLDER/obj/third_party/inspector_protocol/crdtp/*.o $OUTFOLDER/obj/third_party/inspector_protocol/crdtp_platform/*.o
50-
cp "$OUTFOLDER/obj/third_party/inspector_protocol/libinspector_protocol.a" "$DIST/$CURRENT_ARCH"
107+
checkpoint "Packaging libraries for $CURRENT_ARCH..."
51108

52-
ZLIB_INPUT="$OUTFOLDER/obj/third_party/zlib/zlib/*.o"
53109
ARCH_PARTS=(${CURRENT_ARCH//-/ })
54110
ARCH=${ARCH_PARTS[0]}
111+
112+
mkdir -p "$DIST/$CURRENT_ARCH"
113+
OUTFOLDER=out.gn/$CURRENT_ARCH-release
114+
115+
ZLIB_INPUT="$OUTFOLDER/obj/third_party/zlib/zlib/*.o"
116+
55117
if [ $ARCH = "arm64" ]; then
56118
ZLIB_INPUT="$ZLIB_INPUT $OUTFOLDER/obj/third_party/zlib/zlib_adler32_simd/*.o"
57119
ZLIB_INPUT="$ZLIB_INPUT $OUTFOLDER/obj/third_party/zlib/zlib_inflate_chunk_simd/*.o"
58120
fi
59121

60122
ZLIB_INPUT="$ZLIB_INPUT $OUTFOLDER/obj/third_party/zlib/google/compression_utils_portable/*.o"
61123

62-
ar r $OUTFOLDER/obj/third_party/zlib/libzip.a $ZLIB_INPUT
63-
cp "$OUTFOLDER/obj/third_party/zlib/libzip.a" "$DIST/$CURRENT_ARCH"
64-
65-
ar r $OUTFOLDER/obj/cppgc_base/libcppgc_base.a $OUTFOLDER/obj/cppgc_base/*.o
66-
cp "$OUTFOLDER/obj/cppgc_base/libcppgc_base.a" "$DIST/$CURRENT_ARCH"
67-
68-
ar r $OUTFOLDER/obj/v8_cppgc_shared/libv8_cppgc_shared.a $OUTFOLDER/obj/v8_cppgc_shared/*.o
69-
cp "$OUTFOLDER/obj/v8_cppgc_shared/libv8_cppgc_shared.a" "$DIST/$CURRENT_ARCH"
124+
archiveLib "libzip" "$ZLIB_INPUT" $CURRENT_ARCH
125+
archiveLib "libcrdtp" "$OUTFOLDER/obj/third_party/inspector_protocol/crdtp/*.o" $CURRENT_ARCH
126+
archiveLib "libcrdtp_platform" "$OUTFOLDER/obj/third_party/inspector_protocol/crdtp_platform/*.o" $CURRENT_ARCH
127+
archiveLib "libcppgc_base" "$OUTFOLDER/obj/cppgc_base/*.o" $CURRENT_ARCH
70128

71-
cp "$OUTFOLDER/obj/src/inspector/libinspector.a" "$DIST/$CURRENT_ARCH"
72-
cp "$OUTFOLDER/obj/src/inspector/libinspector_string_conversions.a" "$DIST/$CURRENT_ARCH"
129+
checkpoint "Copying libinspector and libinspector_string_conversions"
130+
cp "$OUTFOLDER/obj/src/inspector/libinspector.a" "$DIST/$CURRENT_ARCH/_lib" || echo "Skip"
131+
cp "$OUTFOLDER/obj/src/inspector/libinspector_string_conversions.a" "$DIST/$CURRENT_ARCH/_lib" || echo "Skip"
73132
done
74133

75134
popd

fetch_v8.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
source "$(dirname "$0")/build_utils.sh"
4+
5+
V8_VERSION="10.3.22"
6+
7+
GCLIENT_SYNC_ARGS="
8+
--deps=ios
9+
--reset
10+
--with_branch_head
11+
--revision $V8_VERSION
12+
--delete_unversioned_trees
13+
"
14+
15+
checkpoint "Fetching V8 Version: $V8_VERSION"
16+
17+
echo running: gclient config --name v8 --unmanaged "https://chromium.googlesource.com/v8/v8.git"
18+
gclient config --name v8 --unmanaged "https://chromium.googlesource.com/v8/v8.git"
19+
20+
checkpoint "Syncing V8"
21+
echo running: gclient sync ${GCLIENT_SYNC_ARGS}
22+
gclient sync ${GCLIENT_SYNC_ARGS}
23+
24+
checkpoint "Patching V8"
25+
26+
V8_PATCHSET_IOS=(
27+
# Fix use_system_xcode build error
28+
"system_xcode_build_error.patch"
29+
30+
# Find libclang_rt.iossim.a on Xcode 14
31+
"v8_build_xcode14_toolchain_fixes.patch"
32+
)
33+
34+
for patch in "${V8_PATCHSET_IOS[@]}"
35+
do
36+
checkpoint "Patch set: ${patch}"
37+
patch -d "v8" -p1 < "v8_patches/$patch"
38+
done

0 commit comments

Comments
 (0)