From c238c65b3f42f9232c0dd129dc52463eac6e92bb Mon Sep 17 00:00:00 2001 From: Princeton Ferro Date: Tue, 31 Mar 2026 01:30:16 -0700 Subject: [PATCH] ninjabackend: pass external {c,cpp}_args to detect_vs_dep_prefix probe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- mesonbuild/backend/ninjabackend.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index b8994f8c8..1b5a0162f 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -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()