Skip to content

Commit

Permalink
zig build: add --libc general option
Browse files Browse the repository at this point in the history
This new option sets a default libc paths file to be used for all
LibExeObjSteps. Setting LibExeObjStep.libc_file overrides this default.

This is required to allow users to cross compile projects linking system
libraries without needing to patch the build.zig.
  • Loading branch information
ifreund authored and kubkon committed Jun 15, 2021
1 parent d892d3b commit fb0ecdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub const Builder = struct {
h_dir: []const u8,
install_path: []const u8,
search_prefixes: ArrayList([]const u8),
libc_file: ?[]const u8 = null,
installed_files: ArrayList(InstalledFile),
build_root: []const u8,
cache_root: []const u8,
Expand Down Expand Up @@ -2474,6 +2475,9 @@ pub const LibExeObjStep = struct {
if (self.libc_file) |libc_file| {
try zig_args.append("--libc");
try zig_args.append(libc_file.getPath(self.builder));
} else if (builder.libc_file) |libc_file| {
try zig_args.append("--libc");
try zig_args.append(libc_file);
}

switch (self.build_mode) {
Expand Down
7 changes: 7 additions & 0 deletions lib/std/special/build_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ pub fn main() !void {
return usageAndErr(builder, false, stderr_stream);
};
builder.addSearchPrefix(search_prefix);
} else if (mem.eql(u8, arg, "--libc")) {
const libc_file = nextArg(args, &arg_idx) orelse {
warn("Expected argument after --libc\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
builder.libc_file = libc_file;
} else if (mem.eql(u8, arg, "--color")) {
const next_arg = nextArg(args, &arg_idx) orelse {
warn("expected [auto|on|off] after --color", .{});
Expand Down Expand Up @@ -209,6 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
\\ --prefix-include-dir [path] Override default include directory path
\\
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --libc [file] Provide a file which specifies libc paths
\\
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
Expand Down

0 comments on commit fb0ecdb

Please sign in to comment.