authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-24 19:41:27-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
loga180012dd2bdae6dd30e165e6c74923eeeeb95b7
tree8ae5abfa22c57925e42a0df1579cfdd52c06ce43
parent92803903f3e96995cc705087615bd67749757862

configurer: serialize 3 more Module fields


2 files changed, 89 insertions(+), 75 deletions(-)

lib/compiler/configure_runner.zig+82-71
......@@ -279,7 +279,7 @@ const Serialize = struct {
279279 return (try addOptionalLazyPathEnum(s, lp)).unwrap();
280280 }
281281
282 fn addLazyPath(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath {
282 fn addLazyPath(s: *Serialize, lp: std.Build.LazyPath) !Configuration.LazyPath {
283283 return @enumFromInt(@intFromEnum(try addOptionalLazyPathEnum(s, lp)));
284284 }
285285
......@@ -304,6 +304,86 @@ const Serialize = struct {
304304 for (result, list) |*dest, src| dest.* = try wc.addOptionalString(src);
305305 return result;
306306 }
307
308 fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {
309 if (s.module_map.get(m)) |index| return index;
310
311 const wc = s.wc;
312 const arena = s.arena;
313 const gpa = wc.gpa;
314
315 const lib_paths = try arena.alloc(Configuration.LazyPath, m.lib_paths.items.len);
316 for (lib_paths, m.lib_paths.items) |*dest, src| dest.* = try addLazyPath(s, src);
317
318 const c_macros = try initStringList(s, m.c_macros.items);
319 const export_symbol_names = try initStringList(s, m.export_symbol_names);
320
321 const import_table: Configuration.ImportTable = @enumFromInt(wc.extra.items.len);
322 const import_table_extra_len = 1 + 2 * m.import_table.entries.len;
323 try wc.extra.ensureUnusedCapacity(gpa, import_table_extra_len);
324 wc.extra.items.len += import_table_extra_len;
325 wc.extra.appendAssumeCapacity(@intCast(m.import_table.entries.len));
326 wc.extra.items[@intFromEnum(import_table)] = @intCast(m.import_table.entries.len);
327 for (
328 m.import_table.keys(),
329 @intFromEnum(import_table) + 1..,
330 ) |mod_name, extra_index| {
331 wc.extra.items[extra_index] = @intFromEnum(try wc.addString(mod_name));
332 }
333 for (
334 m.import_table.values(),
335 @intFromEnum(import_table) + 1 + m.import_table.entries.len..,
336 ) |dep, extra_index| {
337 log.err("TODO module dependencies can be cyclic", .{});
338 wc.extra.items[extra_index] = @intFromEnum(try addModule(s, dep));
339 }
340
341 const module_index: Configuration.Module.Index = @enumFromInt(try wc.addExtra(@as(Configuration.Module, .{
342 .flags = .{
343 .optimize = .init(m.optimize),
344 .strip = .init(m.strip),
345 .unwind_tables = .init(m.unwind_tables),
346 .dwarf_format = .init(m.dwarf_format),
347 .single_threaded = .init(m.strip),
348 .stack_protector = .init(m.strip),
349 .stack_check = .init(m.strip),
350 .sanitize_c = .init(m.sanitize_c),
351 .sanitize_thread = .init(m.strip),
352 .fuzz = .init(m.strip),
353 .code_model = m.code_model,
354 .c_macros = c_macros.len != 0,
355 .include_dirs = m.include_dirs.items.len != 0,
356 .lib_paths = lib_paths.len != 0,
357 .rpaths = m.rpaths.items.len != 0,
358 .frameworks = m.frameworks.entries.len != 0,
359 .link_objects = m.link_objects.items.len != 0,
360 .export_symbol_names = export_symbol_names.len != 0,
361 },
362 .flags2 = .{
363 .valgrind = .init(m.strip),
364 .pic = .init(m.strip),
365 .red_zone = .init(m.strip),
366 .omit_frame_pointer = .init(m.strip),
367 .error_tracing = .init(m.strip),
368 .link_libc = .init(m.strip),
369 .link_libcpp = .init(m.strip),
370 .no_builtin = .init(m.strip),
371 },
372 .owner = try s.builderToPackage(m.owner),
373 .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file),
374 .import_table = import_table,
375 .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),
376 .c_macros = .{ .slice = c_macros },
377 .lib_paths = .{ .slice = lib_paths },
378 .export_symbol_names = .{ .slice = export_symbol_names },
379 })));
380
381 log.err("TODO serialize the trailing Module data", .{});
382
383 try s.module_map.putNoClobber(arena, m, module_index);
384
385 return module_index;
386 }
307387};
308388
309389fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
......@@ -479,7 +559,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
479559 .linker_script = c.linker_script != null,
480560 .version_script = c.version_script != null,
481561 },
482 .root_module = try addModule(&s, c.root_module),
562 .root_module = try s.addModule(c.root_module),
483563 .root_name = try wc.addString(c.name),
484564 .linker_script = .{ .value = try s.addOptionalLazyPath(c.linker_script) },
485565 .version_script = .{ .value = try s.addOptionalLazyPath(c.version_script) },
......@@ -612,75 +692,6 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
612692 });
613693}
614694
615fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {
616 if (s.module_map.get(m)) |index| return index;
617
618 const wc = s.wc;
619 const arena = s.arena;
620 const gpa = wc.gpa;
621 const import_table: Configuration.ImportTable = @enumFromInt(wc.extra.items.len);
622 const import_table_extra_len = 1 + 2 * m.import_table.entries.len;
623 try wc.extra.ensureUnusedCapacity(gpa, import_table_extra_len);
624 wc.extra.items.len += import_table_extra_len;
625 wc.extra.appendAssumeCapacity(@intCast(m.import_table.entries.len));
626 wc.extra.items[@intFromEnum(import_table)] = @intCast(m.import_table.entries.len);
627 for (
628 m.import_table.keys(),
629 @intFromEnum(import_table) + 1..,
630 ) |mod_name, extra_index| {
631 wc.extra.items[extra_index] = @intFromEnum(try wc.addString(mod_name));
632 }
633 for (
634 m.import_table.values(),
635 @intFromEnum(import_table) + 1 + m.import_table.entries.len..,
636 ) |dep, extra_index| {
637 log.err("TODO module dependencies can be cyclic", .{});
638 wc.extra.items[extra_index] = @intFromEnum(try addModule(s, dep));
639 }
640
641 const module_index: Configuration.Module.Index = @enumFromInt(try wc.addExtra(@as(Configuration.Module, .{
642 .flags = .{
643 .optimize = .init(m.optimize),
644 .strip = .init(m.strip),
645 .unwind_tables = .init(m.unwind_tables),
646 .dwarf_format = .init(m.dwarf_format),
647 .single_threaded = .init(m.strip),
648 .stack_protector = .init(m.strip),
649 .stack_check = .init(m.strip),
650 .sanitize_c = .init(m.sanitize_c),
651 .sanitize_thread = .init(m.strip),
652 .fuzz = .init(m.strip),
653 .code_model = m.code_model,
654 .c_macros = m.c_macros.items.len != 0,
655 .include_dirs = m.include_dirs.items.len != 0,
656 .lib_paths = m.lib_paths.items.len != 0,
657 .rpaths = m.rpaths.items.len != 0,
658 .frameworks = m.frameworks.entries.len != 0,
659 .link_objects = m.link_objects.items.len != 0,
660 .export_symbol_names = m.export_symbol_names.len != 0,
661
662 .valgrind = .init(m.strip),
663 .pic = .init(m.strip),
664 .red_zone = .init(m.strip),
665 .omit_frame_pointer = .init(m.strip),
666 .error_tracing = .init(m.strip),
667 .link_libc = .init(m.strip),
668 .link_libcpp = .init(m.strip),
669 .no_builtin = .init(m.strip),
670 },
671 .owner = try s.builderToPackage(m.owner),
672 .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file),
673 .import_table = import_table,
674 .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),
675 })));
676
677 log.err("TODO serialize the trailing Module data", .{});
678
679 try s.module_map.putNoClobber(arena, m, module_index);
680
681 return module_index;
682}
683
684695fn addOptionalResolvedTarget(
685696 wc: *Configuration.Wip,
686697 optional_resolved_target: ?std.Build.ResolvedTarget,
lib/std/zig/Configuration.zig+7-4
......@@ -1070,19 +1070,20 @@ pub const Package = struct {
10701070};
10711071
10721072/// Trailing:
1073/// * c_macros: LengthPrefixedList(String), // if flag is set
1074/// * lib_paths: LengthPrefixedList(LazyPath), // if flag is set
1075/// * export_symbol_names: LengthPrefixedList(String), // if flag is set
10761073/// * frameworks: FlagsPrefixedList(FrameworkFlags), // if flag is set
10771074/// * include_dirs: UnionList(IncludeDir), // if flag is set
10781075/// * rpaths: UnionList(RPath), // if flag is set
10791076/// * link_objects: UnionList(LinkObject), // if flag is set
10801077pub const Module = struct {
10811078 flags: Flags,
1079 flags2: Flags2,
10821080 owner: Package.Index,
10831081 root_source_file: OptionalLazyPath,
10841082 import_table: ImportTable,
10851083 resolved_target: ResolvedTarget.OptionalIndex,
1084 c_macros: Storage.FlagLengthPrefixedList(.flags, .c_macros, String),
1085 lib_paths: Storage.FlagLengthPrefixedList(.flags, .lib_paths, LazyPath),
1086 export_symbol_names: Storage.FlagLengthPrefixedList(.flags, .export_symbol_names, String),
10861087
10871088 pub const Optimize = enum(u3) {
10881089 debug,
......@@ -1148,7 +1149,7 @@ pub const Module = struct {
11481149 _,
11491150 };
11501151
1151 pub const Flags = packed struct(u64) {
1152 pub const Flags = packed struct(u32) {
11521153 optimize: Optimize,
11531154 strip: DefaultingBool,
11541155 unwind_tables: UnwindTables,
......@@ -1167,7 +1168,9 @@ pub const Module = struct {
11671168 frameworks: bool,
11681169 link_objects: bool,
11691170 export_symbol_names: bool,
1171 };
11701172
1173 pub const Flags2 = packed struct(u32) {
11711174 valgrind: DefaultingBool,
11721175 pic: DefaultingBool,
11731176 red_zone: DefaultingBool,