authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-06-13 04:49:54+00:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-06-26 12:41:05+02:00
log3e4f3a1924150e22e0ca87e906681ebadcf8433e
tree340219e6781f88f6e20b195b8a0bfeeb76db50a2
parent939408289cd05ba2f3b90eb626a388b6a5c747c4
signaturelock-open Commit is signed but in an unrecognized format.

zig build: add --libc general option

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.

2 files changed, 11 insertions(+), 0 deletions(-)

lib/std/build.zig+4
......@@ -58,6 +58,7 @@ pub const Builder = struct {
5858 h_dir: []const u8,
5959 install_path: []const u8,
6060 search_prefixes: ArrayList([]const u8),
61 libc_file: ?[]const u8 = null,
6162 installed_files: ArrayList(InstalledFile),
6263 build_root: []const u8,
6364 cache_root: []const u8,
......@@ -2377,6 +2378,9 @@ pub const LibExeObjStep = struct {
23772378 if (self.libc_file) |libc_file| {
23782379 try zig_args.append("--libc");
23792380 try zig_args.append(builder.pathFromRoot(libc_file));
2381 } else if (builder.libc_file) |libc_file| {
2382 try zig_args.append("--libc");
2383 try zig_args.append(libc_file);
23802384 }
23812385
23822386 switch (self.build_mode) {
lib/std/special/build_runner.zig+7
......@@ -93,6 +93,12 @@ pub fn main() !void {
9393 return usageAndErr(builder, false, stderr_stream);
9494 };
9595 builder.addSearchPrefix(search_prefix);
96 } else if (mem.eql(u8, arg, "--libc")) {
97 const libc_file = nextArg(args, &arg_idx) orelse {
98 warn("Expected argument after --libc\n\n", .{});
99 return usageAndErr(builder, false, stderr_stream);
100 };
101 builder.libc_file = libc_file;
96102 } else if (mem.eql(u8, arg, "--color")) {
97103 const next_arg = nextArg(args, &arg_idx) orelse {
98104 warn("expected [auto|on|off] after --color", .{});
......@@ -190,6 +196,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
190196 \\ --verbose Print commands before executing them
191197 \\ -p, --prefix [path] Override default install prefix
192198 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
199 \\ --libc [file] Provide a file which specifies libc paths
193200 \\ --color [auto|off|on] Enable or disable colored error messages
194201 \\
195202 \\Project-Specific Options: