authorgravatar for sentrycraft123@gmail.comJan200101 <sentrycraft123@gmail.com> 2021-06-12 11:23:04+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-14 20:26:54+03:00
log5a4249fa25ab789a8c060e5ba71ca8b0358e9c8d
treec689931fae3ec6cadae6598f6263d77ad34ae9d7
parentec36b82d058b7e20101a2f55a7ec123077ce9b70

specify the output lib, exe and include paths with flags


2 files changed, 52 insertions(+), 6 deletions(-)

lib/std/build.zig+30-4
......@@ -124,6 +124,12 @@ pub const Builder = struct {
124124 description: []const u8,
125125 };
126126
127 pub const DirList = struct {
128 lib_dir: ?[]const u8 = null,
129 exe_dir: ?[]const u8 = null,
130 include_dir: ?[]const u8 = null,
131 };
132
127133 pub fn create(
128134 allocator: *Allocator,
129135 zig_exe: []const u8,
......@@ -192,7 +198,7 @@ pub const Builder = struct {
192198 }
193199
194200 /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
195 pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8) void {
201 pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void {
196202 if (self.dest_dir) |dest_dir| {
197203 self.install_prefix = install_prefix orelse "/usr";
198204 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
......@@ -201,9 +207,29 @@ pub const Builder = struct {
201207 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
202208 self.install_path = self.install_prefix;
203209 }
204 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
205 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
206 self.h_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "include" }) catch unreachable;
210
211 var lib_list = [_][]const u8{ self.install_path, "lib" };
212 var exe_list = [_][]const u8{ self.install_path, "bin" };
213 var h_list = [_][]const u8{ self.install_path, "include" };
214
215 if (dir_list.lib_dir) |dir| {
216 if (std.fs.path.isAbsolute(dir)) lib_list[0] = self.dest_dir orelse "";
217 lib_list[1] = dir;
218 }
219
220 if (dir_list.exe_dir) |dir| {
221 if (std.fs.path.isAbsolute(dir)) exe_list[0] = self.dest_dir orelse "";
222 exe_list[1] = dir;
223 }
224
225 if (dir_list.include_dir) |dir| {
226 if (std.fs.path.isAbsolute(dir)) h_list[0] = self.dest_dir orelse "";
227 h_list[1] = dir;
228 }
229
230 self.lib_dir = fs.path.join(self.allocator, &lib_list) catch unreachable;
231 self.exe_dir = fs.path.join(self.allocator, &exe_list) catch unreachable;
232 self.h_dir = fs.path.join(self.allocator, &h_list) catch unreachable;
207233 }
208234
209235 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {
lib/std/special/build_runner.zig+22-2
......@@ -61,6 +61,8 @@ pub fn main() !void {
6161 const stdout_stream = io.getStdOut().writer();
6262
6363 var install_prefix: ?[]const u8 = null;
64 var dir_list = Builder.DirList{};
65
6466 while (nextArg(args, &arg_idx)) |arg| {
6567 if (mem.startsWith(u8, arg, "-D")) {
6668 const option_contents = arg[2..];
......@@ -87,6 +89,21 @@ pub fn main() !void {
8789 warn("Expected argument after {s}\n\n", .{arg});
8890 return usageAndErr(builder, false, stderr_stream);
8991 };
92 } else if (mem.eql(u8, arg, "--lib-dir")) {
93 dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
94 warn("Expected argument after {s}\n\n", .{arg});
95 return usageAndErr(builder, false, stderr_stream);
96 };
97 } else if (mem.eql(u8, arg, "--exe-dir")) {
98 dir_list.exe_dir = nextArg(args, &arg_idx) orelse {
99 warn("Expected argument after {s}\n\n", .{arg});
100 return usageAndErr(builder, false, stderr_stream);
101 };
102 } else if (mem.eql(u8, arg, "--include-dir")) {
103 dir_list.include_dir = nextArg(args, &arg_idx) orelse {
104 warn("Expected argument after {s}\n\n", .{arg});
105 return usageAndErr(builder, false, stderr_stream);
106 };
90107 } else if (mem.eql(u8, arg, "--search-prefix")) {
91108 const search_prefix = nextArg(args, &arg_idx) orelse {
92109 warn("Expected argument after --search-prefix\n\n", .{});
......@@ -135,7 +152,7 @@ pub fn main() !void {
135152 }
136153 }
137154
138 builder.resolveInstallPrefix(install_prefix);
155 builder.resolveInstallPrefix(install_prefix, dir_list);
139156 try runBuild(builder);
140157
141158 if (builder.validateUserInputDidItFail())
......@@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void {
163180fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
164181 // run the build script to collect the options
165182 if (!already_ran_build) {
166 builder.resolveInstallPrefix(null);
183 builder.resolveInstallPrefix(null, .{});
167184 try runBuild(builder);
168185 }
169186
......@@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
189206 \\ -h, --help Print this help and exit
190207 \\ --verbose Print commands before executing them
191208 \\ -p, --prefix [path] Override default install prefix
209 \\ --lib-dir [path] Override default library directory path
210 \\ --exe-dir [path] Override default executable directory path
211 \\ --include-dir [path] Override default include directory path
192212 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
193213 \\ --color [auto|off|on] Enable or disable colored error messages
194214 \\