From 639d737512b1b5a9c13394efa65fc7aba1d0b6ba Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Fri, 13 Mar 2026 22:21:31 +0800 Subject: [PATCH] Check PKG_CONFIG for pkg-config executable When doing cross-compilation in some environments (e.g. NixOS pkgsCross), the name of the pkg-config executable is aarch64-unknown-linux-gnu-pkg-config. Consult the PKG_CONFIG environment variable for the pkg-config executable before checking the presence of pkg-config binary. --- build.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 8e04244..6105316 100644 --- a/build.rs +++ b/build.rs @@ -155,7 +155,11 @@ fn main() { let (compiler, mut cflags) = if vendored_libbpf || vendored_libelf || vendored_zlib { pkg_check("make"); - pkg_check("pkg-config"); + pkg_check( + std::env::var("PKG_CONFIG") + .as_deref() + .unwrap_or("pkg-config"), + ); let compiler = cc::Build::new().try_get_compiler().expect( "a C compiler is required to compile libbpf-sys using the vendored copy of libbpf", @@ -246,7 +250,7 @@ fn open_lockable(path: &Path) -> io::Result { // with write permissions. So just open for reading and hope // for the best. File::open(path) - }, + } e @ Err(..) => e, } }