| ... | ... | @@ -279,7 +279,7 @@ const Serialize = struct { |
| 279 | 279 | return (try addOptionalLazyPathEnum(s, lp)).unwrap(); |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | | fn addLazyPath(s: *Serialize, lp: ?std.Build.LazyPath) !Configuration.LazyPath { |
| 282 | fn addLazyPath(s: *Serialize, lp: std.Build.LazyPath) !Configuration.LazyPath { |
| 283 | 283 | return @enumFromInt(@intFromEnum(try addOptionalLazyPathEnum(s, lp))); |
| 284 | 284 | } |
| 285 | 285 | |
| ... | ... | @@ -304,6 +304,86 @@ const Serialize = struct { |
| 304 | 304 | for (result, list) |*dest, src| dest.* = try wc.addOptionalString(src); |
| 305 | 305 | return result; |
| 306 | 306 | } |
| 307 | |
| 308 | fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index { |
| 309 | if (s.module_map.get(m)) |index| return index; |
| 310 | |
| 311 | const wc = s.wc; |
| 312 | const arena = s.arena; |
| 313 | const gpa = wc.gpa; |
| 314 | |
| 315 | const lib_paths = try arena.alloc(Configuration.LazyPath, m.lib_paths.items.len); |
| 316 | for (lib_paths, m.lib_paths.items) |*dest, src| dest.* = try addLazyPath(s, src); |
| 317 | |
| 318 | const c_macros = try initStringList(s, m.c_macros.items); |
| 319 | const export_symbol_names = try initStringList(s, m.export_symbol_names); |
| 320 | |
| 321 | const import_table: Configuration.ImportTable = @enumFromInt(wc.extra.items.len); |
| 322 | const import_table_extra_len = 1 + 2 * m.import_table.entries.len; |
| 323 | try wc.extra.ensureUnusedCapacity(gpa, import_table_extra_len); |
| 324 | wc.extra.items.len += import_table_extra_len; |
| 325 | wc.extra.appendAssumeCapacity(@intCast(m.import_table.entries.len)); |
| 326 | wc.extra.items[@intFromEnum(import_table)] = @intCast(m.import_table.entries.len); |
| 327 | for ( |
| 328 | m.import_table.keys(), |
| 329 | @intFromEnum(import_table) + 1.., |
| 330 | ) |mod_name, extra_index| { |
| 331 | wc.extra.items[extra_index] = @intFromEnum(try wc.addString(mod_name)); |
| 332 | } |
| 333 | for ( |
| 334 | m.import_table.values(), |
| 335 | @intFromEnum(import_table) + 1 + m.import_table.entries.len.., |
| 336 | ) |dep, extra_index| { |
| 337 | log.err("TODO module dependencies can be cyclic", .{}); |
| 338 | wc.extra.items[extra_index] = @intFromEnum(try addModule(s, dep)); |
| 339 | } |
| 340 | |
| 341 | const module_index: Configuration.Module.Index = @enumFromInt(try wc.addExtra(@as(Configuration.Module, .{ |
| 342 | .flags = .{ |
| 343 | .optimize = .init(m.optimize), |
| 344 | .strip = .init(m.strip), |
| 345 | .unwind_tables = .init(m.unwind_tables), |
| 346 | .dwarf_format = .init(m.dwarf_format), |
| 347 | .single_threaded = .init(m.strip), |
| 348 | .stack_protector = .init(m.strip), |
| 349 | .stack_check = .init(m.strip), |
| 350 | .sanitize_c = .init(m.sanitize_c), |
| 351 | .sanitize_thread = .init(m.strip), |
| 352 | .fuzz = .init(m.strip), |
| 353 | .code_model = m.code_model, |
| 354 | .c_macros = c_macros.len != 0, |
| 355 | .include_dirs = m.include_dirs.items.len != 0, |
| 356 | .lib_paths = lib_paths.len != 0, |
| 357 | .rpaths = m.rpaths.items.len != 0, |
| 358 | .frameworks = m.frameworks.entries.len != 0, |
| 359 | .link_objects = m.link_objects.items.len != 0, |
| 360 | .export_symbol_names = export_symbol_names.len != 0, |
| 361 | }, |
| 362 | .flags2 = .{ |
| 363 | .valgrind = .init(m.strip), |
| 364 | .pic = .init(m.strip), |
| 365 | .red_zone = .init(m.strip), |
| 366 | .omit_frame_pointer = .init(m.strip), |
| 367 | .error_tracing = .init(m.strip), |
| 368 | .link_libc = .init(m.strip), |
| 369 | .link_libcpp = .init(m.strip), |
| 370 | .no_builtin = .init(m.strip), |
| 371 | }, |
| 372 | .owner = try s.builderToPackage(m.owner), |
| 373 | .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file), |
| 374 | .import_table = import_table, |
| 375 | .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target), |
| 376 | .c_macros = .{ .slice = c_macros }, |
| 377 | .lib_paths = .{ .slice = lib_paths }, |
| 378 | .export_symbol_names = .{ .slice = export_symbol_names }, |
| 379 | }))); |
| 380 | |
| 381 | log.err("TODO serialize the trailing Module data", .{}); |
| 382 | |
| 383 | try s.module_map.putNoClobber(arena, m, module_index); |
| 384 | |
| 385 | return module_index; |
| 386 | } |
| 307 | 387 | }; |
| 308 | 388 | |
| 309 | 389 | fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| ... | ... | @@ -479,7 +559,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 479 | 559 | .linker_script = c.linker_script != null, |
| 480 | 560 | .version_script = c.version_script != null, |
| 481 | 561 | }, |
| 482 | | .root_module = try addModule(&s, c.root_module), |
| 562 | .root_module = try s.addModule(c.root_module), |
| 483 | 563 | .root_name = try wc.addString(c.name), |
| 484 | 564 | .linker_script = .{ .value = try s.addOptionalLazyPath(c.linker_script) }, |
| 485 | 565 | .version_script = .{ .value = try s.addOptionalLazyPath(c.version_script) }, |
| ... | ... | @@ -612,75 +692,6 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 612 | 692 | }); |
| 613 | 693 | } |
| 614 | 694 | |
| 615 | | fn addModule(s: *Serialize, m: *std.Build.Module) !Configuration.Module.Index { |
| 616 | | if (s.module_map.get(m)) |index| return index; |
| 617 | | |
| 618 | | const wc = s.wc; |
| 619 | | const arena = s.arena; |
| 620 | | const gpa = wc.gpa; |
| 621 | | const import_table: Configuration.ImportTable = @enumFromInt(wc.extra.items.len); |
| 622 | | const import_table_extra_len = 1 + 2 * m.import_table.entries.len; |
| 623 | | try wc.extra.ensureUnusedCapacity(gpa, import_table_extra_len); |
| 624 | | wc.extra.items.len += import_table_extra_len; |
| 625 | | wc.extra.appendAssumeCapacity(@intCast(m.import_table.entries.len)); |
| 626 | | wc.extra.items[@intFromEnum(import_table)] = @intCast(m.import_table.entries.len); |
| 627 | | for ( |
| 628 | | m.import_table.keys(), |
| 629 | | @intFromEnum(import_table) + 1.., |
| 630 | | ) |mod_name, extra_index| { |
| 631 | | wc.extra.items[extra_index] = @intFromEnum(try wc.addString(mod_name)); |
| 632 | | } |
| 633 | | for ( |
| 634 | | m.import_table.values(), |
| 635 | | @intFromEnum(import_table) + 1 + m.import_table.entries.len.., |
| 636 | | ) |dep, extra_index| { |
| 637 | | log.err("TODO module dependencies can be cyclic", .{}); |
| 638 | | wc.extra.items[extra_index] = @intFromEnum(try addModule(s, dep)); |
| 639 | | } |
| 640 | | |
| 641 | | const module_index: Configuration.Module.Index = @enumFromInt(try wc.addExtra(@as(Configuration.Module, .{ |
| 642 | | .flags = .{ |
| 643 | | .optimize = .init(m.optimize), |
| 644 | | .strip = .init(m.strip), |
| 645 | | .unwind_tables = .init(m.unwind_tables), |
| 646 | | .dwarf_format = .init(m.dwarf_format), |
| 647 | | .single_threaded = .init(m.strip), |
| 648 | | .stack_protector = .init(m.strip), |
| 649 | | .stack_check = .init(m.strip), |
| 650 | | .sanitize_c = .init(m.sanitize_c), |
| 651 | | .sanitize_thread = .init(m.strip), |
| 652 | | .fuzz = .init(m.strip), |
| 653 | | .code_model = m.code_model, |
| 654 | | .c_macros = m.c_macros.items.len != 0, |
| 655 | | .include_dirs = m.include_dirs.items.len != 0, |
| 656 | | .lib_paths = m.lib_paths.items.len != 0, |
| 657 | | .rpaths = m.rpaths.items.len != 0, |
| 658 | | .frameworks = m.frameworks.entries.len != 0, |
| 659 | | .link_objects = m.link_objects.items.len != 0, |
| 660 | | .export_symbol_names = m.export_symbol_names.len != 0, |
| 661 | | |
| 662 | | .valgrind = .init(m.strip), |
| 663 | | .pic = .init(m.strip), |
| 664 | | .red_zone = .init(m.strip), |
| 665 | | .omit_frame_pointer = .init(m.strip), |
| 666 | | .error_tracing = .init(m.strip), |
| 667 | | .link_libc = .init(m.strip), |
| 668 | | .link_libcpp = .init(m.strip), |
| 669 | | .no_builtin = .init(m.strip), |
| 670 | | }, |
| 671 | | .owner = try s.builderToPackage(m.owner), |
| 672 | | .root_source_file = try s.addOptionalLazyPathEnum(m.root_source_file), |
| 673 | | .import_table = import_table, |
| 674 | | .resolved_target = try addOptionalResolvedTarget(wc, m.resolved_target), |
| 675 | | }))); |
| 676 | | |
| 677 | | log.err("TODO serialize the trailing Module data", .{}); |
| 678 | | |
| 679 | | try s.module_map.putNoClobber(arena, m, module_index); |
| 680 | | |
| 681 | | return module_index; |
| 682 | | } |
| 683 | | |
| 684 | 695 | fn addOptionalResolvedTarget( |
| 685 | 696 | wc: *Configuration.Wip, |
| 686 | 697 | optional_resolved_target: ?std.Build.ResolvedTarget, |