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>
This commit is contained in:
Eric Joldasov 2024-05-08 23:21:34 +05:00 committed by Andrew Kelley
parent c746d7a35d
commit d263f1ec0e

View File

@ -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");