| author | |
| committer | |
| log | 5d7cf3f34d13f70de35c2f76db2e44073e6de64e |
| tree | d8ad73215c06b09644c20ed7ecadf9431c850040 |
| parent | e61d80414204d8b3d41c0a4c48b7935e269eadd8 |
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 | 2293 | } |
| 2294 | 2294 | } else { |
| 2295 | 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 | 2297 | conf_step.name.slice(c), |
| 2298 | 2298 | max_rss, |
| 2299 | 2299 | maker.available_rss, |
| ... | ... | @@ -3388,13 +3388,12 @@ pub fn generatedPath(maker: *const Maker, index: Configuration.GeneratedFileInde |
| 3388 | 3388 | pub fn packagePath( |
| 3389 | 3389 | maker: *const Maker, |
| 3390 | 3390 | arena: Allocator, |
| 3391 | inst_index: Configuration.Package.Instance.Index, | |
| 3391 | package_index: Configuration.Package.Index, | |
| 3392 | 3392 | sub_path: []const u8, |
| 3393 | 3393 | ) Allocator.Error!Path { |
| 3394 | 3394 | const c = &maker.scanned_config.configuration; |
| 3395 | 3395 | const graph = maker.graph; |
| 3396 | ||
| 3397 | if (inst_index == .root) return .{ | |
| 3396 | const package = package_index.get(c) orelse return .{ | |
| 3398 | 3397 | .root_dir = graph.build_root_directory, |
| 3399 | 3398 | .sub_path = sub_path, |
| 3400 | 3399 | }; |
| ... | ... | @@ -3405,7 +3404,7 @@ pub fn packagePath( |
| 3405 | 3404 | // construct a cwd relative path here. |
| 3406 | 3405 | return .{ |
| 3407 | 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 | } |
| 3411 | 3410 | |
| ... | ... | @@ -4035,7 +4034,7 @@ fn confPathDepToCachePath( |
| 4035 | 4034 | .root_dir = graph.build_root_directory, |
| 4036 | 4035 | .sub_path = switch (path_dep.pkg.unwrap().?) { |
| 4037 | 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 | 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 | 83 | try tf.end(); |
| 84 | 84 | } |
| 85 | 85 | |
| 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 | 86 | try s.end(); |
| 132 | 87 | } |
| 133 | 88 |
lib/std/Build/Configuration.zig+14-115| ... | ... | @@ -15,14 +15,6 @@ unlazy_deps: []String, |
| 15 | 15 | system_integrations: []SystemIntegration, |
| 16 | 16 | available_options: []AvailableOption, |
| 17 | 17 | search_prefixes: []String, |
| 18 | /// Index 0 always exists and is the root package. | |
| 19 | packages: []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. | |
| 25 | package_instances: []Package.Instance, | |
| 26 | 18 | extra: []u32, |
| 27 | 19 | default_step: Step.Index, |
| 28 | 20 | generated_files_len: u32, |
| ... | ... | @@ -38,8 +30,6 @@ pub const Header = extern struct { |
| 38 | 30 | system_integrations_len: u32, |
| 39 | 31 | available_options_len: u32, |
| 40 | 32 | search_prefixes_len: u32, |
| 41 | packages_len: u32, | |
| 42 | package_instances_len: u32, | |
| 43 | 33 | extra_len: u32, |
| 44 | 34 | |
| 45 | 35 | default_step: Step.Index, |
| ... | ... | @@ -68,8 +58,6 @@ pub const Wip = struct { |
| 68 | 58 | steps: std.ArrayList(Step) = .empty, |
| 69 | 59 | path_deps: std.ArrayList(PathDep) = .empty, |
| 70 | 60 | search_prefixes: std.ArrayList(String) = .empty, |
| 71 | packages: std.ArrayList(Package) = .empty, | |
| 72 | package_instances: std.ArrayList(Package.Instance) = .empty, | |
| 73 | 61 | extra: std.ArrayList(u32) = .empty, |
| 74 | 62 | next_generated_file_index: u32 = 0, |
| 75 | 63 | cache_poison: bool = false, |
| ... | ... | @@ -151,8 +139,6 @@ pub const Wip = struct { |
| 151 | 139 | wip.steps.deinit(gpa); |
| 152 | 140 | wip.path_deps.deinit(gpa); |
| 153 | 141 | wip.search_prefixes.deinit(gpa); |
| 154 | wip.packages.deinit(gpa); | |
| 155 | wip.package_instances.deinit(gpa); | |
| 156 | 142 | wip.extra.deinit(gpa); |
| 157 | 143 | wip.* = undefined; |
| 158 | 144 | } |
| ... | ... | @@ -172,8 +158,6 @@ pub const Wip = struct { |
| 172 | 158 | .system_integrations_len = @intCast(wip.system_integrations.items.len), |
| 173 | 159 | .available_options_len = @intCast(wip.available_options.items.len), |
| 174 | 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 | 161 | .extra_len = @intCast(wip.extra.items.len), |
| 178 | 162 | |
| 179 | 163 | .default_step = static.default_step, |
| ... | ... | @@ -191,8 +175,6 @@ pub const Wip = struct { |
| 191 | 175 | @ptrCast(wip.system_integrations.items), |
| 192 | 176 | @ptrCast(wip.available_options.items), |
| 193 | 177 | @ptrCast(wip.search_prefixes.items), |
| 194 | @ptrCast(wip.packages.items), | |
| 195 | @ptrCast(wip.package_instances.items), | |
| 196 | 178 | @ptrCast(wip.extra.items), |
| 197 | 179 | }; |
| 198 | 180 | try w.writeVecAll(&buffers); |
| ... | ... | @@ -494,7 +476,7 @@ pub const AvailableOption = extern struct { |
| 494 | 476 | |
| 495 | 477 | pub const Step = extern struct { |
| 496 | 478 | name: String, |
| 497 | owner: Package.Instance.Index, | |
| 479 | owner: Package.Index, | |
| 498 | 480 | deps: Deps.Index, |
| 499 | 481 | max_rss: MaxRss, |
| 500 | 482 | extended: Storage.Extended(Flags, union(Tag) { |
| ... | ... | @@ -1543,7 +1525,7 @@ pub const LazyPath = union(@This().Tag) { |
| 1543 | 1525 | |
| 1544 | 1526 | pub const SourcePath = struct { |
| 1545 | 1527 | flags: @This().Flags = .{}, |
| 1546 | owner: Package.Instance.Index, | |
| 1528 | owner: Package.Index, | |
| 1547 | 1529 | sub_path: String, |
| 1548 | 1530 | |
| 1549 | 1531 | pub const Flags = packed struct(u32) { |
| ... | ... | @@ -1614,28 +1596,30 @@ pub const OptionalGeneratedFileIndex = enum(u32) { |
| 1614 | 1596 | } |
| 1615 | 1597 | }; |
| 1616 | 1598 | |
| 1617 | pub const Package = extern struct { | |
| 1599 | pub const Package = struct { | |
| 1618 | 1600 | dep_prefix: String, |
| 1619 | 1601 | hash: String, |
| 1620 | 1602 | root_path: String, |
| 1621 | deps: Dep.List.Index, | |
| 1622 | 1603 | |
| 1623 | 1604 | pub const Index = enum(u32) { |
| 1624 | root, | |
| 1605 | root = max_u32, | |
| 1625 | 1606 | _, |
| 1626 | 1607 | |
| 1627 | pub fn ptr(i: @This(), c: *const Configuration) *const Package { | |
| 1628 | return &c.packages[@backingInt(i)]; | |
| 1608 | /// Returns `null` for root package. | |
| 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 | } |
| 1630 | 1613 | |
| 1631 | 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 | }; |
| 1635 | 1619 | |
| 1636 | 1620 | pub const OptionalIndex = enum(u32) { |
| 1637 | root, | |
| 1638 | none = max_u32, | |
| 1621 | none = max_u32 - 1, | |
| 1622 | root = max_u32, | |
| 1639 | 1623 | _, |
| 1640 | 1624 | |
| 1641 | 1625 | pub fn init(i: Index) OptionalIndex { |
| ... | ... | @@ -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 | }; |
| 1721 | 1640 | |
| 1722 | 1641 | pub const Module = struct { |
| 1723 | 1642 | flags: Flags, |
| 1724 | 1643 | flags2: Flags2, |
| 1725 | 1644 | import_table: ImportTable.Index, |
| 1726 | owner: Package.Instance.Index, | |
| 1645 | owner: Package.Index, | |
| 1727 | 1646 | root_source_file: LazyPath.OptionalIndex, |
| 1728 | 1647 | resolved_target: ResolvedTarget.OptionalIndex, |
| 1729 | 1648 | c_macros: Storage.FlagLengthPrefixedList(.flags, .c_macros, String), |
| ... | ... | @@ -1866,22 +1785,6 @@ pub const Module = struct { |
| 1866 | 1785 | }; |
| 1867 | 1786 | |
| 1868 | 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 | }; |
| 1886 | 1789 | |
| 1887 | 1790 | pub const ImportTable = struct { |
| ... | ... | @@ -1966,7 +1869,7 @@ pub const OptionalStringList = enum(u32) { |
| 1966 | 1869 | pub const PathDep = extern struct { |
| 1967 | 1870 | flags: Flags, |
| 1968 | 1871 | sub: String, |
| 1969 | pkg: Package.Instance.OptionalIndex, | |
| 1872 | pkg: Package.OptionalIndex, | |
| 1970 | 1873 | |
| 1971 | 1874 | pub const Flags = packed struct(u32) { |
| 1972 | 1875 | mode: Mode, |
| ... | ... | @@ -3231,8 +3134,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration { |
| 3231 | 3134 | .system_integrations = try arena.alloc(SystemIntegration, header.system_integrations_len), |
| 3232 | 3135 | .available_options = try arena.alloc(AvailableOption, header.available_options_len), |
| 3233 | 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 | 3137 | .extra = try arena.alloc(u32, header.extra_len), |
| 3237 | 3138 | .default_step = header.default_step, |
| 3238 | 3139 | .generated_files_len = header.generated_files_len, |
| ... | ... | @@ -3246,8 +3147,6 @@ pub fn load(arena: Allocator, reader: *Io.Reader) LoadError!Configuration { |
| 3246 | 3147 | @ptrCast(result.system_integrations), |
| 3247 | 3148 | @ptrCast(result.available_options), |
| 3248 | 3149 | @ptrCast(result.search_prefixes), |
| 3249 | @ptrCast(result.packages), | |
| 3250 | @ptrCast(result.package_instances), | |
| 3251 | 3150 | @ptrCast(result.extra), |
| 3252 | 3151 | }; |
| 3253 | 3152 | try reader.readVecAll(&vecs); |
lib/std/Build/Serialize.zig+18-159| ... | ... | @@ -10,10 +10,7 @@ const log = std.log; |
| 10 | 10 | arena: Allocator, |
| 11 | 11 | wc: *Configuration.Wip, |
| 12 | 12 | module_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. | |
| 14 | package_map: std.array_hash_map.String(void) = .empty, | |
| 15 | /// Index corresponds to `Configuration.package_instances` index. | |
| 16 | package_instance_map: std.array_hash_map.Auto(*std.Build, void) = .empty, | |
| 13 | package_map: std.array_hash_map.Auto(*std.Build, Configuration.Package.Index) = .empty, | |
| 17 | 14 | /// Index corresponds to `Configuration.steps` index. |
| 18 | 15 | step_map: std.array_hash_map.Auto(*Step, void) = .empty, |
| 19 | 16 | |
| ... | ... | @@ -24,31 +21,6 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 24 | 21 | |
| 25 | 22 | var s: Serialize = .{ .wc = wc, .arena = arena }; |
| 26 | 23 | |
| 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 | 24 | try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len); |
| 53 | 25 | for ( |
| 54 | 26 | graph.configure_dependencies.items, |
| ... | ... | @@ -72,10 +44,10 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 72 | 44 | .relative => |r| try wc.addString(r.sub_path), |
| 73 | 45 | }, |
| 74 | 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 | 48 | .generated => unreachable, |
| 77 | 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 | 84 | try wc.steps.ensureTotalCapacity(gpa, s.step_map.entries.capacity); |
| 113 | 85 | wc.steps.appendAssumeCapacity(.{ |
| 114 | 86 | .name = try wc.addString(step.name), |
| 115 | .owner = s.packageInstanceFromBuilder(step.owner), | |
| 87 | .owner = try s.builderToPackage(step.owner), | |
| 116 | 88 | .deps = deps, |
| 117 | 89 | .max_rss = .fromBytes(step.max_rss), |
| 118 | 90 | .extended = @fromBackingInt(@intCast(switch (step.tag) { |
| ... | ... | @@ -750,132 +722,19 @@ pub fn packageOptions(b: *std.Build, wc: *Configuration.Wip) Allocator.Error!voi |
| 750 | 722 | } |
| 751 | 723 | } |
| 752 | 724 | |
| 753 | fn traversePackages(s: *Serialize, b: *std.Build) Allocator.Error!void { | |
| 754 | const arena = s.arena; | |
| 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 | ||
| 772 | fn 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 | ||
| 808 | fn 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 | ||
| 813 | fn addPackageInstance(s: *Serialize, b: *std.Build) Allocator.Error!void { | |
| 725 | fn builderToPackage(s: *Serialize, b: *std.Build) !Configuration.Package.Index { | |
| 726 | if (b.pkg_hash.len == 0) return .root; | |
| 814 | 727 | const arena = s.arena; |
| 815 | 728 | const wc = s.wc; |
| 816 | ||
| 817 | const index = s.package_instance_map.getIndex(b).?; | |
| 818 | ||
| 819 | const modules_values = try arena.alloc(Configuration.Module.Index, b.modules.count()); | |
| 820 | for (modules_values, b.modules.values()) |*dest_value, value| { | |
| 821 | dest_value.* = try s.addModule(value); | |
| 729 | const gop = try s.package_map.getOrPut(arena, b); | |
| 730 | if (!gop.found_existing) { | |
| 731 | gop.value_ptr.* = try wc.addExtra(Configuration.Package, .{ | |
| 732 | .hash = try wc.addString(b.pkg_hash), | |
| 733 | .dep_prefix = try wc.addString(b.dep_prefix), | |
| 734 | .root_path = try wc.addString(try b.root.toString(arena)), | |
| 735 | }); | |
| 822 | 736 | } |
| 823 | ||
| 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 | ||
| 835 | fn 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 | ||
| 876 | fn 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).?)); | |
| 737 | return gop.value_ptr.*; | |
| 879 | 738 | } |
| 880 | 739 | |
| 881 | 740 | fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath.OptionalIndex { |
| ... | ... | @@ -884,7 +743,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio |
| 884 | 743 | .src_path => |src_path| i: { |
| 885 | 744 | const sub_path = try wc.addString(src_path.sub_path); |
| 886 | 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 | 747 | .sub_path = sub_path, |
| 889 | 748 | }); |
| 890 | 749 | }, |
| ... | ... | @@ -912,7 +771,7 @@ fn addOptionalLazyPathEnum(s: *Serialize, lp: ?std.Build.LazyPath) !Configuratio |
| 912 | 771 | .dependency => |dependency| i: { |
| 913 | 772 | const sub_path = try wc.addString(dependency.sub_path); |
| 914 | 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 | 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 | 1200 | const c_macros = try initStringList(s, m.c_macros.items); |
| 1342 | 1201 | const export_symbol_names = try initStringList(s, m.export_symbol_names); |
| 1343 | 1202 | |
| 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 | 1204 | .flags = .{ |
| 1346 | 1205 | .optimize = .init(m.optimize), |
| 1347 | 1206 | .strip = .init(m.strip), |
| ... | ... | @@ -1372,7 +1231,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index { |
| 1372 | 1231 | .link_libcpp = .init(m.link_libcpp), |
| 1373 | 1232 | .no_builtin = .init(m.no_builtin), |
| 1374 | 1233 | }, |
| 1375 | .owner = s.packageInstanceFromBuilder(m.owner), | |
| 1234 | .owner = try s.builderToPackage(m.owner), | |
| 1376 | 1235 | .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file), |
| 1377 | 1236 | .import_table = .invalid, |
| 1378 | 1237 | .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target), |