authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-04 17:40:17-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
log8f36a83b45eedef92b3fcda605e0ccb3828ddbd3
tree90027cc2968f3930f296c8e46785cbaf72b74cd9
parent6c61803d8b7281ffb4517cfbc335e4e0dfcdea66

Configuration: serialize remaining CSourceFiles information


3 files changed, 74 insertions(+), 24 deletions(-)

lib/compiler/Maker/ScannedConfig.zig+2-1
...@@ -103,6 +103,7 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi...@@ -103,6 +103,7 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
103 .enum_optional => comptime unreachable,103 .enum_optional => comptime unreachable,
104 .union_list => comptime unreachable,104 .union_list => comptime unreachable,
105 .length_prefixed_list => comptime unreachable,105 .length_prefixed_list => comptime unreachable,
106 .flag_list => comptime unreachable,
106 .flag_union => comptime unreachable,107 .flag_union => comptime unreachable,
107 .multi_list => comptime unreachable,108 .multi_list => comptime unreachable,
108 } else if (std.enums.tagName(Field, field_value)) |name| {109 } else if (std.enums.tagName(Field, field_value)) |name| {
...@@ -128,7 +129,7 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi...@@ -128,7 +129,7 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
128 try s.value(null, .{});129 try s.value(null, .{});
129 }130 }
130 },131 },
131 .length_prefixed_list, .flag_length_prefixed_list => {132 .length_prefixed_list, .flag_length_prefixed_list, .flag_list => {
132 try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice);133 try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice);
133 },134 },
134 .extended => @compileError("TODO"),135 .extended => @compileError("TODO"),
lib/compiler/configurer.zig+23-11
...@@ -308,40 +308,54 @@ const Serialize = struct {...@@ -308,40 +308,54 @@ const Serialize = struct {
308 }308 }
309309
310 fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index {310 fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index {
311 log.err("TODO addCSourceFile trailing data", .{});
312 const wc = s.wc;311 const wc = s.wc;
312 const args = try initStringList(s, csf.flags);
313 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFile, .{313 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFile, .{
314 .flags = .{314 .flags = .{
315 .args_len = @intCast(csf.flags.len),315 .args_len = @intCast(args.len),
316 .lang = .init(csf.language),316 .lang = .init(csf.language),
317 },317 },
318 .file = try addLazyPath(s, csf.file),318 .file = try addLazyPath(s, csf.file),
319 .args = .{ .slice = args },
319 })));320 })));
320 }321 }
321322
322 fn addCSourceFiles(s: *Serialize, csf: *const std.Build.Module.CSourceFiles) !Configuration.CSourceFiles.Index {323 fn addCSourceFiles(s: *Serialize, csf: *const std.Build.Module.CSourceFiles) !Configuration.CSourceFiles.Index {
323 log.err("TODO addCSourceFiles trailing data", .{});
324 const wc = s.wc;324 const wc = s.wc;
325 const sub_paths = try initStringList(s, csf.files);
326 const args = try initStringList(s, csf.flags);
325 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFiles, .{327 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFiles, .{
326 .flags = .{328 .flags = .{
327 .args_len = @intCast(csf.flags.len),329 .args_len = @intCast(args.len),
328 .lang = .init(csf.language),330 .lang = .init(csf.language),
329 },331 },
330 .root = try addLazyPath(s, csf.root),332 .root = try addLazyPath(s, csf.root),
331 .files_len = @intCast(csf.files.len),333 .sub_paths = .{ .slice = sub_paths },
334 .args = .{ .slice = args },
332 })));335 })));
333 }336 }
334337
335 fn addRcSourceFile(s: *Serialize, rsf: *const std.Build.Module.RcSourceFile) !Configuration.RcSourceFile.Index {338 fn addRcSourceFile(s: *Serialize, rsf: *const std.Build.Module.RcSourceFile) !Configuration.RcSourceFile.Index {
336 log.err("TODO addRcSourceFile trailing data", .{});
337 const wc = s.wc;339 const wc = s.wc;
340 const include_paths = try initLazyPathList(s, rsf.include_paths);
341 const args = try initStringList(s, rsf.flags);
338 return @enumFromInt(try wc.addExtra(@as(Configuration.RcSourceFile, .{342 return @enumFromInt(try wc.addExtra(@as(Configuration.RcSourceFile, .{
343 .flags = .{
344 .args_len = @intCast(args.len),
345 .include_paths = include_paths.len != 0,
346 },
339 .file = try addLazyPath(s, rsf.file),347 .file = try addLazyPath(s, rsf.file),
340 .args_len = @intCast(rsf.flags.len),348 .include_paths = .{ .slice = include_paths },
341 .include_paths_len = @intCast(rsf.include_paths.len),349 .args = .{ .slice = args },
342 })));350 })));
343 }351 }
344352
353 fn initLazyPathList(s: *Serialize, list: []const std.Build.LazyPath) ![]const Configuration.LazyPath {
354 const result = try s.arena.alloc(Configuration.LazyPath, list.len);
355 for (result, list) |*dest, src| dest.* = try addLazyPath(s, src);
356 return result;
357 }
358
345 fn initStringList(s: *Serialize, list: []const []const u8) ![]const Configuration.String {359 fn initStringList(s: *Serialize, list: []const []const u8) ![]const Configuration.String {
346 const wc = s.wc;360 const wc = s.wc;
347 const result = try s.arena.alloc(Configuration.String, list.len);361 const result = try s.arena.alloc(Configuration.String, list.len);
...@@ -400,9 +414,7 @@ const Serialize = struct {...@@ -400,9 +414,7 @@ const Serialize = struct {
400 .name = try wc.addString(name),414 .name = try wc.addString(name),
401 };415 };
402416
403 const lib_paths = try arena.alloc(Configuration.LazyPath, m.lib_paths.items.len);417 const lib_paths = try initLazyPathList(s, m.lib_paths.items);
404 for (lib_paths, m.lib_paths.items) |*dest, src| dest.* = try addLazyPath(s, src);
405
406 const c_macros = try initStringList(s, m.c_macros.items);418 const c_macros = try initStringList(s, m.c_macros.items);
407 const export_symbol_names = try initStringList(s, m.export_symbol_names);419 const export_symbol_names = try initStringList(s, m.export_symbol_names);
408420
lib/std/zig/Configuration.zig+49-12
...@@ -1388,13 +1388,11 @@ pub const SystemLib = struct {...@@ -1388,13 +1388,11 @@ pub const SystemLib = struct {
1388 pub const SearchStrategy = enum(u2) { paths_first, mode_first, no_fallback };1388 pub const SearchStrategy = enum(u2) { paths_first, mode_first, no_fallback };
1389};1389};
13901390
1391/// Trailing:
1392/// * arg: String, // for each args_len
1393/// * sub_path: String, // for each files_len
1394pub const CSourceFiles = struct {1391pub const CSourceFiles = struct {
1395 flags: Flags,1392 flags: Flags,
1396 root: LazyPath,1393 root: LazyPath,
1397 files_len: u32,1394 args: Storage.FlagList(.flags, .args_len, String),
1395 sub_paths: Storage.LengthPrefixedList(String),
13981396
1399 pub const Index = enum(u32) {1397 pub const Index = enum(u32) {
1400 _,1398 _,
...@@ -1407,11 +1405,10 @@ pub const CSourceFiles = struct {...@@ -1407,11 +1405,10 @@ pub const CSourceFiles = struct {
1407 };1405 };
1408};1406};
14091407
1410/// Trailing:
1411/// * arg: String, // for each args_len
1412pub const CSourceFile = struct {1408pub const CSourceFile = struct {
1413 flags: Flags,1409 flags: Flags,
1414 file: LazyPath,1410 file: LazyPath,
1411 args: Storage.FlagList(.flags, .args_len, String),
14151412
1416 pub const Index = enum(u32) {1413 pub const Index = enum(u32) {
1417 _,1414 _,
...@@ -1424,17 +1421,21 @@ pub const CSourceFile = struct {...@@ -1424,17 +1421,21 @@ pub const CSourceFile = struct {
1424 };1421 };
1425};1422};
14261423
1427/// Trailing:
1428/// * arg: String, // for each args_len
1429/// * include_path: String, // for each include_paths_len
1430pub const RcSourceFile = struct {1424pub const RcSourceFile = struct {
1425 flags: Flags,
1431 file: LazyPath,1426 file: LazyPath,
1432 args_len: u32,1427 args: Storage.FlagList(.flags, .args_len, String),
1433 include_paths_len: u32,1428 include_paths: Storage.FlagLengthPrefixedList(.flags, .include_paths, LazyPath),
14341429
1435 pub const Index = enum(u32) {1430 pub const Index = enum(u32) {
1436 _,1431 _,
1437 };1432 };
1433
1434 pub const Flags = packed struct(u32) {
1435 /// C compiler CLI flags.
1436 args_len: u31,
1437 include_paths: bool,
1438 };
1438};1439};
14391440
1440pub const OptionalCSourceLanguage = enum(u3) {1441pub const OptionalCSourceLanguage = enum(u3) {
...@@ -1779,6 +1780,7 @@ pub const Storage = enum {...@@ -1779,6 +1780,7 @@ pub const Storage = enum {
1779 union_list,1780 union_list,
1780 flag_union,1781 flag_union,
1781 multi_list,1782 multi_list,
1783 flag_list,
17821784
1783 /// The presence of the field is determined by a boolean within a packed1785 /// The presence of the field is determined by a boolean within a packed
1784 /// struct.1786 /// struct.
...@@ -1887,6 +1889,26 @@ pub const Storage = enum {...@@ -1887,6 +1889,26 @@ pub const Storage = enum {
1887 };1889 };
1888 }1890 }
18891891
1892 /// The field is a list whose length is an integer inside flags.
1893 pub fn FlagList(
1894 comptime flags_arg: @EnumLiteral(),
1895 comptime flag_arg: @EnumLiteral(),
1896 comptime ElemArg: type,
1897 ) type {
1898 return struct {
1899 slice: []const Elem,
1900
1901 pub const storage: Storage = .flag_list;
1902 pub const flags = flags_arg;
1903 pub const flag = flag_arg;
1904 pub const Elem = ElemArg;
1905
1906 pub fn initErased(s: []const u32) @This() {
1907 return .{ .slice = @ptrCast(s) };
1908 }
1909 };
1910 }
1911
1890 /// The field contains a u32 length followed by that many items for the1912 /// The field contains a u32 length followed by that many items for the
1891 /// first field, that many items for the second field, etc.1913 /// first field, that many items for the second field, etc.
1892 pub fn MultiList(comptime ElemArg: type) type {1914 pub fn MultiList(comptime ElemArg: type) type {
...@@ -2059,6 +2081,13 @@ pub const Storage = enum {...@@ -2059,6 +2081,13 @@ pub const Storage = enum {
2059 defer i.* = data_start + len;2081 defer i.* = data_start + len;
2060 return .{ .slice = @ptrCast(buffer[data_start..][0..len]) };2082 return .{ .slice = @ptrCast(buffer[data_start..][0..len]) };
2061 },2083 },
2084 .flag_list => {
2085 const flags = @field(container, @tagName(Field.flags));
2086 const len: u32 = @field(flags, @tagName(Field.flag));
2087 const data_start = i.*;
2088 defer i.* = data_start + len;
2089 return .{ .slice = @ptrCast(buffer[data_start..][0..len]) };
2090 },
2062 .multi_list => {2091 .multi_list => {
2063 const data_start = i.* + 1;2092 const data_start = i.* + 1;
2064 const len = buffer[data_start - 1];2093 const len = buffer[data_start - 1];
...@@ -2122,7 +2151,10 @@ pub const Storage = enum {...@@ -2122,7 +2151,10 @@ pub const Storage = enum {
2122 },2151 },
2123 .auto => switch (Field.storage) {2152 .auto => switch (Field.storage) {
2124 .flag_optional, .enum_optional, .extended => 1,2153 .flag_optional, .enum_optional, .extended => 1,
2125 .length_prefixed_list, .flag_length_prefixed_list => 1 + @divExact(@sizeOf(Field.Elem), @sizeOf(u32)) * field.slice.len,2154 .length_prefixed_list,
2155 .flag_length_prefixed_list,
2156 .flag_list,
2157 => 1 + @divExact(@sizeOf(Field.Elem), @sizeOf(u32)) * field.slice.len,
2126 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".fields.len,2158 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".fields.len,
2127 .union_list => Field.extraLen(field.len),2159 .union_list => Field.extraLen(field.len),
2128 .flag_union => switch (field.u) {2160 .flag_union => switch (field.u) {
...@@ -2195,6 +2227,11 @@ pub const Storage = enum {...@@ -2195,6 +2227,11 @@ pub const Storage = enum {
2195 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));2227 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
2196 return len + 1;2228 return len + 1;
2197 },2229 },
2230 .flag_list => {
2231 const len: u32 = @intCast(value.slice.len);
2232 @memcpy(buffer[i..][0..len], @as([]const u32, @ptrCast(value.slice)));
2233 return len;
2234 },
2198 .multi_list => {2235 .multi_list => {
2199 const len: u32 = @intCast(value.mal.len);2236 const len: u32 = @intCast(value.mal.len);
2200 if (len == 0) return 0;2237 if (len == 0) return 0;