ninjabackend: pass external {c,cpp}_args to detect_vs_dep_prefix probe

detect_vs_dep_prefix() runs cl.exe /showIncludes /c incdetect.c with no
include paths.  When the INCLUDE environment variable is not set — for
example when using a bundled MSVC toolchain outside a VS Developer Shell
— cl.exe cannot locate stdio.h and Meson raises:

  Could not determine vs dep dependency prefix string

The fix is to also pass the compiler's external args (c_args / cpp_args
from a native or cross file) to the probe subprocess.  This picks up
any user-defined include flags, enabling hermetic builds where all
headers are specified explicitly rather than via environment variables.
This commit is contained in:
Princeton Ferro
2026-03-31 01:30:16 -07:00
committed by Paolo Bonzini
parent 755dbc2dd7
commit c238c65b3f

View File

@@ -564,8 +564,15 @@ class NinjaBackend(backends.Backend):
# and locale dependent. Any attempt at converting it to
# Python strings leads to failure. We _must_ do this detection
# in raw byte mode and write the result in raw bytes.
#
# Pass the compiler's external args (e.g. -I flags from c_args /
# cpp_args in a native file) so that cl.exe can locate system headers
# even when the INCLUDE environment variable is not set — for example,
# when using a bundled MSVC toolchain outside a VS Developer Shell.
extra_args = self.environment.coredata.get_external_args(
MachineChoice.HOST, compiler.language)
pc = subprocess.Popen(compiler.get_exelist() +
['/showIncludes', '/c', filebase],
['/showIncludes', '/c', filebase] + extra_args,
cwd=self.environment.get_scratch_dir(),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = pc.communicate()