10x Editor: Ninja

10x is probably the fastest IDE to date. So it makes only sense to use it with the fastest build system, right?

There is already excellent documentation in form of the blog post that introduced 10x workspaces. Check it out if you run into problems!

tl;dr

10x editor workspace settings dialog with ninja options entered.
<Workspace>
	…
	<BuildCommand>ninja</BuildCommand>
	<RebuildCommand>ninja -t clean &amp;&amp; ninja</RebuildCommand>
	<BuildFileCommand>ninja &amp;&quot;$(BuildFile)&amp;&quot;^^</BuildFileCommand>
	<CleanCommand>ninja -t clean</CleanCommand>

Prerequisites

This article is about 10x, so I assume you wrote a proper build.ninja for your project and you have set up an empty workspace for your project.

Also, ninja must be in your PATH (but it should be trivial to do otherwise).

Build All

Go to Settings > Workspace Settings. In the Settings tab, under Build Command, enter ninja and save via OK.

Build > Build All should now produce an output like the following:

----- Build All Debug x86-WIN -----
Executing build command:
ninja
Working Directory: A:/project
[1/42] compiling "test file 1.cpp" ...
…
[42/42] compiling "test file 42.cpp" ...
===== Success : 0 errors, 0 warnings =====

So this command just calls ninja from within your project directory, where it looks for a build.ninja file and builds all targets.

Clean All

Ninja can remove all generated files using the clean extra tool. Under Clean Command, enter ninja -t clean and save via OK.

Click Build > Clean All:

----- Clean All Debug x86-WIN -----
Executing build command:
ninja -t clean
Working Directory: A:/project
Cleaning... 42 files.
===== Success : 0 errors, 0 warnings =====

Rebuild All

This combines Clean All with Build All. This requires some kind of shell. It seems 10x uses cmd.exe for build commands, so:

Rebuild Command   ninja -t clean && ninja

And indeed:

----- Rebuild Debug x86-WIN -----
Executing build command:
ninja -t clean && ninja
Working Directory: A:/project
Cleaning... 42 files.
[1/42] compiling "test file 1.cpp" ...
…
[42/42] compiling "test file 42.cpp" ...
===== Success : 0 errors, 0 warnings =====

Build Individual File

This is a bit more tricky. First of all, how do you know what the current source file is? Under Substitutions at the bottom of the dialog, 10x reveals that the current file path is stored in the variable $(BuildFile).

But ninja cannot build files. It builds targets. In this case, the target you’d like to see built is the object file corresponding to the current source file. If your build is simple, it might be as easy as adding .o to the name. For out-of-source-builds, it’s very complicated.

Luckily, the ninja manual points out:

There is also a special syntax target^ for specifying a target as the first output of some rule containing the source you put in the command line, if one exists. For example, if you specify target as foo.c^ then foo.o will get built (assuming you have those targets in your build files).

This is exactly what’s needed here!

However, 10x uses cmd.exe to run the command, and ^ is a special character. It must be properly escaped by using ^^ instead!

Finally, 10x does not enclose $(BuildFile) in quotes if the path contains spaces, so add those too:

Build File Command   ninja "$(BuildFile)"^^

Open a file from your project (optimally one with spaces in its path) and click Build Current File or hit Ctrl+F7:

----- BuildFile Debug x86-WIN -----
Executing build command:
ninja.exe "test file.cpp"^^
Working Directory: A:/project
[1/42] compiling "test file 1.cpp" ...
…
[42/42] compiling "test file 42.cpp" ...
===== Success : 0 errors, 0 warnings =====