Skip to content

Commit 65f369b

Browse files
committed
zig build: add --pkg-config option
Useful to override path to pkg-config executable, for example when it's name is prepended by target triple for cross-compilation purposes. Signed-off-by: Eric Joldasov <[email protected]>
1 parent bcb534c commit 65f369b

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

lib/compiler/build_runner.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ pub fn main() !void {
187187
};
188188
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
189189
builder.zig_lib_dir = .{ .cwd_relative = nextArgOrFatal(args, &arg_idx) };
190+
} else if (mem.eql(u8, arg, "--pkg-config-exe")) {
191+
const next_arg = nextArgOrFatal(args, &arg_idx);
192+
builder.graph.pkg_config_exe = next_arg;
190193
} else if (mem.eql(u8, arg, "--seed")) {
191194
const next_arg = nextArg(args, &arg_idx) orelse
192195
fatalWithHint("expected u32 after '{s}'", .{arg});
@@ -1186,6 +1189,7 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
11861189
\\ --global-cache-dir [path] Override path to global Zig cache directory
11871190
\\ --zig-lib-dir [arg] Override path to Zig lib directory
11881191
\\ --build-runner [file] Override path to build runner
1192+
\\ --pkg-config-exe [file] Override path to pkg-config executable (default: pkg-config)
11891193
\\ --seed [integer] For shuffling dependency traversal order (default: random)
11901194
\\ --debug-log [scope] Enable debugging the compiler
11911195
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered

lib/std/Build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub const Graph = struct {
115115
system_package_mode: bool = false,
116116
cache: Cache,
117117
zig_exe: [:0]const u8,
118+
pkg_config_exe: [:0]const u8 = "pkg-config",
118119
env_map: EnvMap,
119120
global_cache_root: Cache.Directory,
120121
needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .{},

lib/std/Build/Step/Compile.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
700700

701701
var code: u8 = undefined;
702702
const stdout = if (b.runAllowFail(&[_][]const u8{
703-
"pkg-config",
703+
b.graph.pkg_config_exe,
704704
pkg_name,
705705
"--cflags",
706706
"--libs",
@@ -1817,7 +1817,7 @@ pub fn doAtomicSymLinks(
18171817
}
18181818

18191819
fn execPkgConfigList(compile: *std.Build, out_code: *u8) (PkgConfigError || RunError)![]const PkgConfigPkg {
1820-
const stdout = try compile.runAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
1820+
const stdout = try compile.runAllowFail(&[_][]const u8{ compile.graph.pkg_config_exe, "--list-all" }, out_code, .Ignore);
18211821
var list = ArrayList(PkgConfigPkg).init(compile.allocator);
18221822
errdefer list.deinit();
18231823
var line_it = mem.tokenizeAny(u8, stdout, "\r\n");

0 commit comments

Comments
 (0)