diff mbox series

[1/1] package/pkgconf: add host link to pkg-config

Message ID 20190404192413.10205-2-stuart.summers@intel.com
State Changes Requested
Headers show
Series fix kernel build failure for 5.1.0-rc3 | expand

Commit Message

Summers, Stuart April 4, 2019, 7:24 p.m. UTC
A patch was added to the Linux kernel in 5.1.0-rc3 which
adds a requirement that the host build environment include
pkg-config. Since pkg-config was deprecated in buildroot,
add a link in the host directory to /usr/bin/pkg-config.

Also add a new config option to enforce building host-pkgconf
before building the Linux kernel.

Signed-off-by: Stuart Summers <stuart.summers@intel.com>
---
 linux/Config.in            | 8 ++++++++
 linux/linux.mk             | 4 ++++
 package/pkgconf/pkgconf.mk | 8 +++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni April 4, 2019, 7:42 p.m. UTC | #1
Hello Stuart,

Thanks for the patch.

On Thu,  4 Apr 2019 12:24:13 -0700
Stuart Summers <stuart.summers@intel.com> wrote:

> A patch was added to the Linux kernel in 5.1.0-rc3 which
> adds a requirement that the host build environment include
> pkg-config. Since pkg-config was deprecated in buildroot,
> add a link in the host directory to /usr/bin/pkg-config.

pkg-config is definitely not deprecated at all, and Buildroot's pkgconf
package is already installing it as $(HOST_DIR)/usr/bin/pkg-config:

define HOST_PKGCONF_INSTALL_WRAPPER
        $(INSTALL) -m 0755 -D package/pkgconf/pkg-config.in \
                $(HOST_DIR)/bin/pkg-config

However, the wrapper assumes by default we are building for the target,
and therefore returns results valid for cross-compilation. To return
results valid for native build, the following environment variables
need to be passed:

        PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
        PKG_CONFIG_SYSROOT_DIR="/" \
        PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
        PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
        PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/share/pkgconfig"

> Also add a new config option to enforce building host-pkgconf
> before building the Linux kernel.

Do we need a new option ? If pkg-config is only used by Linux to detect
libelf, what about just adding host-pkgconf to LINUX_DEPENDENCIES when
BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF is enabled ?

> +define HOST_PKGCONF_LINK_PKGCONFIG
> +	ln -sf pkgconf $(HOST_DIR)/usr/bin/pkg-config
> +endef

This is definitely wrong and will break the wrapper we install.

Thomas
Summers, Stuart April 4, 2019, 9:30 p.m. UTC | #2
On Thu, 2019-04-04 at 21:42 +0200, Thomas Petazzoni wrote:
> Hello Stuart,
> 
> Thanks for the patch.
> 
> On Thu,  4 Apr 2019 12:24:13 -0700
> Stuart Summers <stuart.summers@intel.com> wrote:
> 
> > A patch was added to the Linux kernel in 5.1.0-rc3 which
> > adds a requirement that the host build environment include
> > pkg-config. Since pkg-config was deprecated in buildroot,
> > add a link in the host directory to /usr/bin/pkg-config.
> 
> pkg-config is definitely not deprecated at all, and Buildroot's 

This was maybe a poorly worded commit message. I just meant that we are
using pkgconf in place of pkg-config. I can remove this.

> pkgconf
> package is already installing it as $(HOST_DIR)/usr/bin/pkg-config:
> 
> define HOST_PKGCONF_INSTALL_WRAPPER
>         $(INSTALL) -m 0755 -D package/pkgconf/pkg-config.in \
>                 $(HOST_DIR)/bin/pkg-config
> 
> However, the wrapper assumes by default we are building for the
> target,
> and therefore returns results valid for cross-compilation. To return
> results valid for native build, the following environment variables
> need to be passed:
> 
>         PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
>         PKG_CONFIG_SYSROOT_DIR="/" \
>         PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
>         PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
>         PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/shar
> e/pkgconfig"

I apologize if I'm missing something obvious, but adding this to
packages/pkgconf/pkgconf.mk did not seem to make any difference. I also
tried adding this to linux/linux.mk. The latter I didn't do a full
"make clean", but did on the former.

> 
> > Also add a new config option to enforce building host-pkgconf
> > before building the Linux kernel.
> 
> Do we need a new option ? If pkg-config is only used by Linux to 

No need to add this, I agree.

> detect
> libelf, what about just adding host-pkgconf to LINUX_DEPENDENCIES 
> when
> BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF is enabled ?

At least without including the changes I had, I was seeing host-pkgconf 
show up in output/build even without adding this to LINUX_DEPENDENCIES,
although that seems like the right thing to add anyway.

> 
> > +define HOST_PKGCONF_LINK_PKGCONFIG
> > +	ln -sf pkgconf $(HOST_DIR)/usr/bin/pkg-config
> > +endef
> 
> This is definitely wrong and will break the wrapper we install.

Thanks for the feedback and makes sense. Just looking at the right way
to work around this.

Thanks,
Stuart

> 
> Thomas
Thomas Petazzoni April 5, 2019, 7:53 a.m. UTC | #3
Hello Stuart,

On Thu, 4 Apr 2019 21:30:40 +0000
"Summers, Stuart" <stuart.summers@intel.com> wrote:

> > However, the wrapper assumes by default we are building for the
> > target,
> > and therefore returns results valid for cross-compilation. To return
> > results valid for native build, the following environment variables
> > need to be passed:
> > 
> >         PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
> >         PKG_CONFIG_SYSROOT_DIR="/" \
> >         PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
> >         PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
> >         PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/shar
> > e/pkgconfig"  
> 
> I apologize if I'm missing something obvious, but adding this to
> packages/pkgconf/pkgconf.mk did not seem to make any difference. I also
> tried adding this to linux/linux.mk. The latter I didn't do a full
> "make clean", but did on the former.

Adding those lines to pkgconf.mk will indeed make no difference: they
should be added to the package calling pkg-config, in cases where
pkg-config should return results valid for building native code (i.e
not cross-compiled). Did you try to put this in LINUX_MAKE_ENV for
example ?

> > detect
> > libelf, what about just adding host-pkgconf to LINUX_DEPENDENCIES 
> > when
> > BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF is enabled ?  
> 
> At least without including the changes I had, I was seeing host-pkgconf 
> show up in output/build even without adding this to LINUX_DEPENDENCIES,
> although that seems like the right thing to add anyway.

linux depends on host-kmod, and host-kmod depends on host-pkgconf, so
indeed, host-pkgconf will always be pulled in. However, since Linux is
using it directly, I think it makes sense to add the host-pkgconf
dependency to LINUX_DEPENDENCIES.

> > This is definitely wrong and will break the wrapper we install.  
> 
> Thanks for the feedback and makes sense. Just looking at the right way
> to work around this.

The completely correct way would be:

 - To have pkg-config return results for native build

 - To have <tuple>-pkg-config return results for cross-compilation

But then, when cross-building, we need to convince the packages that
they need to call <tuple>-pkg-config. The autotools PKG_CHECK_MODULES()
macro does this by default, so a majority of packages would be OK. But
there are also lots of packages that call "pkg-config" directly, and
those would have to be fixed.

Best regards,

Thomas
Summers, Stuart April 5, 2019, 6:50 p.m. UTC | #4
On Fri, 2019-04-05 at 09:53 +0200, Thomas Petazzoni wrote:
> Hello Stuart,
> 
> On Thu, 4 Apr 2019 21:30:40 +0000
> "Summers, Stuart" <stuart.summers@intel.com> wrote:
> 
> > > However, the wrapper assumes by default we are building for the
> > > target,
> > > and therefore returns results valid for cross-compilation. To
> > > return
> > > results valid for native build, the following environment
> > > variables
> > > need to be passed:
> > > 
> > >         PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
> > >         PKG_CONFIG_SYSROOT_DIR="/" \
> > >         PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
> > >         PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
> > >         PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/
> > > shar
> > > e/pkgconfig"  
> > 
> > I apologize if I'm missing something obvious, but adding this to
> > packages/pkgconf/pkgconf.mk did not seem to make any difference. I
> > also
> > tried adding this to linux/linux.mk. The latter I didn't do a full
> > "make clean", but did on the former.
> 
> Adding those lines to pkgconf.mk will indeed make no difference: they
> should be added to the package calling pkg-config, in cases where
> pkg-config should return results valid for building native code (i.e
> not cross-compiled). Did you try to put this in LINUX_MAKE_ENV for
> example ?

Pointing out my obvious misunderstanding here :). This does indeed fix
the issue.

> 
> > > detect
> > > libelf, what about just adding host-pkgconf to
> > > LINUX_DEPENDENCIES 
> > > when
> > > BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF is enabled ?  
> > 
> > At least without including the changes I had, I was seeing host-
> > pkgconf 
> > show up in output/build even without adding this to
> > LINUX_DEPENDENCIES,
> > although that seems like the right thing to add anyway.
> 
> linux depends on host-kmod, and host-kmod depends on host-pkgconf, so
> indeed, host-pkgconf will always be pulled in. However, since Linux
> is
> using it directly, I think it makes sense to add the host-pkgconf
> dependency to LINUX_DEPENDENCIES.

I agree.

> 
> > > This is definitely wrong and will break the wrapper we install.  
> > 
> > Thanks for the feedback and makes sense. Just looking at the right
> > way
> > to work around this.
> 
> The completely correct way would be:
> 
>  - To have pkg-config return results for native build
> 
>  - To have <tuple>-pkg-config return results for cross-compilation
> 
> But then, when cross-building, we need to convince the packages that
> they need to call <tuple>-pkg-config. The autotools
> PKG_CHECK_MODULES()
> macro does this by default, so a majority of packages would be OK.
> But
> there are also lots of packages that call "pkg-config" directly, and
> those would have to be fixed.

I did glance through the other packages. Enabling everything that
touches host-pkgconf resulted in a build failure in the python module,
which didn't appear to touch pkg-config. I decided to push something a
bit more targeted instead. If you have another suggestion, though, let
me know.

Thanks again for the feedback here!

-Stuart

> 
> Best regards,
> 
> Thomas
diff mbox series

Patch

diff --git a/linux/Config.in b/linux/Config.in
index 9a4d46e534..5d0c623c2b 100644
--- a/linux/Config.in
+++ b/linux/Config.in
@@ -432,6 +432,14 @@  config BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF
 	  CONFIG_UNWINDER_ORC=y, please install libelf-dev,
 	  libelf-devel or elfutils-libelf-devel".
 
+config BR2_LINUX_KERNEL_NEEDS_HOST_PKG_CONFIG
+	bool "Needs host pkgconf"
+	help
+	  Starting in 5.1.0-rc3, a change was added to the Linux kernel
+	  which uses pkg-config to determine the location of the libelf
+	  library. Without this option, the kernel will fail with build
+	  errors.
+
 # Linux extensions
 source "linux/Config.ext.in"
 
diff --git a/linux/linux.mk b/linux/linux.mk
index 6bf2b88038..d011f92828 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -100,6 +100,10 @@  ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF),y)
 LINUX_DEPENDENCIES += host-elfutils
 endif
 
+ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_PKG_CONFIG),y)
+LINUX_DEPENDENCIES += host-pkgconf
+endif
+
 # If host-uboot-tools is selected by the user, assume it is needed to
 # create a custom image
 ifeq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS),y)
diff --git a/package/pkgconf/pkgconf.mk b/package/pkgconf/pkgconf.mk
index e3c73fd405..8284799f1e 100644
--- a/package/pkgconf/pkgconf.mk
+++ b/package/pkgconf/pkgconf.mk
@@ -16,6 +16,10 @@  define PKGCONF_LINK_PKGCONFIG
 	ln -sf pkgconf $(TARGET_DIR)/usr/bin/pkg-config
 endef
 
+define HOST_PKGCONF_LINK_PKGCONFIG
+	ln -sf pkgconf $(HOST_DIR)/usr/bin/pkg-config
+endef
+
 define HOST_PKGCONF_INSTALL_WRAPPER
 	$(INSTALL) -m 0755 -D package/pkgconf/pkg-config.in \
 		$(HOST_DIR)/bin/pkg-config
@@ -32,7 +36,9 @@  define HOST_PKGCONF_SHARED
 endef
 
 PKGCONF_POST_INSTALL_TARGET_HOOKS += PKGCONF_LINK_PKGCONFIG
-HOST_PKGCONF_POST_INSTALL_HOOKS += HOST_PKGCONF_INSTALL_WRAPPER
+HOST_PKGCONF_POST_INSTALL_HOOKS += \
+	HOST_PKGCONF_INSTALL_WRAPPER \
+	HOST_PKGCONF_LINK_PKGCONFIG
 
 ifeq ($(BR2_STATIC_LIBS),y)
 HOST_PKGCONF_POST_INSTALL_HOOKS += HOST_PKGCONF_STATIC