| author | |
| committer | |
| log | 3bf72f2b3add70ad0671c668baf251f2db93abbf |
| tree | d93b2f65908d00a80bd8da93ed59374b0b098571 |
| parent | 749c3f014ba36a6dc824419f835790f9c181aad3 |
This is useful for build.zig files to check in some cases, for example
to adhere to the convention of installing config to /etc instead of
/usr/etc on linux when using the /usr prefix. Perhaps std.build will
handle such common cases eventually, but that is not yet the case.2 files changed, 11 insertions(+), 20 deletions(-)
lib/std/build.zig+7-16| ... | ... | @@ -51,7 +51,7 @@ pub const Builder = struct { |
| 51 | 51 | default_step: *Step, |
| 52 | 52 | env_map: *BufMap, |
| 53 | 53 | top_level_steps: ArrayList(*TopLevelStep), |
| 54 | install_prefix: ?[]const u8, | |
| 54 | install_prefix: []const u8, | |
| 55 | 55 | dest_dir: ?[]const u8, |
| 56 | 56 | lib_dir: []const u8, |
| 57 | 57 | exe_dir: []const u8, |
| ... | ... | @@ -156,7 +156,7 @@ pub const Builder = struct { |
| 156 | 156 | .default_step = undefined, |
| 157 | 157 | .env_map = env_map, |
| 158 | 158 | .search_prefixes = ArrayList([]const u8).init(allocator), |
| 159 | .install_prefix = null, | |
| 159 | .install_prefix = undefined, | |
| 160 | 160 | .lib_dir = undefined, |
| 161 | 161 | .exe_dir = undefined, |
| 162 | 162 | .h_dir = undefined, |
| ... | ... | @@ -190,22 +190,13 @@ pub const Builder = struct { |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file. |
| 193 | pub fn setInstallPrefix(self: *Builder, optional_prefix: ?[]const u8) void { | |
| 194 | self.install_prefix = optional_prefix; | |
| 195 | } | |
| 196 | ||
| 197 | /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file. | |
| 198 | pub fn resolveInstallPrefix(self: *Builder) void { | |
| 193 | pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8) void { | |
| 199 | 194 | if (self.dest_dir) |dest_dir| { |
| 200 | const install_prefix = self.install_prefix orelse "/usr"; | |
| 201 | self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable; | |
| 195 | self.install_prefix = install_prefix orelse "/usr"; | |
| 196 | self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable; | |
| 202 | 197 | } else { |
| 203 | const install_prefix = self.install_prefix orelse blk: { | |
| 204 | const p = self.cache_root; | |
| 205 | self.install_prefix = p; | |
| 206 | break :blk p; | |
| 207 | }; | |
| 208 | self.install_path = install_prefix; | |
| 198 | self.install_prefix = install_prefix orelse self.cache_root; | |
| 199 | self.install_path = self.install_prefix; | |
| 209 | 200 | } |
| 210 | 201 | self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable; |
| 211 | 202 | self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable; |
lib/std/special/build_runner.zig+4-4| ... | ... | @@ -60,6 +60,7 @@ pub fn main() !void { |
| 60 | 60 | const stderr_stream = io.getStdErr().writer(); |
| 61 | 61 | const stdout_stream = io.getStdOut().writer(); |
| 62 | 62 | |
| 63 | var install_prefix: ?[]const u8 = null; | |
| 63 | 64 | while (nextArg(args, &arg_idx)) |arg| { |
| 64 | 65 | if (mem.startsWith(u8, arg, "-D")) { |
| 65 | 66 | const option_contents = arg[2..]; |
| ... | ... | @@ -82,7 +83,7 @@ pub fn main() !void { |
| 82 | 83 | } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 83 | 84 | return usage(builder, false, stdout_stream); |
| 84 | 85 | } else if (mem.eql(u8, arg, "--prefix")) { |
| 85 | builder.install_prefix = nextArg(args, &arg_idx) orelse { | |
| 86 | install_prefix = nextArg(args, &arg_idx) orelse { | |
| 86 | 87 | warn("Expected argument after --prefix\n\n", .{}); |
| 87 | 88 | return usageAndErr(builder, false, stderr_stream); |
| 88 | 89 | }; |
| ... | ... | @@ -134,7 +135,7 @@ pub fn main() !void { |
| 134 | 135 | } |
| 135 | 136 | } |
| 136 | 137 | |
| 137 | builder.resolveInstallPrefix(); | |
| 138 | builder.resolveInstallPrefix(install_prefix); | |
| 138 | 139 | try runBuild(builder); |
| 139 | 140 | |
| 140 | 141 | if (builder.validateUserInputDidItFail()) |
| ... | ... | @@ -162,8 +163,7 @@ fn runBuild(builder: *Builder) anyerror!void { |
| 162 | 163 | fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void { |
| 163 | 164 | // run the build script to collect the options |
| 164 | 165 | if (!already_ran_build) { |
| 165 | builder.setInstallPrefix(null); | |
| 166 | builder.resolveInstallPrefix(); | |
| 166 | builder.resolveInstallPrefix(null); | |
| 167 | 167 | try runBuild(builder); |
| 168 | 168 | } |
| 169 | 169 |