Build Systems
Ninja Build System
If Makefiles are the reliable old workhorse of C programming, Ninja is the modern bullet train.
What is Ninja?
Ninja is a small, incredibly fast build system with a single focus: Speed.
It was created by a developer at Google who was frustrated with how slow Make became when building the massive Google Chrome codebase.
While Make has tons of complex features (like string manipulation, conditionals, and implicit rules), Ninja strips all of that away. Ninja build files are almost unreadable by humans — they are designed to be generated by higher-level tools like CMake.
Why ESP-IDF Uses Ninja
When you run idf.py build on an ESP32 project, idf.py calls CMake, and CMake generates a build.ninja file. Then, Ninja does the actual compiling.
ESP-IDF chooses Ninja over Make for two main reasons:
- Instant Startup: When you tell
Maketo build a project with thousands of files, it can take 10–20 seconds just to figure out what needs to be compiled before it even starts compiling. Ninja does this analysis almost instantly. - Smart Parallelization: Ninja automatically detects how many CPU cores your computer has and runs compiler jobs in parallel to max out your CPU.
Make vs Ninja
| Feature | GNU Make | Ninja |
|---|---|---|
| Speed | Fast | Blazing Fast |
| Parallel Builds | Manual (e.g., make -j8) | Automatic (maxes out your CPU) |
| Syntax | Human-readable (mostly) | Machine-readable (generated) |
| Features | Complex scripting | Bare minimum for speed |
How to use Ninja Manually
If you are using CMake on a desktop project, you can easily tell it to generate Ninja files instead of Makefiles by passing the -G (Generator) flag.
# 1. Tell CMake to generate Ninja files instead of a Makefile
cmake -G Ninja ..
# 2. Run ninja to compile the code
ninja
If you ever look inside your ESP-IDF build/ folder, you won't find a Makefile. You will find a build.ninja file. This is the engine that compiles your firmware so quickly!

