2017-03-31 10:48:15 +01:00
|
|
|
const root = @import("@build");
|
|
|
|
const std = @import("std");
|
2018-02-08 07:08:45 +00:00
|
|
|
const builtin = @import("builtin");
|
2017-03-31 10:48:15 +01:00
|
|
|
const io = std.io;
|
2017-04-06 10:34:04 +01:00
|
|
|
const fmt = std.fmt;
|
2017-03-31 10:48:15 +01:00
|
|
|
const Builder = std.build.Builder;
|
|
|
|
const mem = std.mem;
|
2019-05-26 18:17:34 +01:00
|
|
|
const process = std.process;
|
2017-05-04 19:05:06 +01:00
|
|
|
const ArrayList = std.ArrayList;
|
2019-05-25 03:52:07 +01:00
|
|
|
const File = std.fs.File;
|
2017-03-31 10:48:15 +01:00
|
|
|
|
2023-01-11 03:21:58 +00:00
|
|
|
pub const dependencies = @import("@dependencies");
|
|
|
|
|
2018-02-01 03:48:40 +00:00
|
|
|
pub fn main() !void {
|
2018-02-12 07:14:44 +00:00
|
|
|
// Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
|
|
|
|
// one shot program. We don't need to waste time freeing memory and finding places to squish
|
|
|
|
// bytes into. So we free everything all at once at the very end.
|
2019-11-25 22:25:06 +00:00
|
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
2018-02-12 07:14:44 +00:00
|
|
|
defer arena.deinit();
|
|
|
|
|
2021-10-29 02:08:41 +01:00
|
|
|
const allocator = arena.allocator();
|
2019-12-16 22:14:16 +00:00
|
|
|
var args = try process.argsAlloc(allocator);
|
|
|
|
defer process.argsFree(allocator, args);
|
2017-04-06 10:34:04 +01:00
|
|
|
|
2017-10-11 15:16:13 +01:00
|
|
|
// skip my own exe name
|
2019-12-16 22:14:16 +00:00
|
|
|
var arg_idx: usize = 1;
|
2017-10-11 15:16:13 +01:00
|
|
|
|
2019-12-16 22:14:16 +00:00
|
|
|
const zig_exe = nextArg(args, &arg_idx) orelse {
|
2022-04-19 22:40:27 +01:00
|
|
|
std.debug.print("Expected path to zig compiler\n", .{});
|
2017-10-11 15:16:13 +01:00
|
|
|
return error.InvalidArgs;
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
|
|
|
const build_root = nextArg(args, &arg_idx) orelse {
|
2022-04-19 22:40:27 +01:00
|
|
|
std.debug.print("Expected build root directory path\n", .{});
|
2017-10-11 15:16:13 +01:00
|
|
|
return error.InvalidArgs;
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
|
|
|
const cache_root = nextArg(args, &arg_idx) orelse {
|
2022-04-19 22:40:27 +01:00
|
|
|
std.debug.print("Expected cache root directory path\n", .{});
|
2017-10-11 15:16:13 +01:00
|
|
|
return error.InvalidArgs;
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
2020-12-01 15:47:47 +00:00
|
|
|
const global_cache_root = nextArg(args, &arg_idx) orelse {
|
2022-04-19 22:40:27 +01:00
|
|
|
std.debug.print("Expected global cache root directory path\n", .{});
|
2020-12-01 15:47:47 +00:00
|
|
|
return error.InvalidArgs;
|
|
|
|
};
|
2017-10-11 15:16:13 +01:00
|
|
|
|
2020-12-01 15:47:47 +00:00
|
|
|
const builder = try Builder.create(
|
|
|
|
allocator,
|
|
|
|
zig_exe,
|
|
|
|
build_root,
|
|
|
|
cache_root,
|
|
|
|
global_cache_root,
|
|
|
|
);
|
2019-07-04 20:32:44 +01:00
|
|
|
defer builder.destroy();
|
2017-04-06 10:34:04 +01:00
|
|
|
|
2017-05-04 19:05:06 +01:00
|
|
|
var targets = ArrayList([]const u8).init(allocator);
|
2021-11-25 06:08:16 +00:00
|
|
|
var debug_log_scopes = ArrayList([]const u8).init(allocator);
|
2017-04-06 10:34:04 +01:00
|
|
|
|
2021-01-06 01:57:18 +00:00
|
|
|
const stderr_stream = io.getStdErr().writer();
|
|
|
|
const stdout_stream = io.getStdOut().writer();
|
2017-10-31 08:47:55 +00:00
|
|
|
|
2021-03-22 12:11:45 +00:00
|
|
|
var install_prefix: ?[]const u8 = null;
|
2021-06-12 10:23:04 +01:00
|
|
|
var dir_list = Builder.DirList{};
|
|
|
|
|
2021-06-21 19:47:38 +01:00
|
|
|
// before arg parsing, check for the NO_COLOR environment variable
|
|
|
|
// if it exists, default the color setting to .off
|
|
|
|
// explicit --color arguments will still override this setting.
|
|
|
|
builder.color = if (std.process.hasEnvVarConstant("NO_COLOR")) .off else .auto;
|
|
|
|
|
2019-12-16 22:14:16 +00:00
|
|
|
while (nextArg(args, &arg_idx)) |arg| {
|
2017-04-06 18:59:11 +01:00
|
|
|
if (mem.startsWith(u8, arg, "-D")) {
|
2017-05-19 15:39:59 +01:00
|
|
|
const option_contents = arg[2..];
|
2017-04-06 10:34:04 +01:00
|
|
|
if (option_contents.len == 0) {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected option name after '-D'\n\n", .{});
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
2017-05-03 22:23:11 +01:00
|
|
|
if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
|
2017-05-19 15:39:59 +01:00
|
|
|
const option_name = option_contents[0..name_end];
|
2018-05-30 21:09:11 +01:00
|
|
|
const option_value = option_contents[name_end + 1 ..];
|
2018-08-03 22:22:17 +01:00
|
|
|
if (try builder.addUserInputOption(option_name, option_value))
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2017-04-06 10:34:04 +01:00
|
|
|
} else {
|
2018-08-03 22:22:17 +01:00
|
|
|
if (try builder.addUserInputFlag(option_contents))
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
} else if (mem.startsWith(u8, arg, "-")) {
|
|
|
|
if (mem.eql(u8, arg, "--verbose")) {
|
|
|
|
builder.verbose = true;
|
2020-11-18 11:58:27 +00:00
|
|
|
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
|
2019-11-13 01:36:07 +00:00
|
|
|
return usage(builder, false, stdout_stream);
|
2021-04-29 13:25:58 +01:00
|
|
|
} else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
|
2021-03-22 12:11:45 +00:00
|
|
|
install_prefix = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after {s}\n\n", .{arg});
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
2021-06-14 19:56:58 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
|
2021-06-12 10:23:04 +01:00
|
|
|
dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after {s}\n\n", .{arg});
|
2021-06-12 10:23:04 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
2021-06-14 19:56:58 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--prefix-exe-dir")) {
|
2021-06-12 10:23:04 +01:00
|
|
|
dir_list.exe_dir = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after {s}\n\n", .{arg});
|
2021-06-12 10:23:04 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
2021-06-14 19:56:58 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--prefix-include-dir")) {
|
2021-06-12 10:23:04 +01:00
|
|
|
dir_list.include_dir = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after {s}\n\n", .{arg});
|
2021-06-12 10:23:04 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
2021-06-25 13:04:38 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--sysroot")) {
|
|
|
|
const sysroot = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after --sysroot\n\n", .{});
|
2021-06-25 13:04:38 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
|
|
|
builder.sysroot = sysroot;
|
2017-12-24 01:21:57 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--search-prefix")) {
|
2019-12-16 22:14:16 +00:00
|
|
|
const search_prefix = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after --search-prefix\n\n", .{});
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
2017-12-24 01:21:57 +00:00
|
|
|
builder.addSearchPrefix(search_prefix);
|
2021-06-13 05:49:54 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--libc")) {
|
|
|
|
const libc_file = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after --libc\n\n", .{});
|
2021-06-13 05:49:54 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
|
|
|
builder.libc_file = libc_file;
|
2020-10-13 19:06:03 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--color")) {
|
|
|
|
const next_arg = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("expected [auto|on|off] after --color", .{});
|
2020-10-13 19:06:03 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
|
|
|
builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("expected [auto|on|off] after --color, found '{s}'", .{next_arg});
|
2020-10-13 19:06:03 +01:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
2021-06-14 19:33:27 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
|
2019-12-16 22:14:16 +00:00
|
|
|
builder.override_lib_dir = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after --zig-lib-dir\n\n", .{});
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2019-12-16 22:14:16 +00:00
|
|
|
};
|
2021-11-25 06:08:16 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--debug-log")) {
|
|
|
|
const next_arg = nextArg(args, &arg_idx) orelse {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Expected argument after {s}\n\n", .{arg});
|
2021-11-25 06:08:16 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
|
|
|
try debug_log_scopes.append(next_arg);
|
2022-11-30 17:14:04 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--debug-compile-errors")) {
|
|
|
|
builder.debug_compile_errors = true;
|
2021-12-02 22:42:59 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--glibc-runtimes")) {
|
|
|
|
builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse {
|
|
|
|
std.debug.print("Expected argument after --glibc-runtimes\n\n", .{});
|
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
|
|
|
};
|
2017-10-26 04:10:41 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--verbose-link")) {
|
|
|
|
builder.verbose_link = true;
|
2021-07-28 02:33:49 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--verbose-air")) {
|
|
|
|
builder.verbose_air = true;
|
2017-10-26 04:10:41 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
|
|
|
|
builder.verbose_llvm_ir = true;
|
|
|
|
} else if (mem.eql(u8, arg, "--verbose-cimport")) {
|
|
|
|
builder.verbose_cimport = true;
|
2019-03-18 17:47:59 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--verbose-cc")) {
|
|
|
|
builder.verbose_cc = true;
|
2020-02-25 01:11:33 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
|
|
|
|
builder.verbose_llvm_cpu_features = true;
|
2021-07-28 02:30:53 +01:00
|
|
|
} else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
|
|
|
|
builder.prominent_compile_errors = true;
|
2021-12-02 22:42:59 +00:00
|
|
|
} else if (mem.eql(u8, arg, "-fwine")) {
|
|
|
|
builder.enable_wine = true;
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-wine")) {
|
|
|
|
builder.enable_wine = false;
|
|
|
|
} else if (mem.eql(u8, arg, "-fqemu")) {
|
|
|
|
builder.enable_qemu = true;
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-qemu")) {
|
|
|
|
builder.enable_qemu = false;
|
|
|
|
} else if (mem.eql(u8, arg, "-fwasmtime")) {
|
|
|
|
builder.enable_wasmtime = true;
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-wasmtime")) {
|
|
|
|
builder.enable_wasmtime = false;
|
|
|
|
} else if (mem.eql(u8, arg, "-frosetta")) {
|
|
|
|
builder.enable_rosetta = true;
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-rosetta")) {
|
|
|
|
builder.enable_rosetta = false;
|
|
|
|
} else if (mem.eql(u8, arg, "-fdarling")) {
|
|
|
|
builder.enable_darling = true;
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-darling")) {
|
|
|
|
builder.enable_darling = false;
|
2022-09-09 16:55:58 +01:00
|
|
|
} else if (mem.eql(u8, arg, "-freference-trace")) {
|
|
|
|
builder.reference_trace = 256;
|
|
|
|
} else if (mem.startsWith(u8, arg, "-freference-trace=")) {
|
|
|
|
const num = arg["-freference-trace=".len..];
|
|
|
|
builder.reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {
|
|
|
|
std.debug.print("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) });
|
|
|
|
process.exit(1);
|
|
|
|
};
|
|
|
|
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
|
|
|
|
builder.reference_trace = null;
|
2019-12-16 22:14:16 +00:00
|
|
|
} else if (mem.eql(u8, arg, "--")) {
|
|
|
|
builder.args = argsRest(args, arg_idx);
|
|
|
|
break;
|
2017-04-06 10:34:04 +01:00
|
|
|
} else {
|
2021-11-30 07:13:07 +00:00
|
|
|
std.debug.print("Unrecognized argument: {s}\n\n", .{arg});
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, false, stderr_stream);
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-15 05:01:02 +00:00
|
|
|
try targets.append(arg);
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-25 06:08:16 +00:00
|
|
|
builder.debug_log_scopes = debug_log_scopes.items;
|
2021-06-12 10:23:04 +01:00
|
|
|
builder.resolveInstallPrefix(install_prefix, dir_list);
|
2023-01-11 03:21:58 +00:00
|
|
|
try builder.runBuild(root);
|
2017-04-06 10:34:04 +01:00
|
|
|
|
|
|
|
if (builder.validateUserInputDidItFail())
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, true, stderr_stream);
|
2017-04-06 10:34:04 +01:00
|
|
|
|
2020-11-06 18:54:08 +00:00
|
|
|
builder.make(targets.items) catch |err| {
|
2018-07-08 01:31:50 +01:00
|
|
|
switch (err) {
|
|
|
|
error.InvalidStepName => {
|
2019-11-13 01:36:07 +00:00
|
|
|
return usageAndErr(builder, true, stderr_stream);
|
2018-07-08 01:31:50 +01:00
|
|
|
},
|
2022-04-28 22:11:53 +01:00
|
|
|
error.UncleanExit => process.exit(1),
|
2018-07-08 01:31:50 +01:00
|
|
|
else => return err,
|
2017-04-30 18:01:35 +01:00
|
|
|
}
|
|
|
|
};
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
|
2020-07-11 12:09:04 +01:00
|
|
|
fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
|
2017-04-06 10:34:04 +01:00
|
|
|
// run the build script to collect the options
|
|
|
|
if (!already_ran_build) {
|
2021-06-12 10:23:04 +01:00
|
|
|
builder.resolveInstallPrefix(null, .{});
|
2023-01-11 03:21:58 +00:00
|
|
|
try builder.runBuild(root);
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
|
2018-01-07 21:51:46 +00:00
|
|
|
try out_stream.print(
|
2020-11-26 12:28:38 +00:00
|
|
|
\\Usage: {s} build [steps] [options]
|
2017-04-13 22:21:00 +01:00
|
|
|
\\
|
|
|
|
\\Steps:
|
|
|
|
\\
|
2019-12-09 03:53:51 +00:00
|
|
|
, .{builder.zig_exe});
|
2017-04-13 22:21:00 +01:00
|
|
|
|
|
|
|
const allocator = builder.allocator;
|
2020-11-06 18:54:08 +00:00
|
|
|
for (builder.top_level_steps.items) |top_level_step| {
|
2019-07-04 20:32:44 +01:00
|
|
|
const name = if (&top_level_step.step == builder.default_step)
|
2020-11-26 12:28:38 +00:00
|
|
|
try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
|
2019-07-04 20:32:44 +01:00
|
|
|
else
|
|
|
|
top_level_step.step.name;
|
2021-07-28 02:30:53 +01:00
|
|
|
try out_stream.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
|
2017-04-13 22:21:00 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 00:22:30 +00:00
|
|
|
try out_stream.writeAll(
|
2017-04-06 10:34:04 +01:00
|
|
|
\\
|
|
|
|
\\General Options:
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ -p, --prefix [path] Override default install prefix
|
|
|
|
\\ --prefix-lib-dir [path] Override default library directory path
|
|
|
|
\\ --prefix-exe-dir [path] Override default executable directory path
|
|
|
|
\\ --prefix-include-dir [path] Override default include directory path
|
2021-06-14 19:56:58 +01:00
|
|
|
\\
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ --sysroot [path] Set the system root directory (usually /)
|
|
|
|
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
|
|
|
|
\\ --libc [file] Provide a file which specifies libc paths
|
2021-06-14 19:56:58 +01:00
|
|
|
\\
|
2021-12-02 22:42:59 +00:00
|
|
|
\\ -fdarling, -fno-darling Integration with system-installed Darling to
|
|
|
|
\\ execute macOS programs on Linux hosts
|
|
|
|
\\ (default: no)
|
|
|
|
\\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
|
|
|
|
\\ foreign-architecture programs on Linux hosts
|
|
|
|
\\ (default: no)
|
|
|
|
\\ --glibc-runtimes [path] Enhances QEMU integration by providing glibc built
|
|
|
|
\\ for multiple foreign architectures, allowing
|
|
|
|
\\ execution of non-native programs that link with glibc.
|
|
|
|
\\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
|
|
|
|
\\ ARM64 macOS hosts. (default: no)
|
|
|
|
\\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to
|
|
|
|
\\ execute WASI binaries. (default: no)
|
|
|
|
\\ -fwine, -fno-wine Integration with system-installed Wine to execute
|
|
|
|
\\ Windows programs on Linux hosts. (default: no)
|
|
|
|
\\
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ -h, --help Print this help and exit
|
|
|
|
\\ --verbose Print commands before executing them
|
|
|
|
\\ --color [auto|off|on] Enable or disable colored error messages
|
|
|
|
\\ --prominent-compile-errors Output compile errors formatted for a human to read
|
2017-04-06 10:34:04 +01:00
|
|
|
\\
|
|
|
|
\\Project-Specific Options:
|
|
|
|
\\
|
2017-04-13 22:21:00 +01:00
|
|
|
);
|
2017-04-06 10:34:04 +01:00
|
|
|
|
2020-04-01 23:00:42 +01:00
|
|
|
if (builder.available_options_list.items.len == 0) {
|
2019-12-09 03:53:51 +00:00
|
|
|
try out_stream.print(" (none)\n", .{});
|
2017-04-06 10:34:04 +01:00
|
|
|
} else {
|
2020-11-06 18:54:08 +00:00
|
|
|
for (builder.available_options_list.items) |option| {
|
2020-11-26 12:28:38 +00:00
|
|
|
const name = try fmt.allocPrint(allocator, " -D{s}=[{s}]", .{
|
2019-12-09 03:53:51 +00:00
|
|
|
option.name,
|
2021-06-11 09:50:48 +01:00
|
|
|
@tagName(option.type_id),
|
2019-12-09 03:53:51 +00:00
|
|
|
});
|
2017-04-06 10:34:04 +01:00
|
|
|
defer allocator.free(name);
|
2021-07-28 02:30:53 +01:00
|
|
|
try out_stream.print("{s:<30} {s}\n", .{ name, option.description });
|
2021-08-31 02:39:02 +01:00
|
|
|
if (option.enum_options) |enum_options| {
|
|
|
|
const padding = " " ** 33;
|
|
|
|
try out_stream.writeAll(padding ++ "Supported Values:\n");
|
|
|
|
for (enum_options) |enum_option| {
|
|
|
|
try out_stream.print(padding ++ " {s}\n", .{enum_option});
|
|
|
|
}
|
|
|
|
}
|
2017-04-06 10:34:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 00:22:30 +00:00
|
|
|
try out_stream.writeAll(
|
2017-10-26 04:10:41 +01:00
|
|
|
\\
|
|
|
|
\\Advanced Options:
|
2022-09-09 16:55:58 +01:00
|
|
|
\\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
|
|
|
|
\\ -fno-reference-trace Disable reference trace
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ --build-file [file] Override path to build.zig
|
2022-04-19 22:40:27 +01:00
|
|
|
\\ --cache-dir [path] Override path to local Zig cache directory
|
|
|
|
\\ --global-cache-dir [path] Override path to global Zig cache directory
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ --zig-lib-dir [arg] Override path to Zig lib directory
|
2021-11-25 06:08:16 +00:00
|
|
|
\\ --debug-log [scope] Enable debugging the compiler
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ --verbose-link Enable compiler debug output for linking
|
2021-07-28 02:33:49 +01:00
|
|
|
\\ --verbose-air Enable compiler debug output for Zig AIR
|
2021-07-28 02:30:53 +01:00
|
|
|
\\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
|
|
|
|
\\ --verbose-cimport Enable compiler debug output for C imports
|
|
|
|
\\ --verbose-cc Enable compiler debug output for C compilation
|
|
|
|
\\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
|
2017-10-26 04:10:41 +01:00
|
|
|
\\
|
|
|
|
);
|
2017-10-31 08:47:55 +00:00
|
|
|
}
|
2017-10-26 04:10:41 +01:00
|
|
|
|
2020-07-11 12:09:04 +01:00
|
|
|
fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: anytype) void {
|
2018-01-07 22:28:20 +00:00
|
|
|
usage(builder, already_ran_build, out_stream) catch {};
|
2019-05-26 18:17:34 +01:00
|
|
|
process.exit(1);
|
2017-03-31 10:48:15 +01:00
|
|
|
}
|
2017-10-11 15:16:13 +01:00
|
|
|
|
2019-12-16 22:14:16 +00:00
|
|
|
fn nextArg(args: [][]const u8, idx: *usize) ?[]const u8 {
|
|
|
|
if (idx.* >= args.len) return null;
|
|
|
|
defer idx.* += 1;
|
|
|
|
return args[idx.*];
|
|
|
|
}
|
2018-02-08 07:08:45 +00:00
|
|
|
|
2019-12-16 22:14:16 +00:00
|
|
|
fn argsRest(args: [][]const u8, idx: usize) ?[][]const u8 {
|
|
|
|
if (idx >= args.len) return null;
|
|
|
|
return args[idx..];
|
2017-10-11 15:16:13 +01:00
|
|
|
}
|