Commit 5a4249fa25
Changed files (2)
lib
std
special
lib/std/special/build_runner.zig
@@ -61,6 +61,8 @@ pub fn main() !void {
const stdout_stream = io.getStdOut().writer();
var install_prefix: ?[]const u8 = null;
+ var dir_list = Builder.DirList{};
+
while (nextArg(args, &arg_idx)) |arg| {
if (mem.startsWith(u8, arg, "-D")) {
const option_contents = arg[2..];
@@ -87,6 +89,21 @@ pub fn main() !void {
warn("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
+ } else if (mem.eql(u8, arg, "--lib-dir")) {
+ dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
+ warn("Expected argument after {s}\n\n", .{arg});
+ return usageAndErr(builder, false, stderr_stream);
+ };
+ } else if (mem.eql(u8, arg, "--exe-dir")) {
+ dir_list.exe_dir = nextArg(args, &arg_idx) orelse {
+ warn("Expected argument after {s}\n\n", .{arg});
+ return usageAndErr(builder, false, stderr_stream);
+ };
+ } else if (mem.eql(u8, arg, "--include-dir")) {
+ dir_list.include_dir = nextArg(args, &arg_idx) orelse {
+ warn("Expected argument after {s}\n\n", .{arg});
+ return usageAndErr(builder, false, stderr_stream);
+ };
} else if (mem.eql(u8, arg, "--search-prefix")) {
const search_prefix = nextArg(args, &arg_idx) orelse {
warn("Expected argument after --search-prefix\n\n", .{});
@@ -135,7 +152,7 @@ pub fn main() !void {
}
}
- builder.resolveInstallPrefix(install_prefix);
+ builder.resolveInstallPrefix(install_prefix, dir_list);
try runBuild(builder);
if (builder.validateUserInputDidItFail())
@@ -163,7 +180,7 @@ fn runBuild(builder: *Builder) anyerror!void {
fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
// run the build script to collect the options
if (!already_ran_build) {
- builder.resolveInstallPrefix(null);
+ builder.resolveInstallPrefix(null, .{});
try runBuild(builder);
}
@@ -189,6 +206,9 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
\\ -p, --prefix [path] Override default install prefix
+ \\ --lib-dir [path] Override default library directory path
+ \\ --exe-dir [path] Override default executable directory path
+ \\ --include-dir [path] Override default include directory path
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --color [auto|off|on] Enable or disable colored error messages
\\
lib/std/build.zig
@@ -124,6 +124,12 @@ pub const Builder = struct {
description: []const u8,
};
+ pub const DirList = struct {
+ lib_dir: ?[]const u8 = null,
+ exe_dir: ?[]const u8 = null,
+ include_dir: ?[]const u8 = null,
+ };
+
pub fn create(
allocator: *Allocator,
zig_exe: []const u8,
@@ -192,7 +198,7 @@ pub const Builder = struct {
}
/// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
- pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8) void {
+ pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void {
if (self.dest_dir) |dest_dir| {
self.install_prefix = install_prefix orelse "/usr";
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 {
(fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
self.install_path = self.install_prefix;
}
- self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
- self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
- self.h_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "include" }) catch unreachable;
+
+ var lib_list = [_][]const u8{ self.install_path, "lib" };
+ var exe_list = [_][]const u8{ self.install_path, "bin" };
+ var h_list = [_][]const u8{ self.install_path, "include" };
+
+ if (dir_list.lib_dir) |dir| {
+ if (std.fs.path.isAbsolute(dir)) lib_list[0] = self.dest_dir orelse "";
+ lib_list[1] = dir;
+ }
+
+ if (dir_list.exe_dir) |dir| {
+ if (std.fs.path.isAbsolute(dir)) exe_list[0] = self.dest_dir orelse "";
+ exe_list[1] = dir;
+ }
+
+ if (dir_list.include_dir) |dir| {
+ if (std.fs.path.isAbsolute(dir)) h_list[0] = self.dest_dir orelse "";
+ h_list[1] = dir;
+ }
+
+ self.lib_dir = fs.path.join(self.allocator, &lib_list) catch unreachable;
+ self.exe_dir = fs.path.join(self.allocator, &exe_list) catch unreachable;
+ self.h_dir = fs.path.join(self.allocator, &h_list) catch unreachable;
}
fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource {