MCPcopy Index your code
hub / github.com/evmar/n2

github.com/evmar/n2 @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
412 symbols 1,311 edges 40 files 87 documented · 21%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

n2, an alternative ninja implementation

CI status

n2 (pronounced "into") implements enough of Ninja to successfully build some projects that build with Ninja. Compared to Ninja, n2 missing some features but is faster to build and has a better UI; see a more detailed comparison.

Here's a small demo of n2 building some of Clang.

Install

$ cargo install --locked --git https://github.com/evmar/n2
# (installs into ~/.cargo/bin/)
# On Windows, add `--features crlf` to support files with CRLF linefeeds --
# costs 10% in file parse time.

$ n2 -C some/build/dir some-target

Using with CMake

When CMake generates Ninja files it attempts run a program named ninja with some particular Ninja behaviors. In particular, it attempts to inform Ninja/n2 that its generated build files are up to date so that the build system doesn't attempt to rebuild them.

n2 can emulate the expected CMake behavior when invoked as ninja. To do this you create a symlink named ninja somewhere in your $PATH, such that CMake can discover it.

  • UNIX: ln -s path/to/n2 ninja
  • Windows(cmd): mklink ninja.exe path\to\n2
  • Windows(PowerShell): New-Item -Type Symlink ninja.exe -Target path\to\n2

Warning\ If you don't have Ninja installed at all, you must install such a symlink because CMake attempts to invoke ninja itself!

The console output

While building, n2 displays build progress like this:

[=========================---------       ] 2772/4459 done, 8/930 running
Building foo/bar (2s)
Building foo/baz

The progress bar always covers all build steps needed for the targets, regardless of whether they need to be executed or not.

The bar shows three categories of state:

  • Done: The = signs show the build steps that are already up to date.
  • In progress: The - signs show steps that are in-progress; if you had enough CPUs they would all be executing. The 8/930 running after shows that n2 is currently executing 8 of the 930 available steps.
  • Unknown: The remaining empty space indicates steps whose status is yet to be known, as they depend on the in progress steps. For example, if an intermediate step doesn't write its outputs n2 may not need to execute the dependent steps.

The lines below the progress bar show some build steps that are currrently running, along with how long they've been running if it has been a while. Their text is controlled by the input build.ninja file.

More reading

I wrote n2 to explore some alternative ideas I had around how to structure a build system. In a very real sense the exploration is more important than the actual software itself, so you can view the design notes as one of the primary artifacts of this.

Extension points exported contracts — how you extend this code

Env (Interface)
An environment providing a mapping of variable name to variable value. This represents one "frame" of evaluation context [5 …
src/eval.rs
Manifest (Interface)
A trait for computing a build's manifest. Indirected as a trait so we can implement it a second time for "-d explain" d [2 …
src/hash.rs
Progress (Interface)
Trait for build progress notifications. [2 implementers]
src/progress.rs
Index (Interface)
(no doc) [4 implementers]
src/densemap.rs

Core symbols most depended-on inside this repo

write
called by 79
tests/e2e/mod.rs
n2_command
called by 65
tests/e2e/mod.rs
run_expect
called by 60
tests/e2e/mod.rs
assert_output_contains
called by 54
tests/e2e/mod.rs
push
called by 36
src/densemap.rs
assert_canon_path_eq
called by 24
src/canon.rs
get
called by 23
src/eval.rs
iter
called by 21
src/smallmap.rs

Shape

Method 199
Function 146
Class 57
Enum 6
Interface 4

Languages

Rust100%
Python1%
C1%

Modules by API surface

src/graph.rs40 symbols
src/work.rs32 symbols
src/db.rs31 symbols
src/parse.rs28 symbols
src/task.rs21 symbols
src/progress_fancy.rs20 symbols
src/scanner.rs17 symbols
tests/e2e/mod.rs14 symbols
tests/e2e/basic.rs14 symbols
src/process_win.rs14 symbols
src/load.rs14 symbols
src/hash.rs14 symbols

For agents

$ claude mcp add n2 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact