authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-02 20:56:48-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
log6c61803d8b7281ffb4517cfbc335e4e0dfcdea66
tree0feea82ce8940641dcff86bd98ab059b36204efb
parent8aec13b6ab1f0a8586f3e5cf5600d70697ac209d

maker: implement module printing


3 files changed, 65 insertions(+), 27 deletions(-)

lib/compiler/Maker.zig+14-4
......@@ -429,19 +429,29 @@ pub fn main(init: process.Init.Minimal) !void {
429429 break :c Configuration.loadFile(arena, io, file) catch |err|
430430 fatal("failed to load configuration file {s}: {t}", .{ configure_path, err });
431431 };
432 const c = &configuration;
432433 var top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index) = .empty;
434 var modules: std.AutoArrayHashMapUnmanaged(Configuration.Module.Index, void) = .empty;
433435 for (configuration.steps, 0..) |*conf_step, step_index_usize| {
434436 if (conf_step.owner != .root) continue;
435437 const step_index: Configuration.Step.Index = @enumFromInt(step_index_usize);
436 const flags = conf_step.flags(&configuration);
437 if (flags.tag == .top_level) {
438 const name = step_index.ptr(&configuration).name.slice(&configuration);
439 try top_level_steps.put(arena, name, step_index);
438 const flags = conf_step.flags(c);
439 switch (flags.tag) {
440 .top_level => {
441 const name = step_index.ptr(c).name.slice(c);
442 try top_level_steps.put(arena, name, step_index);
443 },
444 .compile => {
445 const root_module = step_index.ptr(c).extended.get(configuration.extra).compile.root_module;
446 try modules.put(arena, root_module, {});
447 },
448 else => {},
440449 }
441450 }
442451 break :sc .{
443452 .configuration = configuration,
444453 .top_level_steps = top_level_steps,
454 .modules = modules,
445455 };
446456 };
447457
lib/compiler/Maker/ScannedConfig.zig+49-21
......@@ -9,13 +9,13 @@ const Graph = @import("Graph.zig");
99
1010configuration: Configuration,
1111top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index),
12modules: std.AutoArrayHashMapUnmanaged(Configuration.Module.Index, void),
1213
1314pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
1415 std.log.err("TODO also print paths", .{});
1516 std.log.err("TODO also print unlazy deps", .{});
1617 std.log.err("TODO also print system integrations", .{});
1718 std.log.err("TODO also print available options", .{});
18 std.log.err("TODO also print modules", .{});
1919 const c = &sc.configuration;
2020 var serializer: Serializer = .{ .writer = w };
2121 var s = try serializer.beginStruct(.{});
......@@ -31,7 +31,7 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
3131
3232 {
3333 var tf = try s.beginTupleField("steps", .{});
34 for (c.steps) |*step| {
34 for (c.steps) |step| {
3535 var step_field = try tf.beginStructField(.{});
3636 try printStruct(sc, &step_field, Configuration.Step, step);
3737 try step_field.end();
......@@ -39,10 +39,23 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
3939 try tf.end();
4040 }
4141
42 {
43 var sf = try s.beginStructField("modules", .{});
44
45 for (sc.modules.keys()) |module_index| {
46 var int_buf: [50]u8 = undefined;
47 const int_str = std.fmt.bufPrint(&int_buf, "{d}", .{module_index}) catch unreachable;
48 var step_field = try sf.beginStructField(int_str, .{});
49 try printStruct(sc, &step_field, Configuration.Module, module_index.get(c));
50 try step_field.end();
51 }
52 try sf.end();
53 }
54
4255 try s.end();
4356}
4457
45fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: *const S) !void {
58fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void {
4659 inline for (@typeInfo(S).@"struct".fields) |field| {
4760 try s.fieldPrefix(field.name);
4861 try printValue(sc, s.container.serializer, field.type, @field(v, field.name));
......@@ -78,7 +91,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
7891 if (@hasDecl(Field, "storage")) switch (Field.storage) {
7992 .extended => {
8093 var sub_struct = try s.beginStruct(.{});
81 try printTaggedUnion(sc, &sub_struct, field_value.get(c.extra));
94 switch (field_value.get(c.extra)) {
95 inline else => |u| {
96 try printStruct(sc, &sub_struct, @TypeOf(u), u);
97 },
98 }
8299 try sub_struct.end();
83100 },
84101 .flag_optional => comptime unreachable,
......@@ -98,6 +115,11 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
98115 .@"packed" => {
99116 try s.value(field_value, .{});
100117 },
118 .@"extern" => {
119 var sub_struct = try s.beginStruct(.{});
120 try printStruct(sc, &sub_struct, Field, field_value);
121 try sub_struct.end();
122 },
101123 .auto => switch (Field.storage) {
102124 .flag_optional, .enum_optional => {
103125 if (field_value.value) |some| {
......@@ -110,35 +132,41 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
110132 try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice);
111133 },
112134 .extended => @compileError("TODO"),
113 .union_list => @compileError("TODO"),
135 .union_list => {
136 var slice_field = try s.beginTuple(.{});
137 for (field_value.get(c.extra), 0..) |elem, i| switch (field_value.tag(c.extra, i)) {
138 inline else => |tag| {
139 var sub_struct = try s.beginStruct(.{});
140 try sub_struct.fieldPrefix(@tagName(tag));
141 try printValue(sc, s, @FieldType(Field.Union, @tagName(tag)), @enumFromInt(elem));
142 try sub_struct.end();
143 },
144 };
145 try slice_field.end();
146 },
114147 .flag_union => try printValue(sc, s, Field.Union, field_value.u),
115148 .multi_list => @compileError("TODO"),
116149 },
117 else => @compileError("not implemented: " ++ @typeName(Field)),
118150 },
119151 .@"union" => {
120 switch (field_value) {
121 inline else => |u, tag| {
122 if (@TypeOf(u) == void) {
123 try s.ident(@tagName(tag));
124 } else {
125 var sub_struct = try s.beginStruct(.{});
126 try sub_struct.fieldPrefix(@tagName(tag));
127 try printValue(sc, s, @TypeOf(u), u);
128 try sub_struct.end();
129 }
130 },
131 }
152 try printTaggedUnion(sc, s, field_value);
132153 },
133154 else => @compileError("not implemented: " ++ @typeName(Field)),
134155 },
135156 }
136157}
137158
138fn printTaggedUnion(sc: *const ScannedConfig, s: *Serializer.Struct, value: anytype) !void {
159fn printTaggedUnion(sc: *const ScannedConfig, s: *Serializer, value: anytype) !void {
139160 switch (value) {
140 inline else => |*u| {
141 try printStruct(sc, s, @TypeOf(u.*), u);
161 inline else => |u, tag| {
162 if (@TypeOf(u) == void) {
163 try s.ident(@tagName(tag));
164 } else {
165 var sub_struct = try s.beginStruct(.{});
166 try sub_struct.fieldPrefix(@tagName(tag));
167 try printValue(sc, s, @TypeOf(u), u);
168 try sub_struct.end();
169 }
142170 },
143171 }
144172}
lib/std/zig/Configuration.zig+2-2
......@@ -1219,7 +1219,7 @@ pub const Module = struct {
12191219 win32_resource_file: RcSourceFile.Index,
12201220 };
12211221
1222 pub const Framework = struct {
1222 pub const Framework = extern struct {
12231223 flags: @This().Flags,
12241224 name: String,
12251225
......@@ -2122,7 +2122,7 @@ pub const Storage = enum {
21222122 },
21232123 .auto => switch (Field.storage) {
21242124 .flag_optional, .enum_optional, .extended => 1,
2125 .length_prefixed_list, .flag_length_prefixed_list => field.slice.len + 1,
2125 .length_prefixed_list, .flag_length_prefixed_list => 1 + @divExact(@sizeOf(Field.Elem), @sizeOf(u32)) * field.slice.len,
21262126 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".fields.len,
21272127 .union_list => Field.extraLen(field.len),
21282128 .flag_union => switch (field.u) {