authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-06-13 04:49:54+00:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-15 12:14:04+02:00
logfb0ecdbe1accdb8521fa3539101941a880216292
treea2dc611423aa94f323799164d8cd9a69153fd3af
parentd892d3bbe782c7e5c5a5907c0afd37c3a3efa97f

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 {...@@ -58,6 +58,7 @@ pub const Builder = struct {
58 h_dir: []const u8,58 h_dir: []const u8,
59 install_path: []const u8,59 install_path: []const u8,
60 search_prefixes: ArrayList([]const u8),60 search_prefixes: ArrayList([]const u8),
61 libc_file: ?[]const u8 = null,
61 installed_files: ArrayList(InstalledFile),62 installed_files: ArrayList(InstalledFile),
62 build_root: []const u8,63 build_root: []const u8,
63 cache_root: []const u8,64 cache_root: []const u8,
...@@ -2474,6 +2475,9 @@ pub const LibExeObjStep = struct {...@@ -2474,6 +2475,9 @@ pub const LibExeObjStep = struct {
2474 if (self.libc_file) |libc_file| {2475 if (self.libc_file) |libc_file| {
2475 try zig_args.append("--libc");2476 try zig_args.append("--libc");
2476 try zig_args.append(libc_file.getPath(self.builder));2477 try zig_args.append(libc_file.getPath(self.builder));
2478 } else if (builder.libc_file) |libc_file| {
2479 try zig_args.append("--libc");
2480 try zig_args.append(libc_file);
2477 }2481 }
24782482
2479 switch (self.build_mode) {2483 switch (self.build_mode) {
lib/std/special/build_runner.zig+7
...@@ -110,6 +110,12 @@ pub fn main() !void {...@@ -110,6 +110,12 @@ pub fn main() !void {
110 return usageAndErr(builder, false, stderr_stream);110 return usageAndErr(builder, false, stderr_stream);
111 };111 };
112 builder.addSearchPrefix(search_prefix);112 builder.addSearchPrefix(search_prefix);
113 } else if (mem.eql(u8, arg, "--libc")) {
114 const libc_file = nextArg(args, &arg_idx) orelse {
115 warn("Expected argument after --libc\n\n", .{});
116 return usageAndErr(builder, false, stderr_stream);
117 };
118 builder.libc_file = libc_file;
113 } else if (mem.eql(u8, arg, "--color")) {119 } else if (mem.eql(u8, arg, "--color")) {
114 const next_arg = nextArg(args, &arg_idx) orelse {120 const next_arg = nextArg(args, &arg_idx) orelse {
115 warn("expected [auto|on|off] after --color", .{});121 warn("expected [auto|on|off] after --color", .{});
...@@ -209,6 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -209,6 +215,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
209 \\ --prefix-include-dir [path] Override default include directory path215 \\ --prefix-include-dir [path] Override default include directory path
210 \\216 \\
211 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers217 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
218 \\ --libc [file] Provide a file which specifies libc paths
212 \\219 \\
213 \\ -h, --help Print this help and exit220 \\ -h, --help Print this help and exit
214 \\ --verbose Print commands before executing them221 \\ --verbose Print commands before executing them