git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Peter Seiderer <ps.report@gmx.net>
Cc: git@vger.kernel.org, Eli Schwartz <eschwartz@gentoo.org>
Subject: Re: Meson build leaks host 'sh' path to target build when cross-compiled
Date: Tue, 18 Feb 2025 12:47:10 +0100	[thread overview]
Message-ID: <Z7RzPkiBfbYPhKp_@pks.im> (raw)
In-Reply-To: <20250210122603.5130e309@gmx.net>

On Mon, Feb 10, 2025 at 12:26:03PM +0100, Peter Seiderer wrote:
> On Mon, 10 Feb 2025 08:41:18 +0100, Patrick Steinhardt <ps@pks.im> wrote:
> > On Sun, Feb 09, 2025 at 01:30:27PM +0100, Peter Seiderer wrote:
> > [snip]
> > >   The meson build tries to execute the non-existent '/usr/bin/sh' (instead of
> > >   '/bin/sh' as the autoconf build), 'which sh' on the host returns
> > >   '/usr/bin/sh'...
> > >
> > >   From meson.build
> > >
> > >    [...]
> > >    186 shell = find_program('sh', dirs: program_path)
> > >    [...]
> > >    685   '-DSHELL_PATH="' + fs.as_posix(shell.full_path()) + '"',
> > >
> > >   Do not use the result of 'find_program('sh',...)' for '-DSHELL_PATH='
> > >   (at least not for cross-compile), use fix '/bin/sh' instead or make it
> > >   configurable via a meson option?
> >
> > Hm, very true. We're mixing up concerns here by treating the build
> > environment and the target environment the same.
> >
> > I guess the proper fix is to wire up the "native:" parameter when we
> > call `find_program()`, which allows us to tell Meson whether it should
> > find an executable for the build or the target host. And then, for those
> > binaries where we actually need to know about both the build and target
> > host's locations, we'd end up calling `find_program()` twice.
> >
> > For executables that are supposed to be used on the target host Meson
> > would then know to first consult the cross file, which could look like
> > this:
> >
> >     [binaries]
> >     sh = '/target/path/to/sh'
> >     perl = '/target/path/to/perl'
> >
> > Meson would then pick up that file via `meson setup --cross-file
> > <CROSSFILE_PATH> <BUILDDIR>`.
> 
> Sorry, I believe this will not work..., the description of the native
> parameter in find_program ([2]) on the first sight sounds like doing the
> right thing, but as far as I read the 'Cross compilation' page ([3], [4]) the
> tools under the '[binaries]' section are the tools used while cross-compiling
> (running on the build machine) and not the paths/tools on the target
> (or as meson nomenclature host/target)...

Quoting the documentation of `find_program()`'s `native` parameter [1]:

    Defines how this executable should be searched. By default it is set to
    false, which causes Meson to first look for the executable in the cross
    file (when cross building) and if it is not defined there, then from the
    system. If set to true, the cross file is ignored and the program is
    only searched from the system.

So I think this should work as expected when passing the file via
`--cross-file`, shouldn't it? If we are cross-compiling we'd find the
target binaries via the cross file when `native: false`, which is
exactly what we want.

But I see what you're saying. The _intent_ is to specify the environment
of the cross-compiling environment, and not to describe the target
environment.

I can think of two alternatives:

  - We can introduce build options for this. If unset, we continue to
    use the result of `find_program()`. Otherwise, we use the value
    specified by the user.

  - We can introduce properties into the cross file that allow the user
    to specify those parameters. We can then retrieve them by calling
    `meson.get_external_property()`, but only when cross-compiling.

Let me also Cc Eli, he might have an opinion on how to do this.

> > diff --git a/templates/meson.build b/templates/meson.build
> > index 1faf9a44ce..986c2e03be 100644
> > --- a/templates/meson.build
> > +++ b/templates/meson.build
> > @@ -1,6 +1,6 @@
> >  template_config = configuration_data()
> > -template_config.set('PERL_PATH', perl.found() ? fs.as_posix(perl.full_path()) : '')
> > -template_config.set('SHELL_PATH', fs.as_posix(shell.full_path()))
> > +template_config.set('PERL_PATH', perl.found() ? fs.as_posix(target_perl.full_path()) : '')
> 
> Above should read (perl.found() vs. target_perl.found()):
> 
>    +template_config.set('PERL_PATH', target_perl.found() ? fs.as_posix(target_perl.full_path()) : '')

Ah, yes, indeed.

Patrick

[1]: https://mesonbuild.com/Reference-manual_functions.html#find_program

  reply	other threads:[~2025-02-18 11:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-09 12:30 Meson build leaks host 'sh' path to target build when cross-compiled Peter Seiderer
2025-02-10  7:41 ` Patrick Steinhardt
2025-02-10 11:26   ` Peter Seiderer
2025-02-18 11:47     ` Patrick Steinhardt [this message]
2025-02-18 14:41       ` Eli Schwartz
2025-02-10 16:18   ` Junio C Hamano
2025-02-10 16:43     ` Peter Seiderer
2025-02-10 19:54       ` Junio C Hamano
2025-02-11  8:55         ` Peter Seiderer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z7RzPkiBfbYPhKp_@pks.im \
    --to=ps@pks.im \
    --cc=eschwartz@gentoo.org \
    --cc=git@vger.kernel.org \
    --cc=ps.report@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).