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()