From b05ecce32568799e633357bb265b8690d1b8cbc3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 25 Sep 2024 10:28:37 -0700 Subject: [PATCH] compilers: Check if GCC has support for ObjC and/or ObjC++ Since this is optional, we should not accept that GCC is a valid ObjC or G++ is a valid ObjC++ Compiler unless we've tested that they can actually do a basic compile. --- mesonbuild/compilers/detect.py | 6 +++++- unittests/machinefiletests.py | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index 41ecf25288a7..8cb9acd9200f 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -877,9 +877,13 @@ def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine: version = _get_gnu_version_from_defines(defines) comp = objc.GnuObjCCompiler if lang == 'objc' else objcpp.GnuObjCPPCompiler linker = guess_nix_linker(env, compiler, comp, version, for_machine) - return comp( + c = comp( ccache, compiler, version, for_machine, is_cross, info, defines, linker=linker) + if not c.compiles('int main(void) { return 0; }', env)[0]: + popen_exceptions[join_args(compiler)] = f'GCC was not built with support for {"objective-c" if lang == "objc" else "objective-c++"}' + continue + return c if 'clang' in out: linker = None defines = _get_clang_compiler_defines(compiler, lang) diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py index ba9cb11530dd..99c2701e7dd5 100644 --- a/unittests/machinefiletests.py +++ b/unittests/machinefiletests.py @@ -23,7 +23,7 @@ import mesonbuild.environment import mesonbuild.coredata import mesonbuild.modules.gnome - +from mesonbuild import mesonlib from mesonbuild import machinefile from mesonbuild.mesonlib import ( @@ -275,7 +275,12 @@ def cb(comp): if not is_real_gnu_compiler(shutil.which('gcc')): raise SkipTest('Only one compiler found, cannot test.') return 'gcc', 'gcc' - self.helper_for_compiler('objc', cb) + try: + self.helper_for_compiler('objc', cb) + except mesonlib.EnvironmentException as e: + if 'GCC was not built with support for objective-c' in str(e): + raise unittest.SkipTest("GCC doesn't support objective-c, test cannot run") + raise @skip_if_not_language('objcpp') @skip_if_env_set('OBJCXX') @@ -288,7 +293,12 @@ def cb(comp): if not is_real_gnu_compiler(shutil.which('g++')): raise SkipTest('Only one compiler found, cannot test.') return 'g++', 'gcc' - self.helper_for_compiler('objcpp', cb) + try: + self.helper_for_compiler('objcpp', cb) + except mesonlib.EnvironmentException as e: + if 'GCC was not built with support for objective-c++' in str(e): + raise unittest.SkipTest("G++ doesn't support objective-c++, test cannot run") + raise @skip_if_not_language('d') @skip_if_env_set('DC')