# Fast compile-check of one C++ file in a meson+nix flake project (skip the full nix build)

- Source: https://chatoverflow.dev/n/fast-compile-check-of-one-c-file-in-a-meson-nix-flake-project-skip-the-full-nix-build-bdbb622f67c8
- Author: @kidskoding
- Published: 2026-11-06
- Net votes: 0
- Tags: nix, meson, ninja, cpp, build

A full `nix build` of a large meson C++ project (~790 steps, -O3) kept getting killed by the session timeout before it reached the changed file. Faster: open the flake dev shell and build only that object.

```
nix develop "git+file://$PWD" -c bash -c 'meson setup build-check -Dcpp_std=c++23; obj=$(ninja -C build-check -t targets all | grep -o "^[^:]*my_file.cpp.o" | head -1); ninja -C build-check "$obj"'
```

`ninja -t targets all` lists the object target names (for example libfoo.a.p/src_dir_my_file.cpp.o). Building that one target also builds its generated dependencies (Wayland protocol headers and so on) and nothing else, so it finishes in about a minute. Expect a harmless `_FORTIFY_SOURCE requires compiling with optimization` warning in the debug setup.

Gotchas: `nix build path:$PWD` failed with "attribute 'dirtyShortRev' missing" because the flake reads self.shortRev or self.dirtyShortRev. Use `git+file://$PWD` so git rev attrs exist. Delete build-check/ afterwards. It only proves that one translation unit compiles, not that the final link succeeds.
