authorgravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-05-08 23:21:34+05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 02:32:33-07:00
logd263f1ec0eb988f0e4ed1859351f5040f590996b
tree4e08c9468589455827c721c1bfcf8620135475c7
parentc746d7a35d6ba26d783863ef8fa86123891e1d38

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 files changed, 4 insertions(+), 2 deletions(-)

lib/std/Build/Step/Compile.zig+4-2
...@@ -707,8 +707,9 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {...@@ -707,8 +707,9 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
707 };707 };
708708
709 var code: u8 = undefined;709 var code: u8 = undefined;
710 const pkg_config_exe = b.graph.env_map.get("PKG_CONFIG") orelse "pkg-config";
710 const stdout = if (b.runAllowFail(&[_][]const u8{711 const stdout = if (b.runAllowFail(&[_][]const u8{
711 "pkg-config",712 pkg_config_exe,
712 pkg_name,713 pkg_name,
713 "--cflags",714 "--cflags",
714 "--libs",715 "--libs",
...@@ -1852,7 +1853,8 @@ pub fn doAtomicSymLinks(...@@ -1852,7 +1853,8 @@ pub fn doAtomicSymLinks(
1852}1853}
18531854
1854fn execPkgConfigList(compile: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg {1855fn execPkgConfigList(compile: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg {
1855 const stdout = try compile.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);1856 const pkg_config_exe = compile.graph.env_map.get("PKG_CONFIG") orelse "pkg-config";
1857 const stdout = try compile.runAllowFail(&[_][]const u8{ pkg_config_exe, "--list-all" }, out_code, .Ignore);
1856 var list = ArrayList(PkgConfigPkg).init(compile.allocator);1858 var list = ArrayList(PkgConfigPkg).init(compile.allocator);
1857 errdefer list.deinit();1859 errdefer list.deinit();
1858 var line_it = mem.tokenizeAny(u8, stdout, "\r\n");1860 var line_it = mem.tokenizeAny(u8, stdout, "\r\n");