| author | |
| committer | |
| log | e6b3eae490e4d0c427034c3530be4ed5a74e2253 |
| tree | 7934bd543a744c6f7da7ba9527a7656088d1c3f8 |
| parent | 0fc79d602bf9b3a5c97cfc28b59193b005692cb2 |
| parent | ece1d1daf476fdffc69279c686ad1e2101ce6e4d |
| signature |
stage2: ensure builtin packages are always available4 files changed, 15 insertions(+), 21 deletions(-)
src/Compilation.zig-17| ... | @@ -1494,31 +1494,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1494,31 +1494,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1494 | ); | 1494 | ); |
| 1495 | errdefer test_pkg.destroy(gpa); | 1495 | errdefer test_pkg.destroy(gpa); |
| 1496 | 1496 | ||
| 1497 | try test_pkg.add(gpa, "builtin", builtin_pkg); | ||
| 1498 | try test_pkg.add(gpa, "root", test_pkg); | ||
| 1499 | try test_pkg.add(gpa, "std", std_pkg); | ||
| 1500 | |||
| 1501 | break :root_pkg test_pkg; | 1497 | break :root_pkg test_pkg; |
| 1502 | } else main_pkg; | 1498 | } else main_pkg; |
| 1503 | errdefer if (options.is_test) root_pkg.destroy(gpa); | 1499 | errdefer if (options.is_test) root_pkg.destroy(gpa); |
| 1504 | 1500 | ||
| 1505 | var other_pkg_iter = main_pkg.table.valueIterator(); | ||
| 1506 | while (other_pkg_iter.next()) |pkg| { | ||
| 1507 | try pkg.*.add(gpa, "builtin", builtin_pkg); | ||
| 1508 | try pkg.*.add(gpa, "std", std_pkg); | ||
| 1509 | } | ||
| 1510 | |||
| 1511 | try main_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); | 1501 | try main_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); |
| 1512 | try main_pkg.add(gpa, "root", root_pkg); | 1502 | try main_pkg.add(gpa, "root", root_pkg); |
| 1513 | try main_pkg.addAndAdopt(gpa, "std", std_pkg); | 1503 | try main_pkg.addAndAdopt(gpa, "std", std_pkg); |
| 1514 | 1504 | ||
| 1515 | try std_pkg.add(gpa, "builtin", builtin_pkg); | ||
| 1516 | try std_pkg.add(gpa, "root", root_pkg); | ||
| 1517 | try std_pkg.add(gpa, "std", std_pkg); | ||
| 1518 | |||
| 1519 | try builtin_pkg.add(gpa, "std", std_pkg); | ||
| 1520 | try builtin_pkg.add(gpa, "builtin", builtin_pkg); | ||
| 1521 | |||
| 1522 | const main_pkg_in_std = m: { | 1505 | const main_pkg_in_std = m: { |
| 1523 | const std_path = try std.fs.path.resolve(arena, &[_][]const u8{ | 1506 | const std_path = try std.fs.path.resolve(arena, &[_][]const u8{ |
| 1524 | std_pkg.root_src_directory.path orelse ".", | 1507 | std_pkg.root_src_directory.path orelse ".", |
src/Module.zig+9| ... | @@ -4673,6 +4673,15 @@ pub fn importFile( | ... | @@ -4673,6 +4673,15 @@ pub fn importFile( |
| 4673 | cur_file: *File, | 4673 | cur_file: *File, |
| 4674 | import_string: []const u8, | 4674 | import_string: []const u8, |
| 4675 | ) !ImportFileResult { | 4675 | ) !ImportFileResult { |
| 4676 | if (std.mem.eql(u8, import_string, "std")) { | ||
| 4677 | return mod.importPkg(mod.main_pkg.table.get("std").?); | ||
| 4678 | } | ||
| 4679 | if (std.mem.eql(u8, import_string, "builtin")) { | ||
| 4680 | return mod.importPkg(mod.main_pkg.table.get("builtin").?); | ||
| 4681 | } | ||
| 4682 | if (std.mem.eql(u8, import_string, "root")) { | ||
| 4683 | return mod.importPkg(mod.root_pkg); | ||
| 4684 | } | ||
| 4676 | if (cur_file.pkg.table.get(import_string)) |pkg| { | 4685 | if (cur_file.pkg.table.get(import_string)) |pkg| { |
| 4677 | return mod.importPkg(pkg); | 4686 | return mod.importPkg(pkg); |
| 4678 | } | 4687 | } |
src/Sema.zig-4| ... | @@ -4674,10 +4674,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4674,10 +4674,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 4674 | error.OutOfMemory => return error.OutOfMemory, | 4674 | error.OutOfMemory => return error.OutOfMemory, |
| 4675 | else => unreachable, // we pass null for root_src_dir_path | 4675 | else => unreachable, // we pass null for root_src_dir_path |
| 4676 | }; | 4676 | }; |
| 4677 | const std_pkg = mod.main_pkg.table.get("std").?; | ||
| 4678 | const builtin_pkg = mod.main_pkg.table.get("builtin").?; | ||
| 4679 | try c_import_pkg.add(sema.gpa, "builtin", builtin_pkg); | ||
| 4680 | try c_import_pkg.add(sema.gpa, "std", std_pkg); | ||
| 4681 | 4677 | ||
| 4682 | const result = mod.importPkg(c_import_pkg) catch |err| | 4678 | const result = mod.importPkg(c_import_pkg) catch |err| |
| 4683 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); | 4679 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
src/main.zig+6| ... | @@ -858,6 +858,12 @@ fn buildOutputType( | ... | @@ -858,6 +858,12 @@ fn buildOutputType( |
| 858 | ) catch |err| { | 858 | ) catch |err| { |
| 859 | fatal("Failed to add package at path {s}: {s}", .{ pkg_path.?, @errorName(err) }); | 859 | fatal("Failed to add package at path {s}: {s}", .{ pkg_path.?, @errorName(err) }); |
| 860 | }; | 860 | }; |
| 861 | |||
| 862 | if (mem.eql(u8, pkg_name.?, "std") or mem.eql(u8, pkg_name.?, "root") or mem.eql(u8, pkg_name.?, "builtin")) { | ||
| 863 | fatal("unable to add package '{s}' -> '{s}': conflicts with builtin package", .{ pkg_name.?, pkg_path.? }); | ||
| 864 | } else if (cur_pkg.table.get(pkg_name.?)) |prev| { | ||
| 865 | fatal("unable to add package '{s}' -> '{s}': already exists as '{s}", .{ pkg_name.?, pkg_path.?, prev.root_src_path }); | ||
| 866 | } | ||
| 861 | try cur_pkg.addAndAdopt(gpa, pkg_name.?, new_cur_pkg); | 867 | try cur_pkg.addAndAdopt(gpa, pkg_name.?, new_cur_pkg); |
| 862 | cur_pkg = new_cur_pkg; | 868 | cur_pkg = new_cur_pkg; |
| 863 | } else if (mem.eql(u8, arg, "--pkg-end")) { | 869 | } else if (mem.eql(u8, arg, "--pkg-end")) { |