Skip to content

Commit

Permalink
doc: add "building node with ninja" guide
Browse files Browse the repository at this point in the history
PR-URL: #4767
Refs: nodejs/docs#38
Reviewed-By: Bryan English <[email protected]>
Reviewed-By: Stephan Belanger <[email protected]>
  • Loading branch information
Fishrock123 committed Feb 23, 2016
1 parent 10f55b0 commit 65c0feb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions doc/guides/building-node-with-ninja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Building Node with Ninja

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).

To build Node with ninja, there are 4 steps that must be taken:

1. Configure the project's OS-based build rules via `./configure` as usual.
2. Use `tools/gyp_node.py -f ninja` to produce Ninja-buildable `gyp` output.
3. Run `ninja -C out/Release` to produce a compiled release binary.
4. Lastly, make symlink to `./node` using `ln -fs out/Release/node node`.

When running `ninja -C out/Release` you will see output similar to the following if the build has succeeded:
```
ninja: Entering directory `out/Release`
[4/4] LINK node, POSTBUILDS
```

The bottom line will change while building, showing the progress as `[finished/total]` build steps.
This is useful output that `make` does not produce and is one of the benefits of using Ninja.
Also, Ninja will likely compile much faster than even `make -j8` (or `-j<number of processor threads on your machine>`).

## Considerations

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.

As such, if you wish to run the tests, it can be helpful to invoke the test runner directly, like so:
`tools/test.py --mode=release message parallel sequential -J`

## Alias

`alias nnode='./configure && tools/gyp_node.py -f ninja && ninja -C out/Release && ln -fs out/Release/node node'`

## Producing a debug build

The above alias can be modified slightly to produce a debug build, rather than a release build as shown below:
`alias nnodedebug='./configure && tools/gyp_node.py -f ninja && ninja -C out/Debug && ln -fs out/Debug/node node_g'`


[Ninja]: https://martine.github.io/ninja/

8 comments on commit 65c0feb

@sam-github
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @Fishrock123, does this still work? I just tried, I'm experimenting with ways to speed up my build, but there were refs to libs in the wrong place in the link stage, such as libv8_base.a being at top level of out/Release.

@Fishrock123
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. I actually have not used this in a little bit. Let me check.

@Fishrock123
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sam-github Worked fine for me?

@sam-github
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, you on OS X? I'm on Ubuntu, with ninja 1.5.1. I tried twice, second time from a git clean -x -d. Its nbd, I started using ccache, and my build times are often a minute or two now, which is freaking awesome. Also, I was using ccache and ninja, maybe that was my issue (but I'm not giving up ccache for ninja).

@kenany
Copy link
Contributor

@kenany kenany commented on 65c0feb Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sam-github FWIW, I've also been seeing the same thing on Linux, with [email protected] and [email protected]. I ran a git bisect and it reported that e03a7b2 was the first commit wherein that error begins occurring. Unfortunately I'm not familiar enough with this stuff to figure out a patch to fix this.

for others, the error is:

$ ./configure && tools/gyp_node.py -f ninja && ninja -C out/Release

...

[2248/2248] LINK node
FAILED: node 
ccache g++ -pthread -rdynamic -m64 -Wl,--whole-archive,obj.target/deps/openssl/libopenssl.a -Wl,--no-whole-archive -Wl,-z,noexecstack -Wl,--whole-archive libv8_base.a -Wl,--no-whole-archive -pthread -o node -Wl,--start-group obj/src/node.debug-agent.o obj/src/node.async-wrap.o obj/src/node.env.o obj/src/node.fs_event_wrap.o obj/src/node.cares_wrap.o obj/src/node.connection_wrap.o obj/src/node.connect_wrap.o obj/src/node.handle_wrap.o obj/src/node.js_stream.o obj/src/node.node.o obj/src/node.node_buffer.o obj/src/node.node_config.o obj/src/node.node_constants.o obj/src/node.node_contextify.o obj/src/node.node_file.o obj/src/node.node_http_parser.o obj/src/node.node_javascript.o obj/src/node.node_main.o obj/src/node.node_os.o obj/src/node.node_revert.o obj/src/node.node_url.o obj/src/node.node_util.o obj/src/node.node_v8.o obj/src/node.node_stat_watcher.o obj/src/node.node_watchdog.o obj/src/node.node_zlib.o obj/src/node.node_i18n.o obj/src/node.pipe_wrap.o obj/src/node.signal_wrap.o obj/src/node.spawn_sync.o obj/src/node.string_bytes.o obj/src/node.stream_base.o obj/src/node.stream_wrap.o obj/src/node.tcp_wrap.o obj/src/node.timer_wrap.o obj/src/node.tty_wrap.o obj/src/node.process_wrap.o obj/src/node.udp_wrap.o obj/src/node.uv.o obj/src/node.util.o obj/src/node.string_search.o obj/src/node.inspector_agent.o obj/src/node.inspector_socket.o obj/src/node.node_crypto.o obj/src/node.node_crypto_bio.o obj/src/node.node_crypto_clienthello.o obj/src/node.tls_wrap.o obj/src/node.backtrace_posix.o obj/deps/v8/src/libv8_libplatform.a obj/tools/icu/libicui18n.a obj/deps/v8_inspector/src/inspector/libstandalone_inspector.a obj/deps/openssl/libopenssl.a obj/deps/zlib/libzlib.a obj/deps/http_parser/libhttp_parser.a obj/deps/cares/libcares.a obj/deps/uv/libuv.a obj/deps/v8/src/libv8_base.a obj/deps/v8/src/libv8_libbase.a obj/deps/v8/src/libv8_libsampler.a obj/tools/icu/libicuucx.a obj/tools/icu/libicudata.a obj/tools/icu/libicustubdata.a obj/deps/v8/src/libv8_snapshot.a -Wl,--end-group  -ldl -lrt -lm
g++: error: libv8_base.a: No such file or directory
ninja: build stopped: subcommand failed.

@sam-github
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I saw, and its accurate, obj/deps/v8/src/libv8_base.a is where the lib is, not at the top level.

@gibfahn
Copy link
Member

@gibfahn gibfahn commented on 65c0feb Nov 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised an issue: #9861

@Fishrock123
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I responded on that issue. I'm running it fine on OS X 10.10.5

Please sign in to comment.