Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions mesonbuild/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def find_tool(self, name: str, depname: str, varname: str, required: bool = True
return ExternalProgram.from_entry(name, prog_list)

# Check if pkgconfig has a variable
dep = self.dependency(depname, native=for_machine is MachineChoice.BUILD,
required=False, wanted=wanted)
dep = self.dependency(depname, native=True, required=False, wanted=wanted)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me, since now pkg-config will return a program targeting the build machine even when it's been explicitly requested to get one for the host machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way meson handles find_program, we can't rely on anything being the of the machine type we requested (a find_program with HOST will still end up falling to the system binaries and a one with BUILD will still pick a overridden one for the HOST). IMO this has to change, which is why I talked about replacing all use of native & for_machine with a T.Set[MachineChoice], but that clearly shouldn't be part of a rc bugfix.

The issue specifically is, that meson just passes the path pointed at by the pkg-config into ExternalProgram, which will simply assume that the executable pointed to by the path is executable by the build machine, which it may not if it comes from a HOST dependency.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is weird but it makes sense, a tool should preferrably be built for the build machine. You could have an extra argument support_cross: bool(*) and do native=support_cross or for_machine is MachineChoice.bool. But if support_cross is always true, one might as well write native=True.

(*) True if the output is machine-independent or can be tailored to an arbitrary machine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bonzini: Isn't that functionally the same as my proposed T.Set[MachineChoice]?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it as is, no problem for me.

if dep.found() and dep.type_name == 'pkgconfig':
value = dep.get_variable(pkgconfig=varname)
if value:
Expand Down
14 changes: 13 additions & 1 deletion mesonbuild/modules/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut
scan_command: T.List[T.Union[str, Executable, 'ExternalProgram', 'OverrideProgram']] = [giscanner]
scan_command += ['--quiet']

if state.environment.is_cross_build() and state.environment.need_exe_wrapper():
if state.environment.is_cross_build() and state.environment.need_exe_wrapper() and giscanner.for_machine is MachineChoice.BUILD:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here? There should never need to be an exe_wrapper for the build machine, the build machine is the machine that is natively running the compilation. the exe_wrapper is to allow the build machine to run binaries compiled for the host machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks if the giscanner is from the build machine (right now its a python script with a native module, so this should always be the case [but I plan to change that]).

The exe_wrapper check is to pass the --use-binary-wrapper ... --{begin,end}-binary-wrapper-args to the build machine g-ir-scanner if that is required. So meson invokes the g-ir-scanner on the build machine directly and it makes use of the exe_wrapper whenever it needs to itself internally.

if not state.environment.has_exe_wrapper():
mlog.error('generate_gir requires exe_wrapper')

Expand Down Expand Up @@ -1269,6 +1269,18 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[Execut
# We have to cast here because mypy can't figure this out
T.cast('T.Dict[str, T.Any]', kwargs))

# The g-ir-compiler must match the host architecture. If we have
# found a g-ir-compiler for the build machine (due to it being
# specified in the cross file or meson just falling back to the
# system g-ir-compiler), check if its command begins with
# the command for exe_wrapper, in which case assume that it is
# actually compiled for the host architecture.
if state.environment.is_cross_build() and state.environment.need_exe_wrapper() and gicompiler.for_machine is MachineChoice.BUILD:
binary_wrapper = state.environment.get_exe_wrapper().get_command()
if gicompiler.get_command()[:len(binary_wrapper)] != binary_wrapper:
msg = 'Architecture of g-ir-compiler must match the one of the host machine'
raise MesonException(msg)

typelib_output = f'{ns}-{nsversion}.typelib'
typelib_cmd = [gicompiler, scan_target, '--output', '@OUTPUT@']
typelib_cmd += state.get_include_args(gir_inc_dirs, prefix='--includedir=')
Expand Down
Loading