| ... | ... | @@ -28,11 +28,24 @@ pub fn write(b: *std.Build, wc: *Configuration.Wip, writer: *std.Io.Writer) !voi |
| 28 | 28 | // instances. |
| 29 | 29 | try s.traversePackages(b); |
| 30 | 30 | |
| 31 | | // Seed the package_instance_map, which is later used in calls to |
| 31 | // Next, seed the package_instance_map, which is later used in calls to |
| 32 | 32 | // packageInstanceFromBuilder. |
| 33 | | try s.addPackageInstance(b); |
| 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, {}); |
| 34 | 43 | var iter = b.graph.dependency_cache.valueIterator(); |
| 35 | | while (iter.next()) |dep| try s.addPackageInstance(dep.*.builder); |
| 44 | while (iter.next()) |dep| s.package_instance_map.putAssumeCapacityNoClobber(dep.*.builder, {}); |
| 45 | |
| 46 | try s.addPackageInstance(b); |
| 47 | var iter2 = b.graph.dependency_cache.valueIterator(); |
| 48 | while (iter2.next()) |dep| try s.addPackageInstance(dep.*.builder); |
| 36 | 49 | |
| 37 | 50 | try wc.path_deps.ensureTotalCapacityPrecise(gpa, graph.configure_dependencies.items.len); |
| 38 | 51 | for ( |
| ... | ... | @@ -763,13 +776,13 @@ fn makePackageDep(s: *Serialize, parent_dep_prefix: []const u8, name: []const u8 |
| 763 | 776 | .package = @fromBackingInt(@intCast(index + 1)), |
| 764 | 777 | }; |
| 765 | 778 | |
| 779 | const index: Configuration.Package.Index = @fromBackingInt(@intCast(wc.packages.items.len)); |
| 780 | try s.package_map.put(arena, hash, {}); |
| 781 | |
| 766 | 782 | const entry = std.Build.package_map.get(hash) orelse unreachable; |
| 767 | 783 | |
| 768 | 784 | const dep_prefix = try arena.print("{s}{s}.", .{ parent_dep_prefix, name }); |
| 769 | 785 | |
| 770 | | const index: Configuration.Package.Index = @fromBackingInt(@intCast(wc.packages.items.len)); |
| 771 | | try s.package_map.put(arena, hash, {}); |
| 772 | | |
| 773 | 786 | try wc.packages.append(wc.gpa, .{ |
| 774 | 787 | .dep_prefix = try wc.addString(dep_prefix), |
| 775 | 788 | .hash = try wc.addString(hash), |
| ... | ... | @@ -799,32 +812,58 @@ fn addPackageInstance(s: *Serialize, b: *std.Build) Allocator.Error!void { |
| 799 | 812 | const arena = s.arena; |
| 800 | 813 | const wc = s.wc; |
| 801 | 814 | |
| 815 | const index = s.package_instance_map.getIndex(b).?; |
| 816 | |
| 802 | 817 | const options = try arena.alloc( |
| 803 | 818 | Configuration.PackageInstance.UserInputOption.Index, |
| 804 | 819 | b.user_input_options.count(), |
| 805 | 820 | ); |
| 806 | 821 | |
| 807 | | var i: usize = 0; |
| 808 | | var iter = b.user_input_options.valueIterator(); |
| 809 | | while (iter.next()) |option| : (i += 1) { |
| 810 | | options[i] = try wc.addExtra(Configuration.PackageInstance.UserInputOption, .{ |
| 811 | | .flags = .{ |
| 812 | | .tag = .init(option.value), |
| 813 | | .used = option.used, |
| 814 | | }, |
| 815 | | .name = try wc.addString(option.name), |
| 816 | | .value = .{ .u = try s.makeUserValue(&option.value) }, |
| 817 | | }); |
| 822 | { |
| 823 | var i: usize = 0; |
| 824 | var iter = b.user_input_options.valueIterator(); |
| 825 | while (iter.next()) |option| : (i += 1) { |
| 826 | options[i] = try wc.addExtra(Configuration.PackageInstance.UserInputOption, .{ |
| 827 | .flags = .{ |
| 828 | .tag = .init(option.value), |
| 829 | .used = option.used, |
| 830 | }, |
| 831 | .name = try wc.addString(option.name), |
| 832 | .value = .{ .u = try s.makeUserValue(&option.value) }, |
| 833 | }); |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | const modules_keys = try arena.alloc( |
| 838 | []const u8, |
| 839 | b.modules.count(), |
| 840 | ); |
| 841 | const modules_values = try arena.alloc( |
| 842 | Configuration.Module.Index, |
| 843 | b.modules.count(), |
| 844 | ); |
| 845 | |
| 846 | { |
| 847 | var i: usize = 0; |
| 848 | var iter = b.modules.iterator(); |
| 849 | while (iter.next()) |entry| : (i += 1) { |
| 850 | modules_keys[i] = entry.key_ptr.*; |
| 851 | modules_values[i] = try s.addModule(entry.value_ptr.*); |
| 852 | } |
| 818 | 853 | } |
| 819 | 854 | |
| 820 | | try wc.package_instances.append(wc.gpa, .{ |
| 855 | wc.package_instances.items[index] = .{ |
| 821 | 856 | .package = s.packageFromHash(b.pkg_hash), |
| 822 | 857 | .user_input_options = try wc.addDeduped(Configuration.PackageInstance.UserInputOption.List, .{ |
| 823 | 858 | .options = .{ .slice = options }, |
| 824 | 859 | }), |
| 825 | | }); |
| 826 | | |
| 827 | | try s.package_instance_map.put(arena, b, {}); |
| 860 | .modules = .{ |
| 861 | .keys = try wc.addStringList(modules_keys), |
| 862 | .values = try wc.addDeduped(Configuration.Module.List, .{ |
| 863 | .modules = .{ .slice = modules_values }, |
| 864 | }), |
| 865 | }, |
| 866 | }; |
| 828 | 867 | } |
| 829 | 868 | |
| 830 | 869 | fn makeUserValue(s: *Serialize, user_value: *const std.Build.UserValue) Allocator.Error!Configuration.PackageInstance.UserValue { |
| ... | ... | @@ -1336,7 +1375,7 @@ fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index { |
| 1336 | 1375 | const c_macros = try initStringList(s, m.c_macros.items); |
| 1337 | 1376 | const export_symbol_names = try initStringList(s, m.export_symbol_names); |
| 1338 | 1377 | |
| 1339 | | const module_index: Configuration.Module.Index = try wc.addExtra(Configuration.Module, .{ |
| 1378 | const module_index: Configuration.Module.Index = try wc.addDeduped(Configuration.Module, .{ |
| 1340 | 1379 | .flags = .{ |
| 1341 | 1380 | .optimize = .init(m.optimize), |
| 1342 | 1381 | .strip = .init(m.strip), |