]> git.ipfire.org Git - thirdparty/git.git/commit
meson: distinguish build and target host binaries
authorPatrick Steinhardt <ps@pks.im>
Mon, 31 Mar 2025 08:33:10 +0000 (10:33 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Apr 2025 09:20:44 +0000 (02:20 -0700)
commit23633466dfe32f0dac06d89ffd8867d248396111
treeb1a976645701466136783bab6a0972f41fadae67
parentbdd04b91c3492142dde585a763ad923c3aefbc7b
meson: distinguish build and target host binaries

Almost all of the tools we discover during the build process need to be
native programs. There are only a handful of exceptions, which typically
are programs whose paths we need to embed into the resulting executable
so that they can be found on the target system when Git executes. While
this distinction typically doesn't matter, it does start to matter when
considering cross-compilation where the build and target machines are
different.

Meson supports cross-compilation via so-called machine files. These
machine files allow the user to override parameters for the build
machine, but also for the target machine when cross-compiling. Part of
the machine file is a section that allows the user to override the
location where binaries are to be found in the target system. The
following machine file would for example override the path of the POSIX
shell:

    [binaries]
    sh = '/usr/xpg4/bin/sh'

It can be handed over to Meson via `meson setup --cross-file`.

We do not handle this correctly right now though because we don't know
to distinguish binaries for the build and target hosts at all. Address
this by explicitly passing the `native:` parameter to `find_program()`:

  - When set to `true`, we get binaries discovered on the build host.

  - When set to `false`, we get either the path specified in the
    machine file. Or, if no machine file exists or it doesn't specify
    the binary path, then we fall back to the binary discovered on the
    build host.

As mentioned, only a handful of binaries are not native: only the system
shell, Python and Perl need to be treated specially here.

Reported-by: Peter Seiderer <ps.report@gmx.net>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/meson.build
gitweb/meson.build
meson.build
templates/meson.build