From 47bb7c608e732e52630ef70c34d767e32c9b8128 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 19 Sep 2026 13:07:46 +0200 Subject: [PATCH] deb: resolve cross pkg-config against the target multiarch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In-tree tools locate their libraries with the *host* pkg-config during cross builds (the kernel's tools/build feature checks derive their cflags/ldflags from 'pkg-config --cflags/--libs'), whose search path only covers the build architecture's pkgconfig dirs. Cross builds of linux-riscv died in rtla's Makefile.config: libtraceevent/libtracefs were reported missing although the riscv64 -dev packages were installed, because pkg-config never saw their .pc files. The host-arch -dev packages that used to make those checks pass came from the unscoped arch-indep build-dep pass, whose native re-resolution b34e86d correctly scoped to the host arch — removing the accidental co-install along with the bug it papered over. Export PKG_CONFIG_LIBDIR for the target multiarch instead, so the checks resolve target-arch libraries directly: no native build-dep bloat and no wrong-arch linking. --- src/deb/cross.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/deb/cross.rs b/src/deb/cross.rs index 84e39a8..62c9283 100644 --- a/src/deb/cross.rs +++ b/src/deb/cross.rs @@ -62,6 +62,20 @@ pub fn setup_environment( .map_err(|e| format!("Invalid UTF-8 in dpkg-architecture output: {e}"))?; parse_dpkg_architecture_output(&dpkg_architecture, env); + // In-tree tools locate their libraries with the *host* pkg-config during + // cross builds (the kernel's tools/build feature checks derive their + // cflags/ldflags from `pkg-config --cflags/--libs`), whose search path + // only covers the build architecture's pkgconfig dirs. Point it at the + // target's so `libtraceevent` & co resolve to target-arch libraries: + // linux-riscv cross builds die in rtla's Makefile.config otherwise, even + // with the target -dev packages installed. + if let Some(multiarch) = env.get("DEB_HOST_MULTIARCH").cloned() { + env.insert( + "PKG_CONFIG_LIBDIR".to_string(), + format!("/usr/lib/{multiarch}/pkgconfig:/usr/share/pkgconfig"), + ); + } + env.insert("DEB_BUILD_PROFILES".to_string(), "cross".to_string()); Ok(()) @@ -289,4 +303,25 @@ mod tests { ); assert!(cross_suites("noble", None, "not-a-distro").is_err()); } + + /// setup_environment exports the target multiarch pkg-config libdir: + /// tools' feature checks run the *host* pkg-config, which must find the + /// target's .pc files (rtla hard-errors on libtraceevent otherwise, + /// failing linux-riscv cross builds despite the target -dev packages + /// being installed). + #[test] + fn test_setup_environment_exports_cross_pkg_config_libdir() { + let mut env = HashMap::new(); + let ctx = Arc::new(Context::new(crate::context::ContextConfig::Local).unwrap()); + setup_environment(&mut env, "riscv64", ctx).unwrap(); + + assert_eq!( + env.get("PKG_CONFIG_LIBDIR").map(String::as_str), + Some("/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig") + ); + assert_eq!( + env.get("DEB_BUILD_PROFILES").map(String::as_str), + Some("cross") + ); + } }