diff mbox series

[5/8] classes/pkgconfig: rationalise variable usage

Message ID 20260123180448.2997378-6-ross.burton@arm.com
State Changes Requested
Headers show
Series Rationalise the pkg-config variables | expand

Commit Message

Ross Burton Jan. 23, 2026, 6:04 p.m. UTC
Our PKG_CONFIG_* variables were a bit of a mess.

First, PKG_CONFIG_DIR is not used by either pkg-config or pkgconf.  It's
set to (approximately) ${libdir}/pkgconfig but we also want to search
${datadir}/pkgconfig so it isn't actually useful as an intermediate
variable.

Remove PKG_CONFIG_DIR and replace with the neatest expression for the
value we want: ${STAGING_LIBDIR}/pkgconfig.

Second, PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR shouldn't be set to the
same paths. The semantics of these variables is that PKG_CONFIG_PATH is
searched first, followed by either PKG_CONFIG_LIBDIR or the default paths
compiled into the pkg-config binary.

Currently we set PKG_CONFIG_PATH to (approx.) ${libdir}:${datadir} and
PKG_CONFIG_LIBDIR to ${libdir}, so we search libdir twice.

Also the default paths embedded in the binary will be incorrect as they
point to pkgconfig-native's sysroot, so we absolutely need to set
PKG_CONFIG_LIBDIR.

Instead, set PKG_CONFIG_LIBDIR to ${libdir}:${datadir} so that the
default search path is correct. We can then leave PKG_CONFIG_PATH empty,
if a recipe has specific needs it can set that but normally it is not
needed anymore.

Then bubble these changes out to the few places where the variables are
used directly:

- Kernel/kconfig interaction where 'pkg-config' needs to read the
native files, not target.

- The class classes (native, etc) which redefine the values.  However,
as the values are defined in terms of sysroot variables, we can
typically remove assignments from those classes as they are redundant.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/classes-recipe/cml1.bbclass           | 7 +++----
 meta/classes-recipe/cross-canadian.bbclass | 3 +--
 meta/classes-recipe/cross.bbclass          | 4 ++--
 meta/classes-recipe/kernel.bbclass         | 8 ++------
 meta/classes-recipe/native.bbclass         | 1 -
 meta/classes-recipe/nativesdk.bbclass      | 3 ---
 meta/classes-recipe/pkgconfig.bbclass      | 1 -
 meta/conf/bitbake.conf                     | 6 +++---
 meta/recipes-kernel/linux/linux-yocto.inc  | 7 +++----
 9 files changed, 14 insertions(+), 26 deletions(-)

Comments

Mathieu Dubois-Briand Jan. 28, 2026, 1:30 p.m. UTC | #1
On Fri Jan 23, 2026 at 7:04 PM CET, Ross Burton via lists.openembedded.org wrote:
> Our PKG_CONFIG_* variables were a bit of a mess.
>
> First, PKG_CONFIG_DIR is not used by either pkg-config or pkgconf.  It's
> set to (approximately) ${libdir}/pkgconfig but we also want to search
> ${datadir}/pkgconfig so it isn't actually useful as an intermediate
> variable.
>
> Remove PKG_CONFIG_DIR and replace with the neatest expression for the
> value we want: ${STAGING_LIBDIR}/pkgconfig.
>
> Second, PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR shouldn't be set to the
> same paths. The semantics of these variables is that PKG_CONFIG_PATH is
> searched first, followed by either PKG_CONFIG_LIBDIR or the default paths
> compiled into the pkg-config binary.
>
> Currently we set PKG_CONFIG_PATH to (approx.) ${libdir}:${datadir} and
> PKG_CONFIG_LIBDIR to ${libdir}, so we search libdir twice.
>
> Also the default paths embedded in the binary will be incorrect as they
> point to pkgconfig-native's sysroot, so we absolutely need to set
> PKG_CONFIG_LIBDIR.
>
> Instead, set PKG_CONFIG_LIBDIR to ${libdir}:${datadir} so that the
> default search path is correct. We can then leave PKG_CONFIG_PATH empty,
> if a recipe has specific needs it can set that but normally it is not
> needed anymore.
>
> Then bubble these changes out to the few places where the variables are
> used directly:
>
> - Kernel/kconfig interaction where 'pkg-config' needs to read the
> native files, not target.
>
> - The class classes (native, etc) which redefine the values.  However,
> as the values are defined in terms of sysroot variables, we can
> typically remove assignments from those classes as they are redundant.
>
> Signed-off-by: Ross Burton <ross.burton@arm.com>
> ---

Hi Ross,

This patch is almost fine on the autobuilder, with one little exception:
it breaks runtime_test.TestImage.test_testimage_virgl_gtk_sdl on some
hosts. Or to go further, when qemu-system-native is compiled with "gtk+"
PACKAGECONFIG, the it will have a dependency on host glib version and
might complain it is too old:

ERROR: qemu-system-native-10.2.0-r0 do_configure: Execution of '/srv/pokybuild/yocto-worker/oe-selftest-debian/build/build-st-2977320/tmp/work/x86_64-linux/qemu-system-native/10.2.0/temp/run.do_configure.845525' failed with exit code 1
...
| ../sources/qemu-10.2.0/meson.build:1951:8: ERROR: Dependency lookup for gtk+-3.0 with method 'pkgconfig' failed: Could not generate cflags for gtk+-3.0:
| Package 'pango' requires 'glib-2.0 >= 2.82' but version of glib-2.0 is 2.66.8

https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/3105

This can be reproduced by either running
runtime_test.TestImage.test_testimage_virgl_gtk_sdl selftest, or just
building qemu-system-native with:
PACKAGECONFIG:append:pn-qemu-system-native = " gtk+"

Can you have a look at what is going wrong here?

Thanks,
Mathieu
Mathieu Dubois-Briand Jan. 29, 2026, 6:17 a.m. UTC | #2
On Wed Jan 28, 2026 at 2:30 PM CET, Mathieu Dubois-Briand wrote:
> On Fri Jan 23, 2026 at 7:04 PM CET, Ross Burton via lists.openembedded.org wrote:
>> Our PKG_CONFIG_* variables were a bit of a mess.
>>
>> First, PKG_CONFIG_DIR is not used by either pkg-config or pkgconf.  It's
>> set to (approximately) ${libdir}/pkgconfig but we also want to search
>> ${datadir}/pkgconfig so it isn't actually useful as an intermediate
>> variable.
>>
>> Remove PKG_CONFIG_DIR and replace with the neatest expression for the
>> value we want: ${STAGING_LIBDIR}/pkgconfig.
>>
>> Second, PKG_CONFIG_PATH and PKG_CONFIG_LIBDIR shouldn't be set to the
>> same paths. The semantics of these variables is that PKG_CONFIG_PATH is
>> searched first, followed by either PKG_CONFIG_LIBDIR or the default paths
>> compiled into the pkg-config binary.
>>
>> Currently we set PKG_CONFIG_PATH to (approx.) ${libdir}:${datadir} and
>> PKG_CONFIG_LIBDIR to ${libdir}, so we search libdir twice.
>>
>> Also the default paths embedded in the binary will be incorrect as they
>> point to pkgconfig-native's sysroot, so we absolutely need to set
>> PKG_CONFIG_LIBDIR.
>>
>> Instead, set PKG_CONFIG_LIBDIR to ${libdir}:${datadir} so that the
>> default search path is correct. We can then leave PKG_CONFIG_PATH empty,
>> if a recipe has specific needs it can set that but normally it is not
>> needed anymore.
>>
>> Then bubble these changes out to the few places where the variables are
>> used directly:
>>
>> - Kernel/kconfig interaction where 'pkg-config' needs to read the
>> native files, not target.
>>
>> - The class classes (native, etc) which redefine the values.  However,
>> as the values are defined in terms of sysroot variables, we can
>> typically remove assignments from those classes as they are redundant.
>>
>> Signed-off-by: Ross Burton <ross.burton@arm.com>
>> ---
>
> Hi Ross,
>
> This patch is almost fine on the autobuilder, with one little exception:
> it breaks runtime_test.TestImage.test_testimage_virgl_gtk_sdl on some
> hosts. Or to go further, when qemu-system-native is compiled with "gtk+"
> PACKAGECONFIG, the it will have a dependency on host glib version and
> might complain it is too old:
>
> ERROR: qemu-system-native-10.2.0-r0 do_configure: Execution of '/srv/pokybuild/yocto-worker/oe-selftest-debian/build/build-st-2977320/tmp/work/x86_64-linux/qemu-system-native/10.2.0/temp/run.do_configure.845525' failed with exit code 1
> ...
> | ../sources/qemu-10.2.0/meson.build:1951:8: ERROR: Dependency lookup for gtk+-3.0 with method 'pkgconfig' failed: Could not generate cflags for gtk+-3.0:
> | Package 'pango' requires 'glib-2.0 >= 2.82' but version of glib-2.0 is 2.66.8
>
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/3105
>
> This can be reproduced by either running
> runtime_test.TestImage.test_testimage_virgl_gtk_sdl selftest, or just
> building qemu-system-native with:
> PACKAGECONFIG:append:pn-qemu-system-native = " gtk+"
>
> Can you have a look at what is going wrong here?
>
> Thanks,
> Mathieu

Hi Ross,

I note this is also breaking meta-intel builds:

ERROR: libvpl-2.14.0-r0 do_configure: Execution of '/srv/pokybuild/yocto-worker/meta-intel/build/build/tmp/work/corei7-64-poky-linux/libvpl/2.14.0/temp/run.do_configure.2633134' failed with exit code 1
...
| -- Checking for module 'libva>=1.2'
| --   No package 'libva' found
| -- Checking for module 'libva-drm>=1.2'
| --   No package 'libva-drm' found
| CMake Error at examples/api2x/hello-vpp/CMakeLists.txt:78 (message):
|   libva not found: set LIBVA_SUPPORT=OFF to build hello-vpp without libva
|   support

https://autobuilder.yoctoproject.org/valkyrie/#/builders/41/builds/2937

Thanks,
Mathieu
Ross Burton Feb. 6, 2026, 10:29 a.m. UTC | #3
On 29 Jan 2026, at 06:17, Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> wrote:
> 
> I note this is also breaking meta-intel builds:

This one was easy, some recipes in meta-intel are not inheriting pkgconfig. Patch sent.

Ross
diff mbox series

Patch

diff --git a/meta/classes-recipe/cml1.bbclass b/meta/classes-recipe/cml1.bbclass
index 3c2b4da4af..ac65eec4bf 100644
--- a/meta/classes-recipe/cml1.bbclass
+++ b/meta/classes-recipe/cml1.bbclass
@@ -51,12 +51,11 @@  python do_menuconfig() {
         mtime = 0
 
     # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-    d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
-    d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
-    d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
+    d.setVar("PKG_CONFIG_PATH", "")
+    d.setVar("PKG_CONFIG_LIBDIR", "${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig")
     d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
     # ensure that environment variables are overwritten with this tasks 'd' values
-    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
+    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
 
     oe_terminal("sh -c 'make %s; if [ $? -ne 0 ]; then echo \"Command failed.\"; printf \"Press any key to continue... \"; read r; fi'" % d.getVar('KCONFIG_CONFIG_COMMAND'),
                 d.getVar('PN') + ' Configuration', d)
diff --git a/meta/classes-recipe/cross-canadian.bbclass b/meta/classes-recipe/cross-canadian.bbclass
index 059d9aa95f..6d3d2f7623 100644
--- a/meta/classes-recipe/cross-canadian.bbclass
+++ b/meta/classes-recipe/cross-canadian.bbclass
@@ -161,8 +161,7 @@  libexecdir = "${exec_prefix}/libexec/${TARGET_ARCH}${TARGET_VENDOR}-${TARGET_OS}
 
 FILES:${PN} = "${prefix}"
 
-export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
+PKG_CONFIG_LIBDIR = "${STAGING_DIR_HOST}${exec_prefix}/lib/pkgconfig:${STAGING_DIR_HOST}${exec_prefix}/share/pkgconfig"
 
 do_populate_sysroot[stamp-extra-info] = ""
 do_packagedata[stamp-extra-info] = ""
diff --git a/meta/classes-recipe/cross.bbclass b/meta/classes-recipe/cross.bbclass
index 574ce6988d..82a49dc8f5 100644
--- a/meta/classes-recipe/cross.bbclass
+++ b/meta/classes-recipe/cross.bbclass
@@ -33,8 +33,8 @@  PACKAGE_ARCH = "${BUILD_ARCH}"
 
 MULTIMACH_TARGET_SYS = "${BUILD_ARCH}${BUILD_VENDOR}-${BUILD_OS}"
 
-export PKG_CONFIG_DIR = "${exec_prefix}/lib/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = ""
+PKG_CONFIG_LIBDIR = "${exec_prefix}/lib/pkgconfig:${exec_prefix}/share/pkgconfig"
+PKG_CONFIG_SYSROOT_DIR = ""
 
 TARGET_CPPFLAGS = ""
 TARGET_CFLAGS = ""
diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index f989b31c47..b43b4ff4fb 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -365,9 +365,7 @@  kernel_do_compile() {
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 
 	# setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-	export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
-	export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
-	export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
+	export PKG_CONFIG_LIBDIR="${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig"
 	export PKG_CONFIG_SYSROOT_DIR=""
 
 	if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
@@ -421,9 +419,7 @@  do_compile_kernelmodules() {
 	unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
 
 	# setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-	export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
-	export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
-	export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
+	export PKG_CONFIG_LIBDIR="${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig"
 	export PKG_CONFIG_SYSROOT_DIR=""
 
 	if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
diff --git a/meta/classes-recipe/native.bbclass b/meta/classes-recipe/native.bbclass
index b3411d20ca..e114669940 100644
--- a/meta/classes-recipe/native.bbclass
+++ b/meta/classes-recipe/native.bbclass
@@ -98,7 +98,6 @@  do_populate_sysroot[sstate-outputdirs] = "${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN
 # Since we actually install these into situ there is no staging prefix
 STAGING_DIR_HOST = ""
 STAGING_DIR_TARGET = ""
-PKG_CONFIG_DIR = "${libdir}/pkgconfig"
 
 EXTRA_NATIVE_PKGCONFIG_PATH ?= ""
 PKG_CONFIG_PATH .= "${EXTRA_NATIVE_PKGCONFIG_PATH}"
diff --git a/meta/classes-recipe/nativesdk.bbclass b/meta/classes-recipe/nativesdk.bbclass
index c2e53c8450..117cc2329f 100644
--- a/meta/classes-recipe/nativesdk.bbclass
+++ b/meta/classes-recipe/nativesdk.bbclass
@@ -74,9 +74,6 @@  exec_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
 baselib = "lib"
 sbindir = "${bindir}"
 
-export PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${libdir}/pkgconfig"
-export PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
-
 python nativesdk_virtclass_handler () {
     pn = e.data.getVar("PN")
     if not (pn.endswith("-nativesdk") or pn.startswith("nativesdk-")):
diff --git a/meta/classes-recipe/pkgconfig.bbclass b/meta/classes-recipe/pkgconfig.bbclass
index ea91338d34..50e74d0120 100644
--- a/meta/classes-recipe/pkgconfig.bbclass
+++ b/meta/classes-recipe/pkgconfig.bbclass
@@ -6,7 +6,6 @@ 
 
 DEPENDS:prepend = "pkgconfig-native "
 
-export PKG_CONFIG_DIR
 export PKG_CONFIG_PATH
 export PKG_CONFIG_LIBDIR
 export PKG_CONFIG_SYSROOT_DIR
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 8779f65157..a38f055598 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -768,11 +768,11 @@  BUILDCFG_NEEDEDVARS[type] = "list"
 
 # Other
 
-PKG_CONFIG_DIR = "${STAGING_DIR_HOST}${libdir}/pkgconfig"
-PKG_CONFIG_PATH = "${PKG_CONFIG_DIR}:${STAGING_DATADIR}/pkgconfig"
-PKG_CONFIG_LIBDIR = "${PKG_CONFIG_DIR}"
+PKG_CONFIG_PATH = ""
+PKG_CONFIG_LIBDIR = "${STAGING_LIBDIR}/pkgconfig:${STAGING_DATADIR}/pkgconfig"
 PKG_CONFIG_SYSROOT_DIR = "${STAGING_DIR_HOST}"
 PKG_CONFIG_DISABLE_UNINSTALLED = "yes"
+# With pkg-config these have the sysroot prefixed
 PKG_CONFIG_SYSTEM_LIBRARY_PATH = "${base_libdir}:${libdir}"
 PKG_CONFIG_SYSTEM_INCLUDE_PATH = "${includedir}"
 
diff --git a/meta/recipes-kernel/linux/linux-yocto.inc b/meta/recipes-kernel/linux/linux-yocto.inc
index 4d0a726bb6..d57c1aae25 100644
--- a/meta/recipes-kernel/linux/linux-yocto.inc
+++ b/meta/recipes-kernel/linux/linux-yocto.inc
@@ -89,9 +89,8 @@  EXTRA_OEMAKE += '${@bb.utils.contains("KERNEL_DEBUG", "True", "", "PAHOLE=false"
 
 do_devshell:prepend() {
     # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
-    d.setVar("PKG_CONFIG_DIR", "${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig")
-    d.setVar("PKG_CONFIG_PATH", "${PKG_CONFIG_DIR}:${STAGING_DATADIR_NATIVE}/pkgconfig")
-    d.setVar("PKG_CONFIG_LIBDIR", "${PKG_CONFIG_DIR}")
+    d.setVar("PKG_CONFIG_PATH", "")
+    d.setVar("PKG_CONFIG_LIBDIR", "${STAGING_LIBDIR_NATIVE}/pkgconfig:${STAGING_DATADIR_NATIVE}/pkgconfig")
     d.setVarFlag("PKG_CONFIG_SYSROOT_DIR", "unexport", "1")
-    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_DIR PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
+    d.appendVar("OE_TERMINAL_EXPORTS", " PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR")
 }