by Keith Rosenberg (netpoetica)
Note: do this in some sort of project/ directory that makes sense. depot_tools are going to need to be in your path, so you may want to install them somewhere you are comfortable with.
git clone https://github.com/v8/v8.git
Note: you can read about depot_tools here
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
additionally, the path to depot tools must be available in your PATH, so add it to your ~/.zshrc or ~/.bashrc file
cd depot_tools
pwd
// should print ~/Desktop/git/depot_tools or the like
vim ~/.zshrc
// or .bashrc
// Add it to the path or add this line at the bottom of your file
export PATH=~/Desktop/git/depot_tools:"$PATH"
First make sure clang and clang++ are in in your PATH by running
which clang && which clang++
If for some reason you do not have clang available, make sure you have the most recent Xcode command line tools installed.
vim ~/.zshrc
and add the following:
export CXX="`which clang++`"
export CC="`which clang`"
export CPP="`which clang` -E"
export LINK="`which clang++`"
export CXX_host="`which clang++`"
export CC_host="`which clang`"
export CPP_host="`which clang` -E"
export LINK_host="`which clang++`"
export GYP_DEFINES="clang=1"
In the command line, in the v8 folder, run
make builddeps
it's worth noting that some documentation says to run
make dependencies
from what I can tell, they both install gyp, but make dependencies
installs some third party tools you may eventually need. So either one should work, but go ahead and run both if you want (I did) - it won't hurt anything.
Now the juicy part. In the v8 folder, you'll have to run make. v8's make lets you specify your architecture and number of cores.
However, your best bet is to let make figure out which architecture to build for your machine. If you know how many cores you have for your CPU, there is a command you can use to specify that.
If you open Activity Monitor, and then navigate to Window -> CPU Usage, the visual will pop up that looks like a bar graph. However many bars there are, that is how many cores you have.
On my machine, I have four, so I would run
make native -j 4
However, if you are unsure, just run
make native
This may take a while (on a kind-of-crap MacBook Pro, takes about 10 minutes).
6) Now, copy the hello world example below into a new file in the v8 folder (direct child of v8 folder) and save it as hello_world.cpp
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a new Isolate and make it the current one.
Isolate* isolate = Isolate::New();
Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
// Compile the source code.
Local<Script> script = Script::Compile(source);
// Run the script to get the result.
Local<Value> result = script->Run();
// Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result);
printf("%s\n", *utf8);
return 0;
}
In terminal,in the v8/ folder, run
clang++ -Iinclude out/native/libv8_base.a out/native/libv8_libbase.a out/native/libv8_snapshot.a out/native/libicudata.a out/native/libicuuc.a out/native/libicui18n.a hello_world.cpp -o hello_world
viola! You're now ready to start messing with v8!
Google's Getting Started Guide
Anyone has instructions for compiling against the
brew install v8
libs?