| author | |
| committer | |
| log | 5a4249fa25ab789a8c060e5ba71ca8b0358e9c8d |
| tree | c689931fae3ec6cadae6598f6263d77ad34ae9d7 |
| parent | ec36b82d058b7e20101a2f55a7ec123077ce9b70 |
2 files changed, 52 insertions(+), 6 deletions(-)
lib/std/build.zig+30-4| ... | ... | @@ -124,6 +124,12 @@ pub const Builder = struct { |
| 124 | 124 | description: []const u8, |
| 125 | 125 | }; |
| 126 | 126 | |
| 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 | 133 | pub fn create( |
| 128 | 134 | allocator: *Allocator, |
| 129 | 135 | zig_exe: []const u8, |
| ... | ... | @@ -192,7 +198,7 @@ pub const Builder = struct { |
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 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 | 202 | if (self.dest_dir) |dest_dir| { |
| 197 | 203 | self.install_prefix = install_prefix orelse "/usr"; |
| 198 | 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 | 207 | (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable); |
| 202 | 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; | |
| 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; | |
| 207 | 233 | } |
| 208 | 234 | |
| 209 | 235 | fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource { |
lib/std/special/build_runner.zig+22-2| ... | ... | @@ -61,6 +61,8 @@ pub fn main() !void { |
| 61 | 61 | const stdout_stream = io.getStdOut().writer(); |
| 62 | 62 | |
| 63 | 63 | var install_prefix: ?[]const u8 = null; |
| 64 | var dir_list = Builder.DirList{}; | |
| 65 | ||
| 64 | 66 | while (nextArg(args, &arg_idx)) |arg| { |
| 65 | 67 | if (mem.startsWith(u8, arg, "-D")) { |
| 66 | 68 | const option_contents = arg[2..]; |
| ... | ... | @@ -87,6 +89,21 @@ pub fn main() !void { |
| 87 | 89 | warn("Expected argument after {s}\n\n", .{arg}); |
| 88 | 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 | 107 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 91 | 108 | const search_prefix = nextArg(args, &arg_idx) orelse { |
| 92 | 109 | warn("Expected argument after --search-prefix\n\n", .{}); |
| ... | ... | @@ -135,7 +152,7 @@ pub fn main() !void { |
| 135 | 152 | } |
| 136 | 153 | } |
| 137 | 154 | |
| 138 | builder.resolveInstallPrefix(install_prefix); | |
| 155 | builder.resolveInstallPrefix(install_prefix, dir_list); | |
| 139 | 156 | try runBuild(builder); |
| 140 | 157 | |
| 141 | 158 | if (builder.validateUserInputDidItFail()) |
| ... | ... | @@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void { |
| 163 | 180 | fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void { |
| 164 | 181 | // run the build script to collect the options |
| 165 | 182 | if (!already_ran_build) { |
| 166 | builder.resolveInstallPrefix(null); | |
| 183 | builder.resolveInstallPrefix(null, .{}); | |
| 167 | 184 | try runBuild(builder); |
| 168 | 185 | } |
| 169 | 186 | |
| ... | ... | @@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void |
| 189 | 206 | \\ -h, --help Print this help and exit |
| 190 | 207 | \\ --verbose Print commands before executing them |
| 191 | 208 | \\ -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 | 212 | \\ --search-prefix [path] Add a path to look for binaries, libraries, headers |
| 193 | 213 | \\ --color [auto|off|on] Enable or disable colored error messages |
| 194 | 214 | \\ |