Skip to content

Instantly share code, notes, and snippets.

@leobalter
Last active February 26, 2016 04:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leobalter/aa8953b9a317e2ae9696 to your computer and use it in GitHub Desktop.
Save leobalter/aa8953b9a317e2ae9696 to your computer and use it in GitHub Desktop.
v8 build on Mac/Linux

Follow instructions on Mozilla Wiki or TL;DR:

$ hg clone http://hg.mozilla.org/mozilla-central spidermonkey

Or use git from the GitHub mirror.

The following command avoid clonning the whole repo, but the last commit reference and the HEAD branch

$ git clone  --depth 1 --single-branch git@github.com:mozilla/gecko-dev.git spidermonkey

To build for the first time:

cd js/src/ && \
  autoconf213 && \
  mkdir build_DBG.OBJ && \
  cd build_DBG.OBJ  && \
  ../configure --enable-debug --disable-optimize && \
  make

Create an alias on your .bashrc:

alias js-dev='~/dev/spidermonkey/js/src/build_DBG.OBJ/dist/bin/js'

To Rebuild follow the instructions on the Mozilla Wiki website

Building v8 is easy but not well documented, so here's a fast guide to track you until v8 is up and running in your machine.

First, clone chromium depot_tools and set the given folder to your PATH.

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=`pwd`/depot_tools:"$PATH"

It's also good to include this export statement at .bashrc replacing `pwd` with your pwd return. Just try the pwd command if you didn't heard of it before.

Now fetch the v8 source. It might take more than 1 minute.

$ fetch v8

At this point, if you use Mac OS, open your Activity Monitor, click on Window on the context menu and then on CPU Usage to track your cores usage.

Now build your v8 and replace CORES but the n of cores you want to use for the build. Max is the total cores you have. (e.g.: make native -j 4.

$ cd v8/
$ make native -j `CORES`

This process might take more than 5 minutes. Get a coffee.

After it's done, you'll be able to find the built v8 for development d8 bin at out/native.

$ cd out/native
$ ls d8
d8

From this point you can already just run d8 and play with it.

$ ./d8
V8 version 4.3.0 (candidate) [console: dumb]
d8> var foo = "bar";
undefined
d8> foo
"bar"
d8>

If you wanna try some of the new JS features, in that case you need to use flags.

$ ./d8 --harmony_classes --harmony_sloppy
V8 version 4.3.0 (candidate) [console: dumb]
d8> class Foo {}
class Foo {}
d8> var f = new Foo()
undefined
d8> f
{}
d8>

If you want to check all the d8 flags, just run d8 --help, there's a lot of things.

Create an alias for d8 on your .bashrc:

alias d8='~/dev/v8/out/native/d8'

And now you can run d8 from anywhere in your system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment