authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-14 01:24:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-14 12:40:19+02:00
log5d7cf3f34d13f70de35c2f76db2e44073e6de64e
treed8ad73215c06b09644c20ed7ecadf9431c850040
parente61d80414204d8b3d41c0a4c48b7935e269eadd8

zig build: revert package related changes to Configuration

partial revert of 8e48a5c524f970c4630725e2efe69243d8d79fde partial revert of 8380531aecf20405bad6e008712a39795f224cb3 fixes regression in the build system causing crash when trying to build ffmpeg project from the ecosystem. upon closer inspection, I don't think this is the right direction for adding this data to Configuration. Let's try again and be a little more careful about it.

4 files changed, 37 insertions(+), 325 deletions(-)

lib/compiler/Maker.zig+5-6
...@@ -2293,7 +2293,7 @@ fn prepare(...@@ -2293,7 +2293,7 @@ fn prepare(
2293 }2293 }
2294 } else {2294 } else {
2295 log.err("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory", .{2295 log.err("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory", .{
2296 conf_step.owner.package(c).depPrefixSlice(c),2296 conf_step.owner.depPrefixSlice(c),
2297 conf_step.name.slice(c),2297 conf_step.name.slice(c),
2298 max_rss,2298 max_rss,
2299 maker.available_rss,2299 maker.available_rss,
...@@ -3388,13 +3388,12 @@ pub fn generatedPath(maker: *const Maker, index: Configuration.GeneratedFileInde...@@ -3388,13 +3388,12 @@ pub fn generatedPath(maker: *const Maker, index: Configuration.GeneratedFileInde
3388pub fn packagePath(3388pub fn packagePath(
3389 maker: *const Maker,3389 maker: *const Maker,
3390 arena: Allocator,3390 arena: Allocator,
3391 inst_index: Configuration.Package.Instance.Index,3391 package_index: Configuration.Package.Index,
3392 sub_path: []const u8,3392 sub_path: []const u8,
3393) Allocator.Error!Path {3393) Allocator.Error!Path {
3394 const c = &maker.scanned_config.configuration;3394 const c = &maker.scanned_config.configuration;
3395 const graph = maker.graph;3395 const graph = maker.graph;
33963396 const package = package_index.get(c) orelse return .{
3397 if (inst_index == .root) return .{
3398 .root_dir = graph.build_root_directory,3397 .root_dir = graph.build_root_directory,
3399 .sub_path = sub_path,3398 .sub_path = sub_path,
3400 };3399 };
...@@ -3405,7 +3404,7 @@ pub fn packagePath(...@@ -3405,7 +3404,7 @@ pub fn packagePath(
3405 // construct a cwd relative path here.3404 // construct a cwd relative path here.
3406 return .{3405 return .{
3407 .root_dir = .cwd(),3406 .root_dir = .cwd(),
3408 .sub_path = try Dir.path.join(arena, &.{ inst_index.package(c).ptr(c).root_path.slice(c), sub_path }),3407 .sub_path = try Dir.path.join(arena, &.{ package.root_path.slice(c), sub_path }),
3409 };3408 };
3410}3409}
34113410
...@@ -4035,7 +4034,7 @@ fn confPathDepToCachePath(...@@ -4035,7 +4034,7 @@ fn confPathDepToCachePath(
4035 .root_dir = graph.build_root_directory,4034 .root_dir = graph.build_root_directory,
4036 .sub_path = switch (path_dep.pkg.unwrap().?) {4035 .sub_path = switch (path_dep.pkg.unwrap().?) {
4037 .root => sub_path,4036 .root => sub_path,
4038 else => |index| try Dir.path.join(arena, &.{ index.package(c).ptr(c).root_path.slice(c), sub_path }),4037 else => |index| try Dir.path.join(arena, &.{ index.get(c).?.root_path.slice(c), sub_path }),
4039 },4038 },
4040 },4039 },
4041 .zig_lib => .{4040 .zig_lib => .{
lib/compiler/Maker/ScannedConfig.zig-45
...@@ -83,51 +83,6 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {...@@ -83,51 +83,6 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
83 try tf.end();83 try tf.end();
84 }84 }
8585
86 {
87 var tf = try s.beginTupleField("packages", .{});
88 for (c.packages) |package| {
89 var sf = try tf.beginStructField(.{});
90 try sf.field("dep_prefix", package.dep_prefix.slice(c), .{});
91 try sf.field("hash", package.hash.slice(c), .{});
92 try sf.field("root_path", package.root_path.slice(c), .{});
93
94 var dtf = try sf.beginTupleField("deps", .{});
95 for (package.deps.slice(c)) |dep| {
96 var dsf = try dtf.beginStructField(.{});
97 try sc.printStruct(&dsf, Configuration.Package.Dep, dep);
98 try dsf.end();
99 }
100 try dtf.end();
101
102 try sf.end();
103 }
104 try tf.end();
105 }
106
107 {
108 var tf = try s.beginTupleField("package_instances", .{});
109 for (c.package_instances) |inst| {
110 var sf = try tf.beginStructField(.{});
111
112 try sf.fieldPrefix("package");
113 if (std.enums.tagName(Configuration.Package.Index, inst.package)) |name| {
114 try sf.container.serializer.ident(name);
115 } else {
116 try sf.container.serializer.int(@backingInt(inst.package));
117 }
118
119 var msf = try sf.beginStructField("modules", .{});
120 for (inst.modules.keys.slice(c), inst.modules.values.slice(c)) |key, value| {
121 var msf2 = try msf.beginStructField(key.slice(c), .{});
122 try sc.printStruct(&msf2, Configuration.Module, value.get(c));
123 try msf2.end();
124 }
125 try msf.end();
126
127 try sf.end();
128 }
129 }
130
131 try s.end();86 try s.end();
132}87}
13388
lib/std/Build/Configuration.zig+14-115
...@@ -15,14 +15,6 @@ unlazy_deps: []String,...@@ -15,14 +15,6 @@ unlazy_deps: []String,
15system_integrations: []SystemIntegration,15system_integrations: []SystemIntegration,
16available_options: []AvailableOption,16available_options: []AvailableOption,
17search_prefixes: []String,17search_prefixes: []String,
18/// Index 0 always exists and is the root package.
19packages: []Package,
20/// Index 0 always exists and is the root package instance.
21///
22/// Unlike `packages`, each item corresponds to a `std.Build`, which is a
23/// package that was instantiated by running its build script with specific
24/// input options.
25package_instances: []Package.Instance,
26extra: []u32,18extra: []u32,
27default_step: Step.Index,19default_step: Step.Index,
28generated_files_len: u32,20generated_files_len: u32,
...@@ -38,8 +30,6 @@ pub const Header = extern struct {...@@ -38,8 +30,6 @@ pub const Header = extern struct {
38 system_integrations_len: u32,30 system_integrations_len: u32,
39 available_options_len: u32,31 available_options_len: u32,
40 search_prefixes_len: u32,32 search_prefixes_len: u32,
41 packages_len: u32,
42 package_instances_len: u32,
43 extra_len: u32,33 extra_len: u32,
4434
45 default_step: Step.Index,35 default_step: Step.Index,
...@@ -68,8 +58,6 @@ pub const Wip = struct {...@@ -68,8 +58,6 @@ pub const Wip = struct {
68 steps: std.ArrayList(Step) = .empty,58 steps: std.ArrayList(Step) = .empty,
69 path_deps: std.ArrayList(PathDep) = .empty,59 path_deps: std.ArrayList(PathDep) = .empty,
70 search_prefixes: std.ArrayList(String) = .empty,60 search_prefixes: std.ArrayList(String) = .empty,
71 packages: std.ArrayList(Package) = .empty,
72 package_instances: std.ArrayList(Package.Instance) = .empty,
73 extra: std.ArrayList(u32) = .empty,61 extra: std.ArrayList(u32) = .empty,
74 next_generated_file_index: u32 = 0,62 next_generated_file_index: u32 = 0,
75 cache_poison: bool = false,63 cache_poison: bool = false,
...@@ -151,8 +139,6 @@ pub const Wip = struct {...@@ -151,8 +139,6 @@ pub const Wip = struct {
151 wip.steps.deinit(gpa);139 wip.steps.deinit(gpa);
152 wip.path_deps.deinit(gpa);140 wip.path_deps.deinit(gpa);
153 wip.search_prefixes.deinit(gpa);141 wip.search_prefixes.deinit(gpa);
154 wip.packages.deinit(gpa);
155 wip.package_instances.deinit(gpa);
156 wip.extra.deinit(gpa);142 wip.extra.deinit(gpa);
157 wip.* = undefined;143 wip.* = undefined;
158 }144 }
...@@ -172,8 +158,6 @@ pub const Wip = struct {...@@ -172,8 +158,6 @@ pub const Wip = struct {
172 .system_integrations_len = @intCast(wip.system_integrations.items.len),158 .system_integrations_len = @intCast(wip.system_integrations.items.len),
173 .available_options_len = @intCast(wip.available_options.items.len),159 .available_options_len = @intCast(wip.available_options.items.len),
174 .search_prefixes_len = @intCast(wip.search_prefixes.items.len),160 .search_prefixes_len = @intCast(wip.search_prefixes.items.len),
175 .packages_len = @intCast(wip.packages.items.len),
176 .package_instances_len = @intCast(wip.package_instances.items.len),
177 .extra_len = @intCast(wip.extra.items.len),161 .extra_len = @intCast(wip.extra.items.len),
178162
179 .default_step = static.default_step,163 .default_step = static.default_step,
...@@ -191,8 +175,6 @@ pub const Wip = struct {...@@ -191,8 +175,6 @@ pub const Wip = struct {
191 @ptrCast(wip.system_integrations.items),175 @ptrCast(wip.system_integrations.items),
192 @ptrCast(wip.available_options.items),176 @ptrCast(wip.available_options.items),
193 @ptrCast(wip.search_prefixes.items),177 @ptrCast(wip.search_prefixes.items),
194 @ptrCast(wip.packages.items),
195 @ptrCast(wip.package_instances.items),
196 @ptrCast(wip.extra.items),178 @ptrCast(wip.extra.items),
197 };179 };
198 try w.writeVecAll(&buffers);180 try w.writeVecAll(&buffers);
...@@ -494,7 +476,7 @@ pub const AvailableOption = extern struct {...@@ -494,7 +476,7 @@ pub const AvailableOption = extern struct {
494476
495pub const Step = extern struct {477pub const Step = extern struct {
496 name: String,478 name: String,
497 owner: Package.Instance.Index,479 owner: Package.Index,
498 deps: Deps.Index,480 deps: Deps.Index,
499 max_rss: MaxRss,481 max_rss: MaxRss,
500 extended: Storage.Extended(Flags, union(Tag) {482 extended: Storage.Extended(Flags, union(Tag) {
...@@ -1543,7 +1525,7 @@ pub const LazyPath = union(@This().Tag) {...@@ -1543,7 +1525,7 @@ pub const LazyPath = union(@This().Tag) {
15431525
1544 pub const SourcePath = struct {1526 pub const SourcePath = struct {
1545 flags: @This().Flags = .{},1527 flags: @This().Flags = .{},
1546 owner: Package.Instance.Index,1528 owner: Package.Index,
1547 sub_path: String,1529 sub_path: String,
15481530
1549 pub const Flags = packed struct(u32) {1531 pub const Flags = packed struct(u32) {
...@@ -1614,28 +1596,30 @@ pub const OptionalGeneratedFileIndex = enum(u32) {...@@ -1614,28 +1596,30 @@ pub const OptionalGeneratedFileIndex = enum(u32) {
1614 }1596 }
1615};1597};
16161598
1617pub const Package = extern struct {1599pub const Package = struct {
1618 dep_prefix: String,1600 dep_prefix: String,
1619 hash: String,1601 hash: String,
1620 root_path: String,1602 root_path: String,
1621 deps: Dep.List.Index,
16221603
1623 pub const Index = enum(u32) {1604 pub const Index = enum(u32) {
1624 root,1605 root = max_u32,
1625 _,1606 _,
16261607
1627 pub fn ptr(i: @This(), c: *const Configuration) *const Package {1608 /// Returns `null` for root package.
1628 return &c.packages[@backingInt(i)];1609 pub fn get(i: @This(), c: *const Configuration) ?Package {
1610 if (i == .root) return null;
1611 return extraData(c, Package, @backingInt(i));
1629 }1612 }
16301613
1631 pub fn depPrefixSlice(i: @This(), c: *const Configuration) [:0]const u8 {1614 pub fn depPrefixSlice(i: @This(), c: *const Configuration) [:0]const u8 {
1632 return ptr(i, c).dep_prefix.slice(c);1615 const package = get(i, c) orelse return "";
1616 return package.dep_prefix.slice(c);
1633 }1617 }
1634 };1618 };
16351619
1636 pub const OptionalIndex = enum(u32) {1620 pub const OptionalIndex = enum(u32) {
1637 root,1621 none = max_u32 - 1,
1638 none = max_u32,1622 root = max_u32,
1639 _,1623 _,
16401624
1641 pub fn init(i: Index) OptionalIndex {1625 pub fn init(i: Index) OptionalIndex {
...@@ -1652,78 +1636,13 @@ pub const Package = extern struct {...@@ -1652,78 +1636,13 @@ pub const Package = extern struct {
1652 };1636 };
1653 }1637 }
1654 };1638 };
1655
1656 pub const Dep = extern struct {
1657 name: String,
1658 /// Must not be `.root`.
1659 package: Package.Index,
1660
1661 pub const List = struct {
1662 deps: Storage.LengthPrefixedList(Dep),
1663
1664 pub const Index = enum(u32) {
1665 _,
1666
1667 pub fn get(this: @This(), c: *const Configuration) List {
1668 return extraData(c, List, @backingInt(this));
1669 }
1670
1671 pub fn slice(this: @This(), c: *const Configuration) []const Dep {
1672 return get(this, c).deps.slice;
1673 }
1674 };
1675 };
1676 };
1677
1678 pub const Instance = extern struct {
1679 package: Package.Index,
1680 modules: PublicModules,
1681
1682 pub const PublicModules = extern struct {
1683 keys: StringList,
1684 values: Module.List.Index,
1685 };
1686
1687 pub const Index = enum(u32) {
1688 root,
1689 _,
1690
1691 pub fn ptr(this: @This(), c: *const Configuration) *const Package.Instance {
1692 return &c.package_instances[@backingInt(this)];
1693 }
1694
1695 pub fn package(this: @This(), c: *const Configuration) Package.Index {
1696 return this.ptr(c).package;
1697 }
1698 };
1699
1700 pub const OptionalIndex = enum(u32) {
1701 root,
1702 none = max_u32,
1703 _,
1704
1705 pub fn init(i: Instance.Index) Instance.OptionalIndex {
1706 const result: Instance.OptionalIndex = @fromBackingInt(@intCast(@backingInt(i)));
1707 assert(result != .none);
1708 return result;
1709 }
1710
1711 pub fn unwrap(this: @This()) ?Instance.Index {
1712 return switch (this) {
1713 .none => null,
1714 .root => .root,
1715 _ => @fromBackingInt(@intCast(@backingInt(this))),
1716 };
1717 }
1718 };
1719 };
1720};1639};
17211640
1722pub const Module = struct {1641pub const Module = struct {
1723 flags: Flags,1642 flags: Flags,
1724 flags2: Flags2,1643 flags2: Flags2,
1725 import_table: ImportTable.Index,1644 import_table: ImportTable.Index,
1726 owner: Package.Instance.Index,1645 owner: Package.Index,
1727 root_source_file: LazyPath.OptionalIndex,1646 root_source_file: LazyPath.OptionalIndex,
1728 resolved_target: ResolvedTarget.OptionalIndex,1647 resolved_target: ResolvedTarget.OptionalIndex,
1729 c_macros: Storage.FlagLengthPrefixedList(.flags, .c_macros, String),1648 c_macros: Storage.FlagLengthPrefixedList(.flags, .c_macros, String),
...@@ -1866,22 +1785,6 @@ pub const Module = struct {...@@ -1866,22 +1785,6 @@ pub const Module = struct {
1866 };1785 };
18671786
1868 pub const Index = IndexType(@This());1787 pub const Index = IndexType(@This());
1869
1870 pub const List = struct {
1871 modules: Storage.LengthPrefixedList(Module.Index),
1872
1873 pub const Index = enum(u32) {
1874 _,
1875
1876 pub fn get(this: @This(), c: *const Configuration) List {
1877 return extraData(c, List, @backingInt(this));
1878 }
1879
1880 pub fn slice(this: @This(), c: *const Configuration) []const Module.Index {
1881 return this.get(c).modules.slice;
1882 }
1883 };
1884 };
1885};1788};
18861789
1887pub const ImportTable = struct {1790pub const ImportTable = struct {
...@@ -1966,7 +1869,7 @@ pub const OptionalStringList = enum(u32) {...@@ -1966,7 +1869,7 @@ pub const OptionalStringList = enum(u32) {
1966pub const PathDep = extern struct {1869pub const PathDep = extern struct {
1967 flags: Flags,1870 flags: Flags,
1968 sub: String,1871 sub: String,
1969 pkg: Package.Instance.OptionalIndex,1872 pkg: Package.OptionalIndex,
19701873
1971 pub const Flags = packed struct(u32) {1874 pub const Flags = packed struct(u32) {
1972 mode: Mode,1875 mode: Mode,
...@@ -3231,8 +3134,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {...@@ -3231,8 +3134,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {
3231 .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len),3134 .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len),
3232 .available_options = try arena.alloc(AvailableOption, header.available_options_len),3135 .available_options = try arena.alloc(AvailableOption, header.available_options_len),
3233 .search_prefixes = try arena.alloc(String, header.search_prefixes_len),3136 .search_prefixes = try arena.alloc(String, header.search_prefixes_len),
3234 .packages = try arena.alloc(Package, header.packages_len),
3235 .package_instances = try arena.alloc(Package.Instance, header.package_instances_len),
3236 .extra = try arena.alloc(u32, header.extra_len),3137 .extra = try arena.alloc(u32, header.extra_len),
3237 .default_step = header.default_step,3138 .default_step = header.default_step,
3238 .generated_files_len = header.generated_files_len,3139 .generated_files_len = header.generated_files_len,
...@@ -3246,8 +3147,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {...@@ -3246,8 +3147,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration {
3246 @ptrCast(result.system_integrations),3147 @ptrCast(result.system_integrations),
3247 @ptrCast(result.available_options),3148 @ptrCast(result.available_options),
3248 @ptrCast(result.search_prefixes),3149 @ptrCast(result.search_prefixes),
3249 @ptrCast(result.packages),
3250 @ptrCast(result.package_instances),
3251 @ptrCast(result.extra),3150 @ptrCast(result.extra),
3252 };3151 };
3253 try reader.readVecAll(&vecs);3152 try reader.readVecAll(&vecs);
lib/std/Build/Serialize.zig+18-159
...@@ -10,10 +10,7 @@ const log = std.log;...@@ -10,10 +10,7 @@ const log = std.log;
10arena: Allocator,10arena: Allocator,
11wc: *Configuration.Wip,11wc: *Configuration.Wip,
12module_map: std.array_hash_map.Auto(*std.Build.Module, Configuration.Module.Index) = .empty,12module_map: std.array_hash_map.Auto(*std.Build.Module, Configuration.Module.Index) = .empty,
13/// Keyed by package hash. Index + 1 corresponds to `Configuration.packages` index.13package_map: std.array_hash_map.Auto(*std.Build, Configuration.Package.Index) = .empty,
14package_map: std.array_hash_map.String(void) = .empty,
15/// Index corresponds to `Configuration.package_instances` index.
16package_instance_map: std.array_hash_map.Auto(*std.Build, void) = .empty,
17/// Index corresponds to `Configuration.steps` index.14/// Index corresponds to `Configuration.steps` index.
18step_map: std.array_hash_map.Auto(*Step, void) = .empty,15step_map: std.array_hash_map.Auto(*Step, void) = .empty,
1916
...@@ -24,31 +21,6 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi...@@ -24,31 +21,6 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
2421
25 var s: Serialize = .{ .wc = wc, .arena = arena };22 var s: Serialize = .{ .wc = wc, .arena = arena };
2623
27 // Seed the package_map, which is later used when serializing package
28 // instances.
29 try s.traversePackages(b);
30
31 // Next, seed the package_instance_map, which is later used in calls to
32 // packageInstanceFromBuilder.
33
34 _ = try wc.package_instances.addManyAsSlice(gpa, 1 + b.graph.dependency_cache.count());
35 try s.package_instance_map.ensureTotalCapacity(arena, 1 + b.graph.dependency_cache.count());
36
37 // As serializing package instances also requires serializing the public
38 // modules of each one, we must first allocate an index for each package
39 // instance. Otherwise, addModule may access a package instance that hasn't
40 // been created yet with packageInstanceFromBuilder.
41
42 s.package_instance_map.putAssumeCapacityNoClobber(b, {});
43 for (b.graph.dependency_cache.values()) |dep| {
44 s.package_instance_map.putAssumeCapacityNoClobber(dep.builder, {});
45 }
46
47 try s.addPackageInstance(b);
48 for (b.graph.dependency_cache.values()) |dep| {
49 try s.addPackageInstance(dep.builder);
50 }
51
52 try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len);24 try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len);
53 for (25 for (
54 graph.configure_dependencies.items,26 graph.configure_dependencies.items,
...@@ -72,10 +44,10 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi...@@ -72,10 +44,10 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
72 .relative => |r| try wc.addString(r.sub_path),44 .relative => |r| try wc.addString(r.sub_path),
73 },45 },
74 .pkg = switch (src.lazy_path) {46 .pkg = switch (src.lazy_path) {
75 .src_path => |sp| .init(s.packageInstanceFromBuilder(sp.owner)),47 .src_path => |sp| .init(try s.builderToPackage(sp.owner)),
76 .generated => unreachable,48 .generated => unreachable,
77 .cwd_relative, .relative => .none,49 .cwd_relative, .relative => .none,
78 .dependency => |d| .init(s.packageInstanceFromBuilder(d.dependency.builder)),50 .dependency => |d| .init(try s.builderToPackage(d.dependency.builder)),
79 },51 },
80 };52 };
81 }53 }
...@@ -112,7 +84,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi...@@ -112,7 +84,7 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi
112 try wc.steps.ensureTotalCapacity(gpa, s.step_map.entries.capacity);84 try wc.steps.ensureTotalCapacity(gpa, s.step_map.entries.capacity);
113 wc.steps.appendAssumeCapacity(.{85 wc.steps.appendAssumeCapacity(.{
114 .name = try wc.addString(step.name),86 .name = try wc.addString(step.name),
115 .owner = s.packageInstanceFromBuilder(step.owner),87 .owner = try s.builderToPackage(step.owner),
116 .deps = deps,88 .deps = deps,
117 .max_rss = .fromBytes(step.max_rss),89 .max_rss = .fromBytes(step.max_rss),
118 .extended = @fromBackingInt(@intCast(switch (step.tag) {90 .extended = @fromBackingInt(@intCast(switch (step.tag) {
...@@ -750,132 +722,19 @@ pub fn packageOptions(b: *std.Build, wc: *Configuration.Wip) Allocator.Error!voi...@@ -750,132 +722,19 @@ pub fn packageOptions(b: *std.Build, wc: *Configuration.Wip) Allocator.Error!voi
750 }722 }
751}723}
752724
753fn traversePackages(s: *Serialize, b: *std.Build) Allocator.Error!void {725fn builderToPackage(s: *Serialize, b: *std.Build) !Configuration.Package.Index {
754 const arena = s.arena;726 if (b.pkg_hash.len == 0) return .root;
755 const wc = s.wc;
756
757 try wc.packages.append(wc.gpa, .{
758 .dep_prefix = .empty,
759 .hash = .empty,
760 .root_path = try wc.addString(try b.root.toString(arena)),
761 .deps = undefined,
762 });
763
764 const deps = try arena.alloc(Configuration.Package.Dep, b.available_deps.len);
765 for (deps, b.available_deps) |*dest, src| dest.* = try s.makePackageDep("", src[0], src[1]);
766
767 wc.packages.items[0].deps = try wc.addDeduped(Configuration.Package.Dep.List, .{
768 .deps = .{ .slice = deps },
769 });
770}
771
772fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8, hash: []const u8) Allocator.Error!Configuration.Package.Dep {
773 const arena = s.arena;
774 const wc = s.wc;
775
776 if (s.package_map.getIndex(hash)) |index| return .{
777 .name = try wc.addString(name),
778 .package = @fromBackingInt(@intCast(index + 1)),
779 };
780
781 const index: Configuration.Package.Index = @fromBackingInt(@intCast(wc.packages.items.len));
782 try s.package_map.put(arena, hash, {});
783
784 const entry = std.Build.package_map.get(hash) orelse unreachable;
785
786 const dep_prefix = try arena.print("{s}{s}.", .{ parent_dep_prefix, name });
787
788 try wc.packages.append(wc.gpa, .{
789 .dep_prefix = try wc.addString(dep_prefix),
790 .hash = try wc.addString(hash),
791 .root_path = try wc.addString(entry.build_root),
792 .deps = undefined,
793 });
794
795 const deps = try arena.alloc(Configuration.Package.Dep, entry.deps.len);
796 for (deps, entry.deps) |*dest, src| dest.* = try s.makePackageDep(dep_prefix, src[0], src[1]);
797
798 wc.packages.items[@backingInt(index)].deps = try wc.addDeduped(Configuration.Package.Dep.List, .{
799 .deps = .{ .slice = deps },
800 });
801
802 return .{
803 .name = try wc.addString(name),
804 .package = index,
805 };
806}
807
808fn packageFromHash(s: *Serialize, pkg_hash: []const u8) Configuration.Package.Index {
809 if (pkg_hash.len == 0) return .root;
810 return @fromBackingInt(@intCast(s.package_map.getIndex(pkg_hash).? + 1));
811}
812
813fn addPackageInstance(s: *Serialize, b: *std.Build) Allocator.Error!void {
814 const arena = s.arena;727 const arena = s.arena;
815 const wc = s.wc;728 const wc = s.wc;
816729 const gop = try s.package_map.getOrPut(arena, b);
817 const index = s.package_instance_map.getIndex(b).?;730 if (!gop.found_existing) {
818731 gop.value_ptr.* = try wc.addExtra(Configuration.Package, .{
819 const modules_values = try arena.alloc(Configuration.Module.Index, b.modules.count());732 .hash = try wc.addString(b.pkg_hash),
820 for (modules_values, b.modules.values()) |*dest_value, value| {733 .dep_prefix = try wc.addString(b.dep_prefix),
821 dest_value.* = try s.addModule(value);734 .root_path = try wc.addString(try b.root.toString(arena)),
735 });
822 }736 }
823737 return gop.value_ptr.*;
824 wc.package_instances.items[index] = .{
825 .package = s.packageFromHash(b.pkg_hash),
826 .modules = .{
827 .keys = try wc.addStringList(b.modules.keys()),
828 .values = try wc.addDeduped(Configuration.Module.List, .{
829 .modules = .{ .slice = modules_values },
830 }),
831 },
832 };
833}
834
835fn makeUserValue(s: *Serialize, user_value: *const std.Build.UserValue) Allocator.Error!Configuration.Package.Instance.UserValue {
836 const arena = s.arena;
837 const wc = s.wc;
838
839 return switch (user_value.*) {
840 .flag => .flag,
841 .scalar => |str| .{ .scalar = try wc.addString(str) },
842 .list => |list| .{ .list = try wc.addStringList(list.items) },
843 .map => |map| add: {
844 const keys = try arena.alloc([]const u8, map.count());
845 const values = try arena.alloc(Configuration.Package.Instance.UserValue.Standalone.Index, map.count());
846
847 var i: usize = 0;
848 var iter = map.iterator();
849 while (iter.next()) |entry| : (i += 1) {
850 const value = try s.makeUserValue(entry.value_ptr.*);
851
852 keys[i] = entry.key_ptr.*;
853 values[i] = try wc.addDeduped(
854 Configuration.Package.Instance.UserValue.Standalone,
855 .{ .flags = .{ .tag = value }, .value = .{ .u = value } },
856 );
857 }
858
859 break :add .{ .map = try wc.addDeduped(
860 Configuration.Package.Instance.UserValue.Map,
861 .{
862 .keys = try wc.addStringList(keys),
863 .values = .{ .slice = values },
864 },
865 ) };
866 },
867 .lazy_path => |lp| .{ .lazy_path = try s.addLazyPath(lp) },
868 .lazy_path_list => |lp_list| add: {
869 const paths = try arena.alloc(Configuration.LazyPath.Index, lp_list.items.len);
870 for (paths, lp_list.items) |*dest, src| dest.* = try s.addLazyPath(src);
871 break :add .{ .lazy_path_list = .{ .slice = paths } };
872 },
873 };
874}
875
876fn packageInstanceFromBuilder(s: *Serialize, b: *std.Build) Configuration.Package.Instance.Index {
877 if (b.pkg_hash.len == 0) return .root;
878 return @fromBackingInt(@intCast(s.package_instance_map.getIndex(b).?));
879}738}
880739
881fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex {740fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex {
...@@ -884,7 +743,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio...@@ -884,7 +743,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio
884 .src_path => |src_path| i: {743 .src_path => |src_path| i: {
885 const sub_path = try wc.addString(src_path.sub_path);744 const sub_path = try wc.addString(src_path.sub_path);
886 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{745 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{
887 .owner = s.packageInstanceFromBuilder(src_path.owner),746 .owner = try s.builderToPackage(src_path.owner),
888 .sub_path = sub_path,747 .sub_path = sub_path,
889 });748 });
890 },749 },
...@@ -912,7 +771,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio...@@ -912,7 +771,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio
912 .dependency => |dependency| i: {771 .dependency => |dependency| i: {
913 const sub_path = try wc.addString(dependency.sub_path);772 const sub_path = try wc.addString(dependency.sub_path);
914 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{773 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{
915 .owner = s.packageInstanceFromBuilder(dependency.dependency.builder),774 .owner = try s.builderToPackage(dependency.dependency.builder),
916 .sub_path = sub_path,775 .sub_path = sub_path,
917 });776 });
918 },777 },
...@@ -1341,7 +1200,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {...@@ -1341,7 +1200,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {
1341 const c_macros = try initStringList(s, m.c_macros.items);1200 const c_macros = try initStringList(s, m.c_macros.items);
1342 const export_symbol_names = try initStringList(s, m.export_symbol_names);1201 const export_symbol_names = try initStringList(s, m.export_symbol_names);
13431202
1344 const module_index: Configuration.Module.Index = try wc.addDeduped(Configuration.Module, .{1203 const module_index: Configuration.Module.Index = try wc.addExtra(Configuration.Module, .{
1345 .flags = .{1204 .flags = .{
1346 .optimize = .init(m.optimize),1205 .optimize = .init(m.optimize),
1347 .strip = .init(m.strip),1206 .strip = .init(m.strip),
...@@ -1372,7 +1231,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {...@@ -1372,7 +1231,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index {
1372 .link_libcpp = .init(m.link_libcpp),1231 .link_libcpp = .init(m.link_libcpp),
1373 .no_builtin = .init(m.no_builtin),1232 .no_builtin = .init(m.no_builtin),
1374 },1233 },
1375 .owner = s.packageInstanceFromBuilder(m.owner),1234 .owner = try s.builderToPackage(m.owner),
1376 .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file),1235 .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file),
1377 .import_table = .invalid,1236 .import_table = .invalid,
1378 .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),1237 .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target),