From eef7a2a1d36113ef0a95865f3a7a1548ae9ad771 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 5 Jul 2024 19:21:52 +0800 Subject: [PATCH] modules/gnome.py: Apply CRT cflag for gtkdoc and gir ...when a Visual Studio-style compiler is being used. The scanner and dumper programs for gtkdoc and introspection will fail to link with an obscure undefined symbol '_guard_check_icall_$fo$' without an appropriate CRT cflag (i.e. /MD or /MDd for instance) specified, when the latest Windows SDK (10.0.26100.0 or later) is being used on Visual Studio 2019 at least. This will update the private _get_langs_compilers_flags() if a Visual Studio style compiler is being used, as indicated by the b_vscrt option. This applies the appropriate CRT cflag according to the build options so that this issue will be avoided. --- mesonbuild/modules/gnome.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e0c1214d0851..70d2e493dc53 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -899,12 +899,21 @@ def _get_gir_targets_inc_dirs(girtargets: T.Sequence[build.BuildTarget]) -> Orde @staticmethod def _get_langs_compilers_flags(state: 'ModuleState', langs_compilers: T.List[T.Tuple[str, 'Compiler']] - ) -> T.Tuple[T.List[str], T.List[str], T.List[str]]: + ) -> T.Tuple[T.List[str], T.List[str], T.List[str], T.List[str]]: cflags: T.List[str] = [] internal_ldflags: T.List[str] = [] external_ldflags: T.List[str] = [] + crt_cflags: T.List[str] = [] for lang, compiler in langs_compilers: + if len(crt_cflags) == 0 and OptionKey('b_vscrt') in compiler.base_options: + # For the latest Windows SDK 10.0.26100.0+, we must specify a CRT cflag (/MD or /MDd for instance), + # otherwise the scanner program will fail to link with an obscure undefined symbol + # _guard_check_icall_$fo$ + crt_val = state.environment.coredata.get_option(OptionKey('b_vscrt')) + buildtype = state.environment.coredata.get_option(OptionKey('buildtype')) + if isinstance(crt_val, str) and isinstance(buildtype, str): + crt_cflags = compiler.get_crt_compile_args(crt_val, buildtype) if state.global_args.get(lang): cflags += state.global_args[lang] if state.project_args.get(lang): @@ -924,7 +933,7 @@ def _get_langs_compilers_flags(state: 'ModuleState', langs_compilers: T.List[T.T # does not understand -f LDFLAGS. https://bugzilla.gnome.org/show_bug.cgi?id=783892 # ldflags += compiler.sanitizer_link_args(sanitize) - return cflags, internal_ldflags, external_ldflags + return cflags, internal_ldflags, external_ldflags, crt_cflags @staticmethod def _make_gir_filelist(state: 'ModuleState', srcdir: str, ns: str, @@ -1146,7 +1155,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut depends.extend(girtargets) langs_compilers = self._get_girtargets_langs_compilers(girtargets) - cflags, internal_ldflags, external_ldflags = self._get_langs_compilers_flags(state, langs_compilers) + cflags, internal_ldflags, external_ldflags, crt_cflags = self._get_langs_compilers_flags(state, langs_compilers) deps = self._get_gir_targets_deps(girtargets) deps += kwargs['dependencies'] deps += [gir_dep] @@ -1157,6 +1166,8 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut dep_cflags, dep_internal_ldflags, dep_external_ldflags, gi_includes, depends = \ self._get_dependencies_flags(deps, state, depends, use_gir_args=True) scan_cflags = [] + if len(crt_cflags) > 0: + scan_cflags += list(crt_cflags) scan_cflags += list(self._get_scanner_cflags(cflags)) scan_cflags += list(self._get_scanner_cflags(dep_cflags)) scan_cflags += list(self._get_scanner_cflags(self._get_external_args_for_langs(state, [lc[0] for lc in langs_compilers]))) @@ -1572,6 +1583,8 @@ def _get_build_args(self, c_args: T.List[str], inc_dirs: T.List[T.Union[str, bui compiler = state.environment.coredata.compilers[MachineChoice.HOST]['c'] compiler_flags = self._get_langs_compilers_flags(state, [('c', compiler)]) + if len(compiler_flags[3]) > 0: + cflags.extend(compiler_flags[3]) # Apply CRT cflag first if necessary cflags.extend(compiler_flags[0]) ldflags.extend(compiler_flags[1]) ldflags.extend(compiler_flags[2])