Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/build_runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub fn main() !void {
return usageAndErr(builder, false, stderr_stream);
};
builder.libc_file = libc_file;
} else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) {
builder.quiet = true;
} else if (mem.eql(u8, arg, "--color")) {
const next_arg = nextArg(args, &arg_idx) orelse {
std.debug.print("expected [auto|on|off] after --color", .{});
Expand Down Expand Up @@ -285,6 +287,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
\\ Windows programs on Linux hosts. (default: no)
\\
\\ -h, --help Print this help and exit
\\ -q, --quiet Disable progress output during compilation
\\ --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
Expand Down
6 changes: 6 additions & 0 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub const Builder = struct {
verbose_llvm_cpu_features: bool,
/// The purpose of executing the command is for a human to read compile errors from the terminal
prominent_compile_errors: bool,
quiet: bool,
color: enum { auto, on, off } = .auto,
reference_trace: ?u32 = null,
use_stage1: ?bool = null,
Expand Down Expand Up @@ -188,6 +189,7 @@ pub const Builder = struct {
.verbose_cimport = false,
.verbose_llvm_cpu_features = false,
.prominent_compile_errors = false,
.quiet = false,
.invalid_user_input = false,
.allocator = allocator,
.user_input_options = UserInputOptionsMap.init(allocator),
Expand Down Expand Up @@ -2449,6 +2451,10 @@ pub const LibExeObjStep = struct {
};
zig_args.append(cmd) catch unreachable;

if (builder.quiet) {
try zig_args.append("-q");
}

if (builder.color != .auto) {
try zig_args.append("--color");
try zig_args.append(@tagName(builder.color));
Expand Down
10 changes: 9 additions & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ crt_files: std.StringHashMapUnmanaged(CRTFile) = .{},
/// Keeping track of this possibly open resource so we can close it later.
owned_link_dir: ?std.fs.Dir,

quiet: bool,

/// This is for stage1 and should be deleted upon completion of self-hosting.
/// Don't use this for anything other than stage1 compatibility.
color: Color = .auto,
Expand Down Expand Up @@ -987,6 +989,7 @@ pub const InitOptions = struct {
libc_installation: ?*const LibCInstallation = null,
machine_code_model: std.builtin.CodeModel = .default,
clang_preprocessor_mode: ClangPreprocessorMode = .no,
quiet: bool,
/// This is for stage1 and should be deleted upon completion of self-hosting.
color: Color = .auto,
reference_trace: ?u32 = null,
Expand Down Expand Up @@ -1898,6 +1901,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
.verbose_llvm_cpu_features = options.verbose_llvm_cpu_features,
.disable_c_depfile = options.disable_c_depfile,
.owned_link_dir = owned_link_dir,
.quiet = options.quiet,
.color = options.color,
.reference_trace = options.reference_trace,
.time_report = options.time_report,
Expand Down Expand Up @@ -2320,7 +2324,9 @@ pub fn update(comp: *Compilation) !void {
var progress: std.Progress = .{ .dont_print_on_dumb = true };
const main_progress_node = progress.start("", 0);
defer main_progress_node.end();
if (comp.color == .off) progress.terminal = null;
if (comp.quiet)
// Disable progress output entirely
progress.terminal = null;

try comp.performAllTheWork(main_progress_node);

Expand Down Expand Up @@ -5177,6 +5183,7 @@ fn buildOutputFromZig(
.want_pie = comp.bin_file.options.pie,
.emit_h = null,
.strip = comp.compilerRtStrip(),
.quiet = comp.quiet,
.is_native_os = comp.bin_file.options.is_native_os,
.is_native_abi = comp.bin_file.options.is_native_abi,
.self_exe_path = comp.self_exe_path,
Expand Down Expand Up @@ -5460,6 +5467,7 @@ pub fn build_crt_file(
.Lib => comp.bin_file.options.lto,
.Obj, .Exe => false,
},
.quiet = comp.quiet,
.emit_h = null,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
Expand Down
1 change: 1 addition & 0 deletions src/glibc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ fn buildSharedLib(
.want_tsan = false,
.emit_h = null,
.strip = comp.compilerRtStrip(),
.quiet = comp.quiet,
.is_native_os = false,
.is_native_abi = false,
.self_exe_path = comp.self_exe_path,
Expand Down
2 changes: 2 additions & 0 deletions src/libcxx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn buildLibCXX(comp: *Compilation) !void {
.want_lto = comp.bin_file.options.lto,
.function_sections = comp.bin_file.options.function_sections,
.emit_h = null,
.quiet = comp.quiet,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
.is_native_abi = comp.bin_file.options.is_native_abi,
Expand Down Expand Up @@ -389,6 +390,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
.want_lto = comp.bin_file.options.lto,
.function_sections = comp.bin_file.options.function_sections,
.emit_h = null,
.quiet = comp.quiet,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
.is_native_abi = comp.bin_file.options.is_native_abi,
Expand Down
1 change: 1 addition & 0 deletions src/libtsan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub fn buildTsan(comp: *Compilation) !void {
.want_pic = true,
.want_pie = true,
.emit_h = null,
.quiet = comp.quiet,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
.is_native_abi = comp.bin_file.options.is_native_abi,
Expand Down
1 change: 1 addition & 0 deletions src/libunwind.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub fn buildStaticLib(comp: *Compilation) !void {
.want_lto = false,
.function_sections = comp.bin_file.options.function_sections,
.emit_h = null,
.quiet = comp.quiet,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
.is_native_abi = comp.bin_file.options.is_native_abi,
Expand Down
9 changes: 9 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ const usage_build_generic =
\\
\\General Options:
\\ -h, --help Print this help and exit
\\ -q, --quiet Disable progress output during compilation
\\ --watch Enable compiler REPL
\\ --color [auto|off|on] Enable or disable colored error messages
\\ -femit-bin[=path] (default) Output machine code
Expand Down Expand Up @@ -634,6 +635,7 @@ fn buildOutputType(
var strip: ?bool = null;
var function_sections = false;
var no_builtin = false;
var quiet = false;
var watch = false;
var debug_compile_errors = false;
var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
Expand Down Expand Up @@ -916,6 +918,8 @@ fn buildOutputType(
if (mem.eql(u8, next_arg, "--")) break;
try extra_cflags.append(next_arg);
}
} else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) {
quiet = true;
} else if (mem.eql(u8, arg, "--color")) {
const next_arg = args_iter.next() orelse {
fatal("expected [auto|on|off] after --color", .{});
Expand Down Expand Up @@ -2928,6 +2932,7 @@ fn buildOutputType(
.verbose_cimport = verbose_cimport,
.verbose_llvm_cpu_features = verbose_llvm_cpu_features,
.machine_code_model = machine_code_model,
.quiet = quiet,
.color = color,
.time_report = time_report,
.stack_report = stack_report,
Expand Down Expand Up @@ -3713,6 +3718,7 @@ pub const usage_build =
pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
var prominent_compile_errors: bool = false;
var use_stage1: ?bool = null;
var quiet: bool = false;

// We want to release all the locks before executing the child process, so we make a nice
// big block here to ensure the cleanup gets run when we extract out our argv.
Expand Down Expand Up @@ -3779,6 +3785,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
try child_argv.append(arg);
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
try child_argv.append(arg);
} else if (mem.eql(u8, arg, "-q") or mem.eql(u8, arg, "--quiet")) {
quiet = true;
}
}
try child_argv.append(arg);
Expand Down Expand Up @@ -3907,6 +3915,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
.main_pkg = &main_pkg,
.emit_bin = emit_bin,
.emit_h = null,
.quiet = quiet,
.optimize_mode = .Debug,
.self_exe_path = self_exe_path,
.thread_pool = &thread_pool,
Expand Down
1 change: 1 addition & 0 deletions src/musl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
.want_tsan = false,
.emit_h = null,
.strip = comp.compilerRtStrip(),
.quiet = comp.quiet,
.is_native_os = false,
.is_native_abi = false,
.self_exe_path = comp.self_exe_path,
Expand Down
1 change: 1 addition & 0 deletions src/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,7 @@ pub const TestContext = struct {
.emit_h = emit_h,
.main_pkg = &main_pkg,
.keep_source_files_loaded = true,
.quiet = false,
.is_native_os = case.target.isNativeOs(),
.is_native_abi = case.target.isNativeAbi(),
.dynamic_linker = target_info.dynamic_linker.get(),
Expand Down