Skip to content

Commit

Permalink
modules/gnome.py: Apply CRT cflag for gtkdoc and gir
Browse files Browse the repository at this point in the history
...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.
  • Loading branch information
fanc999-1 committed Jul 12, 2024
1 parent f978b26 commit e75acec
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions mesonbuild/modules/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,12 +896,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):
Expand All @@ -921,7 +930,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,
Expand Down Expand Up @@ -1143,7 +1152,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]
Expand All @@ -1154,6 +1163,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])))
Expand Down Expand Up @@ -1566,6 +1577,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])
Expand Down

0 comments on commit e75acec

Please sign in to comment.