deb/cross: stop exporting PKG_CONFIG_LIBDIR for cross builds
CI / build (push) Successful in 3m13s
CI / test (push) Skipped
CI / publish (push) Skipped
CI / snap (push) Successful in 6m15s

dpkg-buildpackage and sbuild export no pkg-config redirection: the
environment is the package's to set.  Pointing the whole build at the
target multiarch pkgconfig dirs makes every pkg-config-consuming tool
resolve against the target libraries, the host-side tools of the same
build included: the host linker is then handed target-arch -L paths
(the kernel's resolve_btfids logging 'skipping incompatible
/usr/lib/aarch64-linux-gnu/libelf.so') and only survives through
fallbacks when the build-architecture libraries happen to be installed
too.

Packages whose cross builds need target pkg-config data must arrange
for it themselves, the way the kernel packaging builds rtla statically
against no target system libraries.
This commit is contained in:
2026-09-25 20:54:06 +02:00
parent ce19c5648b
commit 46407375d0
+7 -24
View File
@@ -62,20 +62,6 @@ pub fn setup_environment(
.map_err(|e| format!("Invalid UTF-8 in dpkg-architecture output: {e}"))?; .map_err(|e| format!("Invalid UTF-8 in dpkg-architecture output: {e}"))?;
parse_dpkg_architecture_output(&dpkg_architecture, env); 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()); env.insert("DEB_BUILD_PROFILES".to_string(), "cross".to_string());
Ok(()) Ok(())
@@ -304,21 +290,18 @@ mod tests {
assert!(cross_suites("noble", None, "not-a-distro").is_err()); assert!(cross_suites("noble", None, "not-a-distro").is_err());
} }
/// setup_environment exports the target multiarch pkg-config libdir: /// setup_environment exports the dpkg cross variables and the 'cross'
/// tools' feature checks run the *host* pkg-config, which must find the /// build profile, and nothing beyond what dpkg-buildpackage exports:
/// target's .pc files (rtla hard-errors on libtraceevent otherwise, /// no pkg-config redirection (the environment is the package's to
/// failing linux-riscv cross builds despite the target -dev packages /// set, and target-arch pkgconfig paths would also poison the
/// being installed). /// host-side tools of the same build).
#[test] #[test]
fn test_setup_environment_exports_cross_pkg_config_libdir() { fn test_setup_environment_exports_dpkg_cross_variables_only() {
let mut env = HashMap::new(); let mut env = HashMap::new();
let ctx = Arc::new(Context::new(crate::context::ContextConfig::Local).unwrap()); let ctx = Arc::new(Context::new(crate::context::ContextConfig::Local).unwrap());
setup_environment(&mut env, "riscv64", ctx).unwrap(); setup_environment(&mut env, "riscv64", ctx).unwrap();
assert_eq!( assert!(!env.contains_key("PKG_CONFIG_LIBDIR"));
env.get("PKG_CONFIG_LIBDIR").map(String::as_str),
Some("/usr/lib/riscv64-linux-gnu/pkgconfig:/usr/share/pkgconfig")
);
assert_eq!( assert_eq!(
env.get("DEB_BUILD_PROFILES").map(String::as_str), env.get("DEB_BUILD_PROFILES").map(String::as_str),
Some("cross") Some("cross")