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 {...@@ -124,6 +124,12 @@ pub const Builder = struct {
124 description: []const u8,124 description: []const u8,
125 };125 };
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
127 pub fn create(133 pub fn create(
128 allocator: *Allocator,134 allocator: *Allocator,
129 zig_exe: []const u8,135 zig_exe: []const u8,
...@@ -192,7 +198,7 @@ pub const Builder = struct {...@@ -192,7 +198,7 @@ pub const Builder = struct {
192 }198 }
193199
194 /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.200 /// 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 {
196 if (self.dest_dir) |dest_dir| {202 if (self.dest_dir) |dest_dir| {
197 self.install_prefix = install_prefix orelse "/usr";203 self.install_prefix = install_prefix orelse "/usr";
198 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;204 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 {...@@ -201,9 +207,29 @@ pub const Builder = struct {
201 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);207 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
202 self.install_path = self.install_prefix;208 self.install_path = self.install_prefix;
203 }209 }
204 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;210
205 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;211 var lib_list = [_][]const u8{ self.install_path, "lib" };
206 self.h_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "include" }) catch unreachable;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;
207 }233 }
208234
209 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {235 fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {
lib/std/special/build_runner.zig+22-2
...@@ -61,6 +61,8 @@ pub fn main() !void {...@@ -61,6 +61,8 @@ pub fn main() !void {
61 const stdout_stream = io.getStdOut().writer();61 const stdout_stream = io.getStdOut().writer();
6262
63 var install_prefix: ?[]const u8 = null;63 var install_prefix: ?[]const u8 = null;
64 var dir_list = Builder.DirList{};
65
64 while (nextArg(args, &arg_idx)) |arg| {66 while (nextArg(args, &arg_idx)) |arg| {
65 if (mem.startsWith(u8, arg, "-D")) {67 if (mem.startsWith(u8, arg, "-D")) {
66 const option_contents = arg[2..];68 const option_contents = arg[2..];
...@@ -87,6 +89,21 @@ pub fn main() !void {...@@ -87,6 +89,21 @@ pub fn main() !void {
87 warn("Expected argument after {s}\n\n", .{arg});89 warn("Expected argument after {s}\n\n", .{arg});
88 return usageAndErr(builder, false, stderr_stream);90 return usageAndErr(builder, false, stderr_stream);
89 };91 };
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 };
90 } else if (mem.eql(u8, arg, "--search-prefix")) {107 } else if (mem.eql(u8, arg, "--search-prefix")) {
91 const search_prefix = nextArg(args, &arg_idx) orelse {108 const search_prefix = nextArg(args, &arg_idx) orelse {
92 warn("Expected argument after --search-prefix\n\n", .{});109 warn("Expected argument after --search-prefix\n\n", .{});
...@@ -135,7 +152,7 @@ pub fn main() !void {...@@ -135,7 +152,7 @@ pub fn main() !void {
135 }152 }
136 }153 }
137154
138 builder.resolveInstallPrefix(install_prefix);155 builder.resolveInstallPrefix(install_prefix, dir_list);
139 try runBuild(builder);156 try runBuild(builder);
140157
141 if (builder.validateUserInputDidItFail())158 if (builder.validateUserInputDidItFail())
...@@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void {...@@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void {
163fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {180fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
164 // run the build script to collect the options181 // run the build script to collect the options
165 if (!already_ran_build) {182 if (!already_ran_build) {
166 builder.resolveInstallPrefix(null);183 builder.resolveInstallPrefix(null, .{});
167 try runBuild(builder);184 try runBuild(builder);
168 }185 }
169186
...@@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
189 \\ -h, --help Print this help and exit206 \\ -h, --help Print this help and exit
190 \\ --verbose Print commands before executing them207 \\ --verbose Print commands before executing them
191 \\ -p, --prefix [path] Override default install prefix208 \\ -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
192 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers212 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
193 \\ --color [auto|off|on] Enable or disable colored error messages213 \\ --color [auto|off|on] Enable or disable colored error messages
194 \\214 \\