Commit d263f1ec0e

Eric Joldasov <bratishkaerik@landless-city.net>
2024-05-08 20:21:34
zig build: respect `PKG_CONFIG` environment variable
`PKG_CONFIG` environment variable is used to override path to pkg-config executable, for example when it's name is prepended by target triple for cross-compilation purposes: ``` PKG_CONFIG=/usr/bin/aarch64-unknown-linux-gnu-pkgconf zig build ``` Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
1 parent c746d7a
Changed files (1)
lib
std
Build
lib/std/Build/Step/Compile.zig
@@ -707,8 +707,9 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
     };
 
     var code: u8 = undefined;
+    const pkg_config_exe = b.graph.env_map.get("PKG_CONFIG") orelse "pkg-config";
     const stdout = if (b.runAllowFail(&[_][]const u8{
-        "pkg-config",
+        pkg_config_exe,
         pkg_name,
         "--cflags",
         "--libs",
@@ -1852,7 +1853,8 @@ pub fn doAtomicSymLinks(
 }
 
 fn execPkgConfigList(compile: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg {
-    const stdout = try compile.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
+    const pkg_config_exe = compile.graph.env_map.get("PKG_CONFIG") orelse "pkg-config";
+    const stdout = try compile.runAllowFail(&[_][]const u8{ pkg_config_exe, "--list-all" }, out_code, .Ignore);
     var list = ArrayList(PkgConfigPkg).init(compile.allocator);
     errdefer list.deinit();
     var line_it = mem.tokenizeAny(u8, stdout, "\r\n");