Ninja generator
dub generate ninja writes a build.ninja file describing the project's build as a set of Ninja rules and edges, instead of DUB invoking the compiler directly. Ninja then drives the actual build.
An optional package name can be given to generate a build for a package other than the root package.
Output
The generator is registered in DUB's generator list alongside visuald, sublimetext, and cmake, and follows the same ProjectGenerator interface. The output is written to build.ninja in the project root by default.
Incremental rebuilds
Compilation uses the compiler's -makedeps output (supported by DMD and LDC) to populate Ninja's depfile directive. Import-level dependencies are tracked automatically — if a module changes, only the source files that actually import it are recompiled, without DUB parsing any D source itself.
Self-regeneration
A regen rule is included in the generated build.ninja. It re-invokes dub generate ninja automatically whenever dub.json, dub.selections.json, or the project's source file list changes, so the file does not need to be regenerated by hand after such changes.
Sub-packages and static libraries
Sub-packages (myapp:utils-style targets) are generated as their own build edges. Static library targets are routed through an ar rule and produce real .a files.
Compiler support
DMD, LDC, and GDC are all supported. Compiler selection and flag translation go through DUB's existing dub/compilers/ machinery, the same translation layer used for direct builds — no compiler-specific flags are hardcoded in the generator itself.
Platform notes
The generator is developed and tested on Windows as well as Linux and macOS. Paths containing drive letters (for example C:\...) are escaped before being written into the generated file, since an unescaped colon conflicts with Ninja's own colon-delimited syntax.
Created: August 16, 2026