Ninja build available for Visual Studio users

Building LLVM with Visual Studio is a bit of a pain because the
available methods are slow and doesn't make good use of multiprocessor
systems.

From now on it is possible to build LLVM+Clang with the usual cmake

method but using Ninja, an ultra-fast tool that knows how to take
advantage of the availabe execution threads. Ultra-fast is no
exageration: with a warm cache, a no-op build of LLVM is done in less
than half a second.

Rigth now Ninja/VS support is activated on a cmake experimental build,
with strong possibilities of making its way into the next official
release. For now, you need to build the patched cmake+ninja yourselves
or download the executables from

http://sourceforge.net/projects/cmakescript/files/

Download and install cmake-Ninja-2.8.8.*-win32-x86.exe, then download
ninja.exe to the `bin' subdirectory of the place where you installed
cmake. Then proceed to build LLVM:

mkdir myLLVMbuildWithNinja
cd myLLVMbuildWithNinja
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release path/to/llvm/source/root
ninja

(be sure to use the cmake you just installed, not the one you already
had on the system)

If you prefer to build cmake+ninja yourselves, read the thread

http://news.gmane.org/find-root.php?group=gmane.comp.programming.tools.cmake.devel&article=3903

(long, sorry) or ask on the cmake developer's mailing list for pointers,
as right now the exact sources are a bit of a moving target. If you find
bugs building LLVM or any other cmake-based project with ninja, please
report them on cmake's developers mailing list, available through gmane:

http://dir.gmane.org/gmane.comp.programming.tools.cmake.devel

or via e-mail:

http://www.cmake.org/mailman/listinfo/cmake-developers

About ninja:

http://martine.github.com/ninja/

Oops! Yes, that was intended to go to the list. This was the message for those of you interested:

Thanks for getting the word out about ninja!

I’ll add that with Cmake2.8, ninja build isn’t enabled by default on Mac due to things that don’t affect building LLVM. You’ll have to build CMake yourself (it’s easy), and pass it -DCMAKE_ENABLE_NINJA=ON when configuring. Then you’ll be able to build LLVM with ninja on mac!

Could somebody please provide more info. What exactly is ninja (I’m guessing it’s a build system) and how to set it up in combination with Visual Studio?

Nikola Smiljanic <popizdeh@gmail.com> writes:

Could somebody please provide more info. What exactly is ninja (I'm
guessing it's a build system) and how to set it up in combination with
Visual Studio?

This is the message I posted on the LLVM mailing list. Here it goes
again for the benefit of CLang'ers:

Building LLVM with Visual Studio is a bit of a pain because the
available methods are slow and doesn't make good use of multiprocessor
systems.

From now on it is possible to build LLVM+Clang with the usual cmake

method but using Ninja, an ultra-fast tool that knows how to take
advantage of the availabe execution threads. Ultra-fast is no
exageration: with a warm cache, a no-op build of LLVM is done in less
than half a second.

Rigth now Ninja/VS support is activated on a cmake experimental build,
with strong possibilities of making its way into the next official
release. For now, you need to build the patched cmake+ninja yourselves
or download the executables from

http://sourceforge.net/projects/cmakescript/files/

Download and install cmake-Ninja-2.8.8.*-win32-x86.exe, then download
ninja.exe to the `bin' subdirectory of the place where you installed
cmake. Then proceed to build LLVM:

mkdir myLLVMbuildWithNinja
cd myLLVMbuildWithNinja
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release path/to/llvm/source/root
ninja

(be sure to use the cmake you just installed, not the one you already
had on the system)

If you prefer to build cmake+ninja yourselves, read the thread

http://news.gmane.org/find-root.php?group=gmane.comp.programming.tools.cmake.devel&article=3903

(long, sorry) or ask on the cmake developer's mailing list for pointers,
as right now the exact sources are a bit of a moving target. If you find
bugs building LLVM or any other cmake-based project with ninja, please
report them on cmake's developers mailing list, available through gmane:

http://dir.gmane.org/gmane.comp.programming.tools.cmake.devel

or via e-mail:

http://www.cmake.org/mailman/listinfo/cmake-developers

About ninja:

http://martine.github.com/ninja/

Wow, this is seriously fast on Windows! I’ve been using Ninja on Linux/Mac for awhile now, I’m glad to see it working on Windows now.

Today was the first day that our Windows CMake dashboard using the Ninja generator had all of its tests passing. So… I just committed code to CMake to turn on the Ninja generator by default in Windows builds of CMake.

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2077e98753a505490d16cba42af0e0cae04f2c36

The upcoming 2.8.9 release of CMake should have these recent changes in them to make it easy to build CMake based projects with ninja.

Thanks,
David Cole
Kitware, Inc.

A tiny question (I hardly know what Ninja is, but am looking forward to trying it out): Does the changes also work with MinGW builds? I’ve got a Windows buildbot slave that does nothing but building LLVM+Clang using MinGW64 all day, every day. Or, is it only for Visual Studio?

2012/6/13 Justin Holewinski <justin.holewinski@gmail.com>

A tiny question (I hardly know what Ninja is, but am looking forward to trying it out): Does the changes also work with MinGW builds? I’ve got a Windows buildbot slave that does nothing but building LLVM+Clang using MinGW64 all day, every day. Or, is it only for Visual Studio?

I just tried a mingw64 build, and all was fine!

I’m probably doing something wrong here, but after running cmake -G Ninja all I get are some ninja build files. Typing ninja in the command line builds everything, but how do I integrate this with the IDE, it’s missing VS solution and projects?

I have a slightly off topic problem that is related to VS and CMake and this seems like a good time to ask for some help.

VS keeps complaining that some projects are out of date every time I start a debugging session.

I checkout llvm and clang
I run cmake -G Visual Studio 2010
I build all projects from the solution
I mark clang as the startup project

After I hit F5 I’m presented with a list of projects that are supposedly out of date.

I know that this problem is usually about cyclic dependencies or file time stamps that have changed (pre or post compile steps). I wrote a small python script to check for cycles but couldn’t find any. I couldn’t check my time stamp assumption since CMake is mostly magic to me :slight_smile:

I’ve talked to Francois about this and he says that he never had this problem. I even tried installing XP under VM to have a fresh start but the same thing happens.

Nikola Smiljanic <popizdeh@gmail.com> writes:

I'm probably doing something wrong here, but after running cmake -G Ninja
all I get are some ninja build files. Typing ninja in the command line
builds everything, but how do I integrate this with the IDE, it's missing
VS solution and projects?

Ninja is a build tool unrelated to VS. If you prefer VS project files to
build with VS use -G "Visual Studio blah blah".

So the Visual Studio part in the subject of this thread means that
Ninja can use msvc compiler, and has nothing to do with IDE?

I don't really care about building from VS as long as I can use it to
debug, but as far as I'm aware this is also tied to project files?

So the Visual Studio part in the subject of this thread means that
Ninja can use msvc compiler, and has nothing to do with IDE?

Yes, though you could quite easily create a VS project that invokes ninja as a custom build step.

I don’t really care about building from VS as long as I can use it to
debug, but as far as I’m aware this is also tied to project files?

You can setup the debugger for the wrapper project mentioned above if all you want is VS debugging. Or you could use WinDbg and friends.

FWIW, the same thing happens to me on two different machines (both
with VS 2010). I simply hit "no" when it asks me if I'd like to
rebuild, if I know the build is already up to date.

~Aaron

You can setup the debugger for the wrapper project mentioned above if all
you want is VS debugging.

What wrapper project?

Or you could use WinDbg and friends.

NOOOOoooooo!!!

You can setup the debugger for the wrapper project mentioned above if all
you want is VS debugging.

What wrapper project?

You can just create a blank project, and invoke ninja as a custom build step and set the executable you want to debug in the debugger options.

Nikola Smiljanic <popizdeh@gmail.com> writes:

So the Visual Studio part in the subject of this thread means that
Ninja can use msvc compiler, and has nothing to do with IDE?

Right.

I don't really care about building from VS as long as I can use it to
debug, but as far as I'm aware this is also tied to project files?

You can debug with the VS IDE without a project file. In the "Open
project/solution" dialog, simply open the executable.

This is off-topic, so let's stop the dicussion here.