|
| 1 | +# Building Node with Ninja |
| 2 | + |
| 3 | +The purpose of this guide is to show how to build Node.js using [Ninja][], as doing so can be significantly quicker than using `make`. Please see [Ninja's site][Ninja] for installation instructions (unix only). |
| 4 | + |
| 5 | +To build Node with ninja, there are 4 steps that must be taken: |
| 6 | + |
| 7 | +1. Configure the project's OS-based build rules via `./configure` as usual. |
| 8 | +2. Use `tools/gyp_node.py -f ninja` to produce Ninja-buildable `gyp` output. |
| 9 | +3. Run `ninja -C out/Release` to produce a compiled release binary. |
| 10 | +4. Lastly, make symlink to `./node` using `ln -fs out/Release/node node`. |
| 11 | + |
| 12 | +When running `ninja -C out/Release` you will see output similar to the following if the build has succeeded: |
| 13 | +``` |
| 14 | +ninja: Entering directory `out/Release` |
| 15 | +[4/4] LINK node, POSTBUILDS |
| 16 | +``` |
| 17 | + |
| 18 | +The bottom line will change while building, showing the progress as `[finished/total]` build steps. |
| 19 | +This is useful output that `make` does not produce and is one of the benefits of using Ninja. |
| 20 | +Also, Ninja will likely compile much faster than even `make -j8` (or `-j<number of processor threads on your machine>`). |
| 21 | + |
| 22 | +## Considerations |
| 23 | + |
| 24 | +Ninja builds vary slightly from `make` builds. If you wish to run `make test` after, `make` will likely still need to rebuild some amount of Node. |
| 25 | + |
| 26 | +As such, if you wish to run the tests, it can be helpful to invoke the test runner directly, like so: |
| 27 | +`tools/test.py --mode=release message parallel sequential -J` |
| 28 | + |
| 29 | +## Alias |
| 30 | + |
| 31 | +`alias nnode='./configure && tools/gyp_node.py -f ninja && ninja -C out/Release && ln -fs out/Release/node node'` |
| 32 | + |
| 33 | +## Producing a debug build |
| 34 | + |
| 35 | +The above alias can be modified slightly to produce a debug build, rather than a release build as shown below: |
| 36 | +`alias nnodedebug='./configure && tools/gyp_node.py -f ninja && ninja -C out/Debug && ln -fs out/Debug/node node_g'` |
| 37 | + |
| 38 | + |
| 39 | +[Ninja]: https://martine.github.io/ninja/ |
0 commit comments