From patchwork Mon Dec 16 10:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsOpbXkgUk9TRU4=?= X-Patchwork-Id: 1210217 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=smile.fr Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=smile-fr.20150623.gappssmtp.com header.i=@smile-fr.20150623.gappssmtp.com header.b="TfjZkrQu"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47byH7310cz9sPK for ; Mon, 16 Dec 2019 21:31:15 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 00612204E6; Mon, 16 Dec 2019 10:31:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Ce2hA4eC0k7; Mon, 16 Dec 2019 10:31:06 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 2F300204C9; Mon, 16 Dec 2019 10:31:06 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 96D031BF2B5 for ; Mon, 16 Dec 2019 10:31:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8C53F86A70 for ; Mon, 16 Dec 2019 10:31:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b5KGUE6EabCw for ; Mon, 16 Dec 2019 10:31:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by whitealder.osuosl.org (Postfix) with ESMTPS id C31948528B for ; Mon, 16 Dec 2019 10:30:59 +0000 (UTC) Received: by mail-wr1-f45.google.com with SMTP id w15so6592988wru.4 for ; Mon, 16 Dec 2019 02:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smile-fr.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yrhKR/5W6TuzFyhxw4Kei2n0MHHOq2yo9psp6qJco/A=; b=TfjZkrQu0fKsRLDhU4yVqJwiEDDdZ+MCOkjBqVxB776ttDy1RaEhQ/q2aSUcDyhc9W YSrCazp2HxcIj+y3xIFgpFuMuUpMMvJ3kxOmJnlqsQ5DYtAmGsUOVp6vK+f2cHvDgkIK n5vZQtjVHZgW+gvmzvLnTrJf96qivmo7BFXh58zsBO/7usccJk3dqIkSUNp7BSjnpeMs 1efPJ5aS69bV0/EBtkiIP0zrkWVV4E/cfPZbRjOoSm9cYE+vYjkXdoDvgq8sgJQXLbX9 hBzTsbaKeQuvRvYdXDsXCncWBoP6N3spJDUDTrY9kNe9aENVeEeGbBhFJP08UJf6Nsil ywtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yrhKR/5W6TuzFyhxw4Kei2n0MHHOq2yo9psp6qJco/A=; b=nk1/H9ENcMPLNVxXqbQsxEq6C815MbghtxQh05Bjr3Nwg5+2qWcst3xe24FsuoZmBH XAMfdZyF6JaAFwozuLh6CIZNoml4hOAORgSVUpdbU0YYhGbZLRBZO0EF7R10vfEWA/XS MQEsqnn+c5ppBoyFPhXaBsVXMDXAKphdwamRTaOk7c/3ARcs/ITpYx0EhJVtDlZmCQiz Tpn0ljScYz0ZbDXVeLzF4hRW5sHTPGmCeRLBN7UG4rDFi3whMNljErTU4oooHSMhAFtW J9m2N7gFFw/Ivq1wM1s6rqR4CReXQW4uhpkstzGrtZXMz6quS0/IHC1Gk4ma3MXVMnX5 6Iqw== X-Gm-Message-State: APjAAAX4Sf+V6GRWyrvTq4dRq/0wkeaP+LdNucxftIGh73g5EytO2LId iYEAEn7EcX9mG7wueYjJUtYV981P+w== X-Google-Smtp-Source: APXvYqx8VU8/2zcp3YjqTPQ2i0U7K5vFSkr3DTfnBgNSMWyiJYU0qpb+6QXFXc/ngs/sDvqiBDsIQA== X-Received: by 2002:a5d:46d0:: with SMTP id g16mr30731027wrs.287.1576492257713; Mon, 16 Dec 2019 02:30:57 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:4f5:d4c0:c24e:c904:189d:5967]) by smtp.googlemail.com with ESMTPSA id h8sm22313643wrx.63.2019.12.16.02.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 02:30:57 -0800 (PST) From: =?utf-8?b?SsOpcsOpbXkgUm9zZW4=?= To: buildroot@buildroot.org Date: Mon, 16 Dec 2019 11:30:40 +0100 Message-Id: <20191216103052.35220-2-jeremy.rosen@smile.fr> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191216103052.35220-1-jeremy.rosen@smile.fr> References: <20191216103052.35220-1-jeremy.rosen@smile.fr> MIME-Version: 1.0 Subject: [Buildroot] [PATCH v5 01/13] package/systemd: add host variant X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?SsOpcsOpbXkgUm9zZW4=?= Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Add the infrastructure to build the host version of systemd * disable all optional features, they can be re-added when needed * systemd has creative way of dealing with cross compile we build a "normal" host systemd, but install it in $HOST_DIR we use systemctl --root to correctly act on TARGET_DIR * we need to adjust RPATH using patchelf because meson can't do it correctly by itsel Explanation of Yann E.MORIN about the RPATH trick ------------------- 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. Signed-off-by: Jérémy Rosen --- package/Config.in.host | 1 + package/systemd/Config.in.host | 3 ++ package/systemd/systemd.mk | 94 ++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 package/systemd/Config.in.host diff --git a/package/Config.in.host b/package/Config.in.host index 758c268e00..62e860d7c3 100644 --- a/package/Config.in.host +++ b/package/Config.in.host @@ -70,6 +70,7 @@ menu "Host utilities" source "package/squashfs/Config.in.host" source "package/sunxi-tools/Config.in.host" source "package/swig/Config.in.host" + source "package/systemd/Config.in.host" source "package/tegrarcm/Config.in.host" source "package/ti-cgt-pru/Config.in.host" source "package/uboot-tools/Config.in.host" diff --git a/package/systemd/Config.in.host b/package/systemd/Config.in.host new file mode 100644 index 0000000000..219f24239e --- /dev/null +++ b/package/systemd/Config.in.host @@ -0,0 +1,3 @@ +# Select this if you need host systemd tools (e.g. systemctl) +config BR2_PACKAGE_HOST_SYSTEMD + bool diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk index a292a7512b..5329f91bf8 100644 --- a/package/systemd/systemd.mk +++ b/package/systemd/systemd.mk @@ -550,4 +550,98 @@ endef SYSTEMD_CONF_ENV = $(HOST_UTF8_LOCALE_ENV) SYSTEMD_NINJA_ENV = $(HOST_UTF8_LOCALE_ENV) + +# +# Host-systemd configuration +# +# Options tweaked for buildroot +HOST_SYSTEMD_CONF_OPTS = \ + -Dsplit-bin=true \ + -Dsplit-usr=false \ + --prefix=/usr \ + --libdir=lib \ + --sysconfdir=/etc \ + --localstatedir=/var + +# disable everything else +HOST_SYSTEMD_CONF_OPTS += \ + -Dutmp=false \ + -Dhibernate=false \ + -Dldconfig=false \ + -Dresolve=false \ + -Defi=false \ + -Dtpm=false \ + -Denvironment-d=false \ + -Dbinfmt=false \ + -Dcoredump=false \ + -Dpstore=false \ + -Dlogind=false \ + -Dhostnamed=false \ + -Dlocaled=false \ + -Dmachined=false \ + -Dportabled=false \ + -Dnetworkd=false \ + -Dtimedated=false \ + -Dtimesyncd=false \ + -Dremote=false \ + -Dcreate-log-dirs=false \ + -Dnss-myhostname=false \ + -Dnss-mymachines=false \ + -Dnss-resolve=false \ + -Dnss-systemd=false \ + -Dfirstboot=false \ + -Drandomseed=false \ + -Dbacklight=false \ + -Dvconsole=false \ + -Dquotacheck=false \ + -Dsysusers=false \ + -Dtmpfiles=false \ + -Dimportd=false \ + -Dhwdb=false \ + -Drfkill=false \ + -Dman=false \ + -Dhtml=false \ + -Dsmack=false \ + -Dpolkit=false \ + -Dblkid=false \ + -Didn=false \ + -Dadm-group=false \ + -Dwheel-group=false \ + -Dzlib=false \ + -Dgshadow=false \ + -Dima=false \ + -Dtests=false \ + -Dglib=false \ + -Dacl=false \ + -Dsysvinit-path='' + +HOST_SYSTEMD_DEPENDENCIES = \ + host-util-linux \ + host-patchelf \ + host-libcap \ + host-gperf + +# Fix RPATH After installation +# * systemd provides a install_rpath instruction to meson because the binaries +# need to link with libsystemd which is not in a standard path +# * meson can only replace the RPATH, not append to it +# * the original rpath is thus lost. +# * the original path had been tweaked by buildroot via LDFLAGS to add +# $(HOST_DIR)/lib +# * thus re-tweak rpath after the installation for all binaries that need it +# buildroot detects incorrect RPATH, so adding new binaries should be safe (it +# won't compile unless properly integrated). +HOST_SYSTEMD_HOST_TOOLS = \ + systemd-analyze systemd-mount systemctl udevadm + +define HOST_SYSTEMD_FIX_RPATH + $(foreach f,$(HOST_SYSTEMD_HOST_TOOLS), \ + $(HOST_DIR)/bin/patchelf --set-rpath $(HOST_DIR)/lib:$(HOST_DIR)/lib/systemd $(HOST_DIR)/bin/$(f) + ) +endef + +HOST_SYSTEMD_POST_INSTALL_HOOKS += HOST_SYSTEMD_FIX_RPATH +HOST_SYSTEMD_NINJA_ENV = DESTDIR=$(HOST_DIR) + +$(eval $(host-meson-package)) $(eval $(meson-package))