Skip to main content

Module validate

Module validate 

Source
Expand description

Validate that a detected toolchain can run the commands the C++ backend emits.

The planner emits commands in one of two dialects - GCC/Clang-style or MSVC-style - chosen by the detected C++ compiler. The GCC/Clang shapes are:

  • C++ compile: cxx -std=<effective standard> -O… [-g] [-DNDEBUG] -MD -MF <depfile> -D<name> -I<dir> [-isystem <dir>] [extra-args] -c <src> -o <obj>.
  • Static-library archive: ar crs <lib> <objs>.
  • Link: cxx <objs> <libs> [extra-args] -o <exe>.

Any compiler / archiver that cannot run those exact shapes - or that lacks the flag for a requested language standard - is rejected up front rather than left to fail with a confusing Ninja error.

Structs§

RequestedStandards
The set of language standards a build’s compiles request, per language. A language’s set is empty iff no compile of that language exists, which is the signal the C-compiler checks key on.

Functions§

collect_requested_standards
Pre-plan approximation of requested_standards_of: walk every selected package’s targets and classify each declared source. Over-approximates per target (it cannot know which targets the plan will reach), so it must not gate validation - use it only for decisions needed before planning, like the MSVC /external:I fallback. Dev-only targets (test / example) contribute only for packages in dev_for, mirroring dev-dependency activation.
msvc_external_includes_supported
Whether every compiler that will run a compile in this build accepts the MSVC-dialect distinct system-include spelling (/external:W0 + /external:I <dir>). Mirrors validate_toolchain_for_backend’s contract for the optional cc slot: the C compiler only weighs in when a C source exists, because the planner never invokes it otherwise.
requested_standards_of
The exact standards a planned build requests: every compile action in the graph contributes its typed standard. This is the set validate_toolchain_for_backend should be called with - the planner has already narrowed targets to the requested selection, so a sibling target that is not built cannot gate the toolchain.
validate_planned_standards
Surface the first standards violation the planner recorded that survived into the final graph (after the cabin check rewrite, when applicable): an MSVC no-stable-flag compile or an escape-hatch flag conflict on a planned compile. Must run before anything is lowered or written; commands that skip the toolchain-validation pass (cabin tidy’s fail-soft path) must still call this so a violating compile cannot be silently dropped from the compile database.
validate_toolchain_for_backend
Validate that every populated tool in report can execute the command shapes emitted by the current backend. Returns the first problem encountered so users see one actionable error, not a wall of unrelated failures.
validate_toolchain_standards
Validate the plan-dependent half of the toolchain contract: every language standard in requested, plus - when the plan compiles C - the C compiler’s backend shape and dialect coherence. requested is derived from the final planned graph via requested_standards_of (after the cabin check rewrite when applicable), so only compiles the command will run participate: an unbuilt sibling target, an unrelated C executable in a dependency package, or a dependency compile that cabin check drops can never gate the build. Runs after plan() and before any Ninja file is written; the plan-independent C++/archiver shape checks in validate_toolchain_for_backend stay pre-plan so a broken toolchain still fails fast.