This document describes how to build and run GraalVM JavaScript.
Building yourself should only be necessary if you are contributing to GraalVM JavaScript or you want to try out the latest features. The average user will prefer the pre-built binaries as part of GraalVM or the GraalVM JavaScript JAR files published to Maven (see blog post).
- Python 3.8+ (required by
mx) - git (to download, update, and locate repositories)
- Java JDK 11 or newer
Building the Node.js support is optional, and requires additional tools, see futher below.
-
to build GraalVM JavaScript from sources you need to clone several repositories, at least
graaljs,mxandgraal. We recommend to put them in a dedicated directory:mkdir graalvm cd graalvm -
clone
mxand add it to yourPATH:git clone https://github.com/graalvm/mx.git export PATH=$PWD/mx:$PATHYou can put
mxin yourgraalvmfolder, but anywhere else in the system is fine as you are putting it on thePATHanyway. -
clone the
graaljsrepository and enter it:git clone https://github.com/graalvm/graaljs.git cd graaljs/graal-jsNote that the
graaljsrepository contains two so-called suites:graal-js(the core JavaScript engine) andgraal-nodejs(the Node.js project modified so it uses GraalVM JavaScript as JavaScript engine). For the further steps you need to be in either of those directories (we assume you cd'ed to thegraal-jsdirectory). -
setup your environment:
- assuming you build with JDK11 or newer:
export JAVA_HOME=[path to JDK11+]
- assuming you build with JDK11 or newer:
-
(optional) clone or update the dependent repositories:
mx sforceimports
This will update the
graalrepository, where different required projects (truffle,sdk,regex) are found - or download it when no checkout of the repository can be found in thegraalvmdirectory. The GraalVM compiler (found ingraal/compiler/) is not required to build GraalVM JavaScript, but is used to execute it with high performance (see below). This step is marked as optional, as the following step (mx build) will automatically clone missing repositories, for instance, when you first build GraalVM JavaScript. However,mx buildwon't update dependencies if they already exist, so runningmx sforceimportsis a safe bet and guarantees you are using the right commits of dependent repositories. -
build:
mx build
-
set up projects for your IDE:
mx ideinit
For future updates, you will want to git pull in the graaljs repository, then call mx sforceimports (in graalvm/graaljs/graal-js) to update the graal repository, and then (again in the graal-js suite) call mx build && mx ideinit to build and update the IDE configuration.
After cloning all required repositories, a possible directory structure could look similar to the following pattern (the first level is the project directory, on the second level are the repositories, on the third level are the suites and additional directories of the repositories):
graalvm
├── graal
| ├── compiler
| ├── regex
| ├── sdk
| ├── truffle
| `── (some more directories here)
├── graaljs
| ├── graal-js
| ├── graal-nodejs
| `── docs
`── mxThe main requirement here is that mx is on the PATH and that the two repositories graaljs and graal are checked out as sibling directories.
To start the GraalVM JavaScript command line interpreter or run a JavaScript file:
cd graaljs/graal-js
mx js [OPTION]... [FILE]...Assuming that you also built the GraalVM compiler (using the instructions in graal/compiler/README.md), here is how you can use it to run GraalVM JavaScript:
cd graaljs/graal-js
mx --dynamicimports /compiler js [OPTION]... [FILE]...Here we describe how to build and run Node.js on GraalVM JavaScript.
- the same as for GraalVM JavaScript
- for building Node.js, the requirements according to the Node.js documentation are:
gccandg++6.3 or newer, or- on macOS: Xcode Command Line Tools version 8 or newer
- GNU Make 3.81 or newer
- Note, that for the GraalVM JavaScript integration of Node.js, some parts of the whole Node.js ecosystem needs not be built, relaxing those requirements. Most prominently, the V8 JavaScript engine is not built in that case. We are successfully building GraalVM+Node.js currently with
gcc version 4.9.4.
To build both GraalVM JavaScript and Node.js:
cd graaljs/graal-nodejs
mx buildTo start the Node.js command line interpreter or run a Node.js file:
cd graaljs/graal-nodejs
mx node [OPTION]... [FILE]...Assuming that you also built the GraalVM Compiler (using the instructions in graal/compiler/README.md), here is how you can use it to run Node.js on GraalVM JavaScript:
cd graaljs/graal-nodejs
mx --dynamicimports /compiler node [OPTION]... [FILE]...-
mx sforceimportsclones thegraalrepository next tograaljs(step 5 above) -
if you already cloned
graaljs, you can update to a newer version ofgraalby running:cd graaljs git pull cd graal-js # or "graal-nodejs" mx sforceimports # updates the "graal" repository to the version imported by the current suite mx build
-
GraalVM JavaScript depends on
truffle,sdk, andregexprovided in thegraalrepository. There is no need to build code from this repository, this is done automatically when you build GraalVM JavaScript withmx build -
to print the help message of both GraalVM JavaScript and Node.js on GraalVM JavaScript, pass the
--helpoption:
cd graaljs/graal-js
mx js --help