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
103103 .enum_optional => comptime unreachable,
104104 .union_list => comptime unreachable,
105105 .length_prefixed_list => comptime unreachable,
106 .flag_list => comptime unreachable,
106107 .flag_union => comptime unreachable,
107108 .multi_list => comptime unreachable,
108109 } else if (std.enums.tagName(Field, field_value)) |name| {
......@@ -128,7 +129,7 @@ fn printValue(sc: *const ScannedConfig, s: *Serializer, comptime Field: type, fi
128129 try s.value(null, .{});
129130 }
130131 },
131 .length_prefixed_list, .flag_length_prefixed_list => {
132 .length_prefixed_list, .flag_length_prefixed_list, .flag_list => {
132133 try printValue(sc, s, @TypeOf(field_value.slice), field_value.slice);
133134 },
134135 .extended => @compileError("TODO"),
lib/compiler/configurer.zig+23-11
......@@ -308,40 +308,54 @@ const Serialize = struct {
308308 }
309309
310310 fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index {
311 log.err("TODO addCSourceFile trailing data", .{});
312311 const wc = s.wc;
312 const args = try initStringList(s, csf.flags);
313313 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFile, .{
314314 .flags = .{
315 .args_len = @intCast(csf.flags.len),
315 .args_len = @intCast(args.len),
316316 .lang = .init(csf.language),
317317 },
318318 .file = try addLazyPath(s, csf.file),
319 .args = .{ .slice = args },
319320 })));
320321 }
321322
322323 fn addCSourceFiles(s: *Serialize, csf: *const std.Build.Module.CSourceFiles) !Configuration.CSourceFiles.Index {
323 log.err("TODO addCSourceFiles trailing data", .{});
324324 const wc = s.wc;
325 const sub_paths = try initStringList(s, csf.files);
326 const args = try initStringList(s, csf.flags);
325327 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFiles, .{
326328 .flags = .{
327 .args_len = @intCast(csf.flags.len),
329 .args_len = @intCast(args.len),
328330 .lang = .init(csf.language),
329331 },
330332 .root = try addLazyPath(s, csf.root),
331 .files_len = @intCast(csf.files.len),
333 .sub_paths = .{ .slice = sub_paths },
334 .args = .{ .slice = args },
332335 })));
333336 }
334337
335338 fn addRcSourceFile(s: *Serialize, rsf: *const std.Build.Module.RcSourceFile) !Configuration.RcSourceFile.Index {
336 log.err("TODO addRcSourceFile trailing data", .{});
337339 const wc = s.wc;
340 const include_paths = try initLazyPathList(s, rsf.include_paths);
341 const args = try initStringList(s, rsf.flags);
338342 return @enumFromInt(try wc.addExtra(@as(Configuration.RcSourceFile, .{
343 .flags = .{
344 .args_len = @intCast(args.len),
345 .include_paths = include_paths.len != 0,
346 },
339347 .file = try addLazyPath(s, rsf.file),
340 .args_len = @intCast(rsf.flags.len),
341 .include_paths_len = @intCast(rsf.include_paths.len),
348 .include_paths = .{ .slice = include_paths },
349 .args = .{ .slice = args },
342350 })));
343351 }
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
345359 fn initStringList(s: *Serialize, list: []const []const u8) ![]const Configuration.String {
346360 const wc = s.wc;
347361 const result = try s.arena.alloc(Configuration.String, list.len);
......@@ -400,9 +414,7 @@ const Serialize = struct {
400414 .name = try wc.addString(name),
401415 };
402416
403 const lib_paths = try arena.alloc(Configuration.LazyPath, m.lib_paths.items.len);
404 for (lib_paths, m.lib_paths.items) |*dest, src| dest.* = try addLazyPath(s, src);
405
417 const lib_paths = try initLazyPathList(s, m.lib_paths.items);
406418 const c_macros = try initStringList(s, m.c_macros.items);
407419 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 {
13881388 pub const SearchStrategy = enum(u2) { paths_first, mode_first, no_fallback };
13891389};
13901390
1391/// Trailing:
1392/// * arg: String, // for each args_len
1393/// * sub_path: String, // for each files_len
13941391pub const CSourceFiles = struct {
13951392 flags: Flags,
13961393 root: LazyPath,
1397 files_len: u32,
1394 args: Storage.FlagList(.flags, .args_len, String),
1395 sub_paths: Storage.LengthPrefixedList(String),
13981396
13991397 pub const Index = enum(u32) {
14001398 _,
......@@ -1407,11 +1405,10 @@ pub const CSourceFiles = struct {
14071405 };
14081406};
14091407
1410/// Trailing:
1411/// * arg: String, // for each args_len
14121408pub const CSourceFile = struct {
14131409 flags: Flags,
14141410 file: LazyPath,
1411 args: Storage.FlagList(.flags, .args_len, String),
14151412
14161413 pub const Index = enum(u32) {
14171414 _,
......@@ -1424,17 +1421,21 @@ pub const CSourceFile = struct {
14241421 };
14251422};
14261423
1427/// Trailing:
1428/// * arg: String, // for each args_len
1429/// * include_path: String, // for each include_paths_len
14301424pub const RcSourceFile = struct {
1425 flags: Flags,
14311426 file: LazyPath,
1432 args_len: u32,
1433 include_paths_len: u32,
1427 args: Storage.FlagList(.flags, .args_len, String),
1428 include_paths: Storage.FlagLengthPrefixedList(.flags, .include_paths, LazyPath),
14341429
14351430 pub const Index = enum(u32) {
14361431 _,
14371432 };
1433
1434 pub const Flags = packed struct(u32) {
1435 /// C compiler CLI flags.
1436 args_len: u31,
1437 include_paths: bool,
1438 };
14381439};
14391440
14401441pub const OptionalCSourceLanguage = enum(u3) {
......@@ -1779,6 +1780,7 @@ pub const Storage = enum {
17791780 union_list,
17801781 flag_union,
17811782 multi_list,
1783 flag_list,
17821784
17831785 /// The presence of the field is determined by a boolean within a packed
17841786 /// struct.
......@@ -1887,6 +1889,26 @@ pub const Storage = enum {
18871889 };
18881890 }
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
18901912 /// The field contains a u32 length followed by that many items for the
18911913 /// first field, that many items for the second field, etc.
18921914 pub fn MultiList(comptime ElemArg: type) type {
......@@ -2059,6 +2081,13 @@ pub const Storage = enum {
20592081 defer i.* = data_start + len;
20602082 return .{ .slice = @ptrCast(buffer[data_start..][0..len]) };
20612083 },
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 },
20622091 .multi_list => {
20632092 const data_start = i.* + 1;
20642093 const len = buffer[data_start - 1];
......@@ -2122,7 +2151,10 @@ pub const Storage = enum {
21222151 },
21232152 .auto => switch (Field.storage) {
21242153 .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,
21262158 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".fields.len,
21272159 .union_list => Field.extraLen(field.len),
21282160 .flag_union => switch (field.u) {
......@@ -2195,6 +2227,11 @@ pub const Storage = enum {
21952227 @memcpy(buffer[i + 1 ..][0..len], @as([]const u32, @ptrCast(value.slice)));
21962228 return len + 1;
21972229 },
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 },
21982235 .multi_list => {
21992236 const len: u32 = @intCast(value.mal.len);
22002237 if (len == 0) return 0;