From 797decc3e47823c8ae49db421597a5affd0810ad Mon Sep 17 00:00:00 2001 From: Princeton Ferro Date: Fri, 3 Apr 2026 04:15:59 -0700 Subject: [PATCH] compilers: pass external args to sanity check; add #include Two improvements so the compiler sanity check exercises the same code paths as cc.links(): 1. Compiler._sanity_check_compile_args (the base class) now passes get_external_args() and get_external_link_args() to the probe, just as build_wrapper_args() does. CLikeCompiler already did this via _get_basic_compiler_args(); the base class fix extends it to non-CLike compilers (Fortran, Swift, etc.). Duplicates in the CLike path are harmless because arglist deduplicates them. 2. CCompiler and CPPCompiler sanity check sources now include . This ensures that a broken or missing include path is caught at compiler detection time with a natural compiler error, rather than surfacing later as a cryptic Meson exception. --- mesonbuild/compilers/c.py | 2 +- mesonbuild/compilers/compilers.py | 4 +++- mesonbuild/compilers/cpp.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 2bff42b1d..a478c7961 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -75,7 +75,7 @@ class CCompiler(CLikeCompiler, Compiler): return ['-nostdinc'] def _sanity_check_source_code(self) -> str: - return 'int main(void) { int class=0; return class; }\n' + return '#include \nint main(void) { int class=0; return class; }\n' def has_header_symbol(self, hname: str, symbol: str, prefix: str, *, extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None, diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 2652a7f5e..deafa3eea 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1366,7 +1366,9 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): :return: a tuple of arguments, the first is the executable and compiler arguments, the second is linker arguments """ - return self.exelist_no_ccache + self.get_always_args() + self.get_output_args(binname) + [sourcename], [] + cargs = list(self.environment.coredata.get_external_args(self.for_machine, self.language)) + largs = list(self.environment.coredata.get_external_link_args(self.for_machine, self.language)) + return self.exelist_no_ccache + self.get_always_args() + self.get_output_args(binname) + [sourcename] + cargs, largs @abc.abstractmethod def _sanity_check_source_code(self) -> str: diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 21614f2c9..7718f5017 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -89,7 +89,7 @@ class CPPCompiler(CLikeCompiler, Compiler): return [] def _sanity_check_source_code(self) -> str: - return 'class breakCCompiler;int main(void) { return 0; }\n' + return '#include \nclass breakCCompiler;int main(void) { return 0; }\n' def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: # -fpermissive allows non-conforming code to compile which is necessary