0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-28 16:21:04 -05:00
Rust bindings for the V8 JavaScript engine
Find a file
Ryan Dahl d70088fa06
ci: Use github action's cache (#319)
We don't have many crate deps, but this is free and reduces sccache load slightly.
2020-03-18 10:48:34 -04:00
.github/workflows ci: Use github action's cache (#319) 2020-03-18 10:48:34 -04:00
base/trace_event Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
build@cfbf17d712 Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
buildtools@d0a9124cf0 Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
src Add v8::Function::new_with_data to attach associated data (#310) 2020-03-14 22:42:18 -04:00
tests Add v8::Function::new_with_data to attach associated data (#310) 2020-03-14 22:42:18 -04:00
third_party Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
tools Support binary downloads (#316) 2020-03-17 17:59:37 -04:00
v8@3f53e61b1c Upgrade V8 to 8.2.308 (#306) 2020-03-13 22:05:16 -07:00
.clang-format Add .clang-format 2019-12-18 17:40:45 -05:00
.gitignore add hello world example (#142) 2019-12-27 06:41:44 -05:00
.gitmodules Upgrade V8 to 8.1.108 (#197) 2020-01-08 01:40:25 +01:00
.gn Add AArch64/ARM64 builds and tests (#266) 2020-02-12 18:43:38 -08:00
.rustfmt.toml update 2019-10-08 02:06:48 +02:00
BUILD.gn Move all cc code to binding.cc (#70) 2019-12-18 07:37:13 -05:00
build.rs Use env var V8_BINARY instead of cargo feature 2020-03-17 20:32:21 -04:00
Cargo.lock v0.3.8 2020-03-17 20:32:21 -04:00
Cargo.toml v0.3.8 2020-03-17 20:32:21 -04:00
LICENSE clean up (#4) 2019-11-01 13:50:12 -04:00
README.md Use env var V8_BINARY instead of cargo feature 2020-03-17 20:32:21 -04:00

Rusty V8 Binding

V8 Version: 8.2.308, 2020-03-12

ci crates docs

Goals

  1. Provide high quality Rust bindings to V8's C++ API. The API should match the original API as closely as possible

  2. Do not introduce additional call overhead. (For example, previous attempts at Rust V8 bindings forced the use of Persistent handles.)

  3. Do not rely on a binary libv8.a built outside of cargo. V8 is a very large project (over 600,000 lines of C++) which often takes 30 minutes to compile. Furthermore, V8 relies on Chromium's bespoke build system (gn + ninja) which is not easy to use outside of Chromium. For this reason many attempts to bind to V8 rely on pre-built binaries that are built separately from the binding itself. While this is simple, it makes upgrading V8 difficult, it makes CI difficult, it makes producing builds with different configurations difficult, and it is a security concern since binary blobs can hide malicious code. For this reason we believe it is imperative to build V8 from source code during "cargo build".

  4. Publish the crate on crates.io and allow docs.rs to generate documentation. Due to the complexity and size of V8's build, this is nontrivial. For example the crate size must be kept under 10 MiB in order to publish.

Build V8 from Source

Use cargo build -vv to build the crate.

Depends on Python 2.7, not Python 3. Do not open issues with us regarding Python 3; it's something that must be fixed in Chromium..

For linux builds: glib-2.0 development files need to be installed such that pkg-config can find them. On Ubuntu, run sudo apt install libglib2.0-dev to install them.

For Windows builds: the 64-bit toolchain needs to be used. 32-bit targets are not supported.

The build depends on several binary tools: gn, ninja and a recent version of clang (V8 relies on bleeding edge features). Because these are not generally available they are automatically download during the build by default. It should be possible to opt out of the gn and ninja download by specifying the $GN and $NINJA environmental variables. The clang download can be skipped by providing a $CLANG_BASE_PATH environmental variable pointing to a recent llvm/clang installation (currently LLVM v8.0+ or Apple clang v11.0+). You could also pass in additional arguments to gn by setting the $GN_ARGS environmental variable.

Env vars used in build.rs: SCCACHE, GN, NINJA, CLANG_BASE_PATH, GN_ARGS

Binary Build

V8 is very large and take a long time to compile. Many users may prefer to use a prebuilt version of V8. We publish static libs for every version of rusty v8 on Github.

To use these prebuilt binaries use the V8_BINARY=1 environmental variable:

V8_BINARY=1 cargo build

This will cause rusty v8 to download the static lib binary during the build process.

FAQ

Building V8 takes over 30 minutes, this is too slow for me to use this crate. What should I do?

Install sccache. Our build scripts will detect and use sccache. Set the $SCCACHE environmental variable if it's not in your path.

What are all these random directories for like build and buildtools are these really necessary?

In order to build V8 from source code, we must provide a certain directory structure with some git submodules from Chromium. We welcome any simplifications to the code base, but this is a structure we have found after many failed attempts that carefully balances the requirements of cargo crates and GN/Ninja.

V8 has a very large API with hundreds of methods. Why don't you automate the generation of this binding code?

In the limit we would like to auto-generate bindings. We have actually started down this route several times, however due to many excentric features of the V8 API, this has not proven successful. Therefore we are proceeding in a brute-force fashion for now, focusing on solving our stated goals first. We hope to auto-generate bindings in the future.

Why are you building this?

This is to support the Deno project. We previously have gotten away with a simpler high-level Rust binding to V8 called libdeno. But as Deno has matured we've found ourselves continually needing access to an increasing amount of V8's API in Rust.

When building I get unknown argument: '-gno-inline-line-tables'

Use export GN_ARGS="no_inline_line_tables=false" during build.