Skip to content

Commit 11f0f85

Browse files
authored
Merge pull request #63 from lightpanda-io/v8_upgrade
V8 upgrade
2 parents fc764e7 + 935fd66 commit 11f0f85

File tree

304 files changed

+483
-47572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+483
-47572
lines changed

.dockerignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/zig-cache/
1+
/.zig-cache/
22
/zig-out/
3-
/tools/ninja_gn_binaries*
4-
/v8-build/
5-
/gclient/
63
/v8/

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/zig-cache/
2-
/tools/ninja_gn_binaries*
3-
/v8-build/
4-
/gclient/
5-
/v8/
6-
/zig-out/
7-
/vendor
8-
/libc_v8.a
91
/.zig-cache/
2+
/zig-out/
3+
/v8/

.gn

Lines changed: 0 additions & 37 deletions
This file was deleted.

BUILD.gn

Lines changed: 0 additions & 92 deletions
This file was deleted.

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ RUN apt update && \
1313
ADD . /src/
1414
WORKDIR /src
1515

16-
RUN zig build get-tools
16+
RUN zig build
1717
RUN zig build get-v8
18-
RUN zig build -Doptimize=ReleaseSafe
18+
RUN zig build -Doptimize=ReleaseSafe build-v8
1919

20-
RUN mv /src/v8-build/$ARCH-$OS/release/ninja/obj/zig/libc_v8.a /src/libc_v8.a
20+
RUN mv v8/out/release/obj/zig/libc_v8.a /src/libc_v8.a
2121

2222
FROM scratch as artifact
2323

README.md

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,87 +4,24 @@ Builds V8 from official source and provides C bindings and a Zig API. This would
44

55
V8 is the JS/WASM runtime that powers Google Chrome and Microsoft Edge.
66

7-
## Project Status
8-
Static libs are built and released with [Github Actions](https://github.com/fubark/zig-v8/actions).
9-
| Native | Cross Compile | Target | Demo Binary ([shell.zig](https://github.com/fubark/zig-v8/blob/master/src/shell.zig))* |
10-
| ------ | ------ | -------- | -------- |
11-
|| | Linux x64 | shell - 19 M |
12-
||| Windows x64 | shell.exe - 14 M |
13-
|| | macOS x64 | shell - 24 M |
14-
||| macOS arm64 | shell - 21 M |
15-
16-
\* shell.zig is a JS repl and statically linked with v8. Compiled with -Drelease-safe. The V8 dependency can be further reduced in size if you don't need all the features (eg. disable WASM runtime).
17-
18-
| Toolchain | Fresh Build* | Cached Build* |
19-
| ------ | ------ | ------ |
20-
| gclient, full feature + v8 toolchain | 1.5-2 hrs | with sccache: 10-20min |
21-
| minimal feature + v8 toolchain | 40-50 min | with sccache: 5-10min |
22-
| minimal feature + zig c++ toolchain | | with zig caching: |
23-
24-
\* Time is measured on standard Github instances.
25-
267
## System Requirements
278
- Zig compiler (0.14.0). Clone and build https://github.com/ziglang/zig.
289
- Python 3 (2.7 seems to work as well)
10+
- unzip (`apt install unzip`)
2911
- For native macOS builds:
3012
- XCode (You won't need this when using zig's c++ toolchain!)<br/>
3113
if you come across this error:<br />
3214
`xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance`<br />
3315
run `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer`
3416

3517
## Build
36-
By default UseGclient=false in build.zig. This will pull the minimum sources and deps needed to build v8 and reduce build times.
37-
38-
If you want to include everything, set UseGclient=true. Build times can be quite long using gclient but afterwards rerunning "zig build" should be incremental. You can also use sccache for better incremental build times.
18+
Compiling v8 will take 20+ minutes.
3919

4020
```sh
41-
# Clone the repo.
42-
git clone https://github.com/fubark/zig-v8.git
43-
cd zig-v8
44-
45-
# Pull prebuilt GN/Ninja. If UseGclient=true, it also pulls depot_tools.
46-
zig build get-tools
47-
48-
# Pull v8 source
4921
zig build get-v8
50-
51-
# Build, resulting static library should be at:
52-
# v8-build/{target}/{debug/release}/ninja/obj/zig/libc_v8.a
53-
# On windows, use msvc: zig build zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-msvc
54-
zig build -Doptimize=ReleaseSafe
55-
```
56-
## Demo
57-
```sh
58-
# shell.zig is a simple JS repl.
59-
# Assumes you've already built v8.
60-
zig build run -Dpath="src/shell.zig" -Doptimize=ReleaseSafe
61-
62-
# If you built v8 using the zig toolchain, you'll need to add the flag here as well.
63-
zig build run -Dpath="src/shell.zig" -Doptimize=ReleaseSafe -Dzig-toolchain
64-
```
65-
66-
## Cross Compiling
67-
With Zig's toolchain, we can build V8 from libstdc++ that's bundled with zig and cross compile to foreign targets/cpus! Simply amazing. Eventually, this will also replace the default V8 toolchain for native builds after further testing.
68-
### Linux x64 (Host) to MacOS arm64 (Target)
69-
```sh
70-
# Assumes you've fetched tools and v8 sources. See above build steps.
71-
# Resulting static lib will be at:
72-
# v8-build/aarch64-macos/release/ninja/obj/zig/libc_v8.a
73-
zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-macos-gnu -Dzig-toolchain
74-
```
75-
76-
### Cross compile to Windows with gnu (mingw64)
77-
Zig comes with mingw64 source and headers so you'll be able to target Windows without MSVC.
78-
```sh
79-
zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-gnu -Dzig-toolchain
22+
zig build build-v8
8023
```
8124

82-
## Usage
83-
84-
See src/shell.zig or test/test.zig on how to use the library with the Zig API as well as build.zig (fn linkV8) on how to link with the built V8 static library.
85-
86-
## Contributing
87-
88-
The C bindings is incomplete but it should be relatively easy to add more as we need them.
25+
Once complete, you can find v8 in: `v8/out/debug/obj/zig/libc_v8.a`
8926

90-
C API naming convention should closely follow the V8 C++ API.
27+
If you build with `zig build -Doptimize=ReleaseFast build-v8`, v8 will be in `v8/out/release/obj/zig/libc_v8.a`.

V8_REVISION

Lines changed: 0 additions & 1 deletion
This file was deleted.

build-tools/.gn

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# This file is used by the GN meta build system to find the root of the source
2+
# tree and to set startup options. For documentation on the values set in this
3+
# file, run "gn help dotfile" at the command line.
4+
5+
# Use the default python3 so gn succeeds. Not sure why deno requires python2 atm.
6+
script_executable = "python3"
7+
8+
# The location of the build configuration file.
9+
buildconfig = "//build/config/BUILDCONFIG.gn"
10+
11+
# These are the targets to check headers for by default. The files in targets
12+
# matching these patterns (see "gn help label_pattern" for format) will have
13+
# their includes checked for proper dependencies when you run either
14+
# "gn check" or "gn gen --check".
15+
check_targets = []
16+
17+
# The secondary source root is a parallel directory tree where
18+
# GN build files are placed when they can not be placed directly
19+
# in the source tree, e.g. for third party source trees.
20+
secondary_source = "//v8/"
21+
22+
default_args = {
23+
clang_use_chrome_plugins = false
24+
is_component_build = false
25+
linux_use_bundled_binutils = false
26+
use_dummy_lastchange = true
27+
use_sysroot = false
28+
simple_template_names = false
29+
30+
# Minimize size of debuginfo in distributed static library.
31+
line_tables_only = true
32+
no_inline_line_tables = true
33+
symbol_level = 1
34+
use_debug_fission = false
35+
36+
v8_embedder_string = "-lightpanda"
37+
38+
v8_enable_sandbox = false
39+
v8_enable_javascript_promise_hooks = true
40+
v8_promise_internal_field_count = 1
41+
v8_use_external_startup_data = false
42+
43+
v8_enable_pointer_compression = true
44+
45+
v8_imminent_deprecation_warnings = false
46+
47+
# This flag speeds up the performance of fork/execve on Linux systems for
48+
# embedders which use it (like Node.js). It works by marking the pages that
49+
# V8 allocates as MADV_DONTFORK. Without MADV_DONTFORK, the Linux kernel
50+
# spends a long time manipulating page mappings on fork and exec which the
51+
# child process doesn't generally need to access.
52+
v8_enable_private_mapping_fork_optimization = true
53+
54+
# We prefer embedders to bring their own compression
55+
v8_use_zlib = true
56+
v8_enable_snapshot_compression = false
57+
58+
# Disable handle zapping for performance
59+
v8_enable_handle_zapping = false
60+
# Ensure allocation of typed arrays and arraybuffers always goes through
61+
# the embedder's ArrayBufferAllocator, otherwise small buffers get moved
62+
# around by the garbage collector but embedders normally want them to have
63+
# fixed addresses.
64+
v8_typed_array_max_size_in_heap = 0
65+
66+
# Historically these always had 2 slots. Keep for compat.
67+
v8_array_buffer_internal_field_count = 2
68+
v8_array_buffer_view_internal_field_count = 2
69+
70+
# Enabling the shared read-only heap comes with a restriction that all
71+
# isolates running at the same time must be created from the same snapshot.
72+
# This is problematic for Deno, which has separate "runtime" and "typescript
73+
# compiler" snapshots, and sometimes uses them both at the same time.
74+
v8_enable_shared_ro_heap = false
75+
76+
# V8 11.6 hardcoded an assumption in `mksnapshot` that shared RO heap
77+
# is enabled. In our case it's disabled so without this flag we can't
78+
# compile.
79+
v8_enable_verify_heap = false
80+
81+
# Enable V8 object print for debugging.
82+
# v8_enable_object_print = true
83+
84+
# V8 12.3 added google/fuzztest as a third party dependency.
85+
# https://chromium.googlesource.com/v8/v8.git/+/d5acece0c9b89b18716c177d1fcc8f734191e1e2%5E%21/#F4
86+
#
87+
# This flag disables it.
88+
v8_enable_fuzztest = false
89+
90+
# Disable v8::HandleScope LIFO checks.
91+
# https://chromium-review.googlesource.com/c/v8/v8/+/5110566
92+
#
93+
# rusty_v8 scopes are not on the stack.
94+
v8_enable_v8_checks = false
95+
96+
use_relative_vtables_abi = false
97+
98+
icu_use_data_file = false
99+
}

BUILD.gclient.gn renamed to build-tools/BUILD.gn

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
22
# Based on https://github.com/denoland/rusty_v8/blob/main/BUILD.gn
3-
import("//build/config/host_byteorder.gni")
43

54
static_library("c_v8") {
65
complete_static_lib = true
7-
sources = [ "../../binding.cpp" ]
6+
7+
sources = [ "../binding.cpp" ]
88
deps = [
99
"//build/config:shared_library_deps",
1010
"//:v8",
@@ -43,8 +43,4 @@ config("c_v8_config") {
4343
"-fansi-escape-codes",
4444
]
4545
}
46-
47-
if (is_debug && is_clang && !is_win) {
48-
cflags += [ "-glldb" ]
49-
}
5046
}

0 commit comments

Comments
 (0)