Commit 52ba2c3a43

Alexandros Naskos <alex_naskos@hotmail.com>
2020-10-03 18:26:21
Reintroduce progress bar when compiling C files
1 parent 9917b05
Changed files (1)
src/Compilation.zig
@@ -1149,7 +1149,15 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors {
     };
 }
 
-pub fn performAllTheWork(self: *Compilation) error{OutOfMemory}!void {
+pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemory }!void {
+    var progress: std.Progress = .{};
+    var main_progress_node = try progress.start("", null);
+    defer main_progress_node.end();
+    if (self.color == .Off) progress.terminal = null;
+
+    var c_comp_progress_node = main_progress_node.start("Compile C Objects", self.c_source_files.len);
+    defer c_comp_progress_node.end();
+
     while (self.work_queue.readItem()) |work_item| switch (work_item) {
         .codegen_decl => |decl| switch (decl.analysis) {
             .unreferenced => unreachable,
@@ -1226,7 +1234,7 @@ pub fn performAllTheWork(self: *Compilation) error{OutOfMemory}!void {
             };
         },
         .c_object => |c_object| {
-            self.updateCObject(c_object) catch |err| switch (err) {
+            self.updateCObject(c_object, &c_comp_progress_node) catch |err| switch (err) {
                 error.AnalysisFail => continue,
                 else => {
                     try self.failed_c_objects.ensureCapacity(self.gpa, self.failed_c_objects.items().len + 1);
@@ -1312,7 +1320,7 @@ pub fn performAllTheWork(self: *Compilation) error{OutOfMemory}!void {
             if (!build_options.is_stage1)
                 unreachable;
 
-            self.updateStage1Module() catch |err| {
+            self.updateStage1Module(main_progress_node) catch |err| {
                 fatal("unable to build stage1 zig object: {}", .{@errorName(err)});
             };
         },
@@ -1473,7 +1481,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
     };
 }
 
-fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
+fn updateCObject(comp: *Compilation, c_object: *CObject, c_comp_progress_node: *std.Progress.Node) !void {
     if (!build_options.have_llvm) {
         return comp.failCObj(c_object, "clang not available: compiler built without LLVM extensions", .{});
     }
@@ -1516,6 +1524,12 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
     const arena = &arena_allocator.allocator;
 
     const c_source_basename = std.fs.path.basename(c_object.src.src_path);
+
+    c_comp_progress_node.activate();
+    var child_progress_node = c_comp_progress_node.start(c_source_basename, null);
+    child_progress_node.activate();
+    defer child_progress_node.end();
+
     // Special case when doing build-obj for just one C file. When there are more than one object
     // file and building an object we need to link them together, but with just one it should go
     // directly to the output file.
@@ -2509,7 +2523,7 @@ fn buildStaticLibFromZig(comp: *Compilation, src_basename: []const u8, out: *?CR
     };
 }
 
-fn updateStage1Module(comp: *Compilation) !void {
+fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node) !void {
     const tracy = trace(@src());
     defer tracy.end();
 
@@ -2615,10 +2629,6 @@ fn updateStage1Module(comp: *Compilation) !void {
         .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null,
         .llvm_cpu_features = comp.bin_file.options.llvm_cpu_features.?,
     };
-    var progress: std.Progress = .{};
-    var main_progress_node = try progress.start("", null);
-    defer main_progress_node.end();
-    if (comp.color == .Off) progress.terminal = null;
 
     comp.stage1_cache_manifest = &man;