Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v4 01/13] new recipe : host-systemd
Date: Thu, 12 Dec 2019 18:31:56 +0100	[thread overview]
Message-ID: <20191212173156.GE30031@scaer> (raw)
In-Reply-To: <20191212111920.297bdca6@windsurf>

J?r?my, Thomas,All,

On 2019-12-12 11:19 +0100, Thomas Petazzoni spake thusly:
> On Thu, 12 Dec 2019 08:53:48 +0100
> J?r?my Rosen <jeremy.rosen@smile.fr> wrote:
[--SNIP--]
> > diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> > index a292a7512b..ad16b58ceb 100644
> > --- a/package/systemd/systemd.mk
> > +++ b/package/systemd/systemd.mk
> > @@ -204,6 +204,11 @@ endif
> >  
> >  ifeq ($(BR2_PACKAGE_SYSTEMD_HWDB),y)
> >  SYSTEMD_CONF_OPTS += -Dhwdb=true
> > +define SYSTEMD_BUILD_HWDB
> > +	$(HOST_DIR)/bin/udevadm hwdb --update --root $(TARGET_DIR)
> > +endef
> 
> I think this change could be a separate patch, no? Or is the udevadm
> binary installed by host-systemd conflicting with the one installed by
> host-eudev ?
> 
> Should be explained in the commit log.

I think this change should go in current patch 2, where systemd is made
dependent on host-systemd, which indeed installs its own udevadm which
would conflict with the one from host-eudev.

[--SNIP--]
> > +# Host-systemd configuration
> > +#
> > +#Options tweaked for buildroot
> > +HOST_SYSTEMD_CONF_OPTS= \
> > +	-Dsplit-bin=true \
> > +	-Dsplit-usr=false \
> > +	--prefix=/usr \
> 
> This should really be:
> 
> 	--prefix=$(HOST_DIR)
> 
> > +	--libdir=lib \
> > +	--sysconfdir=/etc \
> > +	--localstatedir=/var
> 
> But in fact, all these options are already passed by the
> host-meson-package infrastructure. Why are you overriding them ?
[--SNIP--]
> > +# * thus re-tweak rpath after the installation for all binaries that need it
> I must admit I don't really understand what's going on here. Can't you
> simply do something like this:
> 
> HOST_SYSTEMD_CONF_ENV = \
> 	LDFLAGS="$(HOST_LDFLAGS) -Wl,-rpath,$(HOST_DIR)/lib/systemd"
> 
> and that's it ?

For the records, here are the explanations I provided on IRC.

The first question is: why do we use --prefix=/usr ?

systemd will store its --prefix in all the executables it generates. As
such, systemctl will have a hardcoded 'prefix', where it will manipulate
and create files/symlinks in. When called natively, this is nice and
shinny.

However, for cross-setup, that does not work obviously.

So, systemd has its tools know about the 'root' directory where this
prefix should be related to. We can call systemctl --root=$(TARGET_DIR)
and systemctl wil do the links and such in there.

However, it does so by appending its known prefix to it.

So, if we were to configure host-systemd as we usually do, with
--prefix=$(HOST_DIR), then when we would call host systemctl --root=$(TARGET_DIR)
it would look for files in $(TARGET_DIR)/$(HOST_DIR), which is wrong.

Calling the host systemctl without --root is also wrong, as it would look for
files in $(HOST_DIR)

So, there is no satisfying official support for this case.

The trick then, is to configure systemd with the prefix it would expect
at runtime (on the target!), that is with /usr, but install out-of-tree.

That was it for the first part of the question: why do we use --prefix.

Now, the second question is: why do we need to muck up with the rpath
after installation?
Well, this boils down to meson (and not systemd itself). When it
installs executables, meson will handily insert whatever rpath the
package meson.build would tell it to use. systemd installs libs in
$(prefix)/lib/systemd and as a NEEDED to those libs, so it uses an RPATH
to find those libs, and meson does introduce that RPATH.
However, we Buildroot also want to insert our own RPATH, because systemd
uses util-linux' libs and libcap, so it needs our RPATH.
However, meson can not extend the RPATH from the LDFLAGS in the
environment; meson can only set the RPATH from what it knows about from
the package's meson.build.

That, in addition to the --prefix=/usr issue above, means that the
executables installed by host-systemd have an RPATH set to
/usr/lib/systemd. when we would want it to be set to
$(HOST_DIR)/lib:$(HOST_DIR)/lib/systemd

That;s what is done in the post-install hook: set the RPATH to the
appropriate values.

[--SNIP--]
> > +HOST_SYSTEMD_POST_INSTALL_HOOKS +=  HOST_SYSTEMD_FIX_RPATH
> > +HOST_SYSTEMD_NINJA_ENV = DESTDIR=$(HOST_DIR)
> With the correct --prefix=$(HOST_DIR) passed by the default
> host-meson-package infrastructure, this DESTDIR=$(HOST_DIR) should no
> longer be necessary.

Alas, this is not possible... :-(

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  parent reply	other threads:[~2019-12-12 17:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12  7:53 [Buildroot] [PATCH v4 00/13] use host-systemd to enable units Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 01/13] new recipe : host-systemd Jérémy Rosen
2019-12-12 10:19   ` Thomas Petazzoni
2019-12-12 10:35     ` Jérémy ROSEN
2019-12-12 17:31     ` Yann E. MORIN [this message]
2019-12-12  7:53 ` [Buildroot] [PATCH v4 02/13] use host-systemctl preset all to enable units Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 03/13] fix tty handling Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 04/13] fix trivial packages with buildroot-provided services Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 05/13] fix trivial cases, upstream-provided services Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 06/13] package/connman: adapt to preset-all Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 07/13] package/linuxptp " Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 08/13] package/network-manager: " Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 09/13] package/wpa_supplicant: adapt for preset-all Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 10/13] package/sysrepo: update to new systemd Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 11/13] package/syslog-ng: implement default using DefaultInstance Jérémy Rosen
2019-12-12  7:53 ` [Buildroot] [PATCH v4 12/13] package/rauc: add a WantedBy section to the unit Jérémy Rosen
2019-12-12  7:54 ` [Buildroot] [PATCH v4 13/13] package/alsa-utils: " Jérémy Rosen
2019-12-12 10:14 ` [Buildroot] [PATCH v4 00/13] use host-systemd to enable units Thomas Petazzoni

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=20191212173156.GE30031@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.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