From 1ac6fc0595f992621cbb79b7971ba07db1fa8e62 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 17 Feb 2022 01:02:25 -0500 Subject: [PATCH] intl dependency: include header when checking for libc builtin This header is required anyway. And the compile test for linking to libc with the gettext symbol, can succeed when we try to use the literal symbol name without includes, but fail later during project build, because actually including libintl.h might redefine the function to match a forked symbol. This happens when GNU libintl is installed as a standalone library on systems that have a less fully-featured gettext implementation. So, by including the header in has_function, we can ensure that we test against the default resolved header. In the event that the symbol which is #define'd by the header is 'libintl_gettext', linking will fail against libc even when a builtin gettext does exist, and we will fall back to the intl dependency that provides -lintl (and which is needed to properly use the default header). Of course, even that probably won't work. has_function(prefix: '...') is useless to check the difference between builtins and external library functions. It has code to detect "builtins" that misfires in some cases (previously seen with iconv_open). Instead compile an open-coded test file that this intl dependency implementation fully controls, that doesn't get up to imaginative edge cases like trying to find `__builtin_gettext`. It's the only way to be sure. Fixes compiling against the intl dependency on e.g. Alpine Linux when the libintl package is installed. --- mesonbuild/dependencies/misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index c76907769..9cc549c7c 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -490,8 +490,9 @@ class IconvSystemDependency(SystemDependency): class IntlBuiltinDependency(BuiltinDependency): def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): super().__init__(name, env, kwargs) + code = '''#include \n\nint main() {\n gettext("Hello world");\n}''' - if self.clib_compiler.has_function('ngettext', '', env)[0]: + if self.clib_compiler.links(code, env)[0]: self.is_found = True