diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-28 15:20:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-28 15:20:49 -0700 |
| commit | e6b3eae490e4d0c427034c3530be4ed5a74e2253 (patch) | |
| tree | 7934bd543a744c6f7da7ba9527a7656088d1c3f8 /src | |
| parent | 0fc79d602bf9b3a5c97cfc28b59193b005692cb2 (diff) | |
| parent | ece1d1daf476fdffc69279c686ad1e2101ce6e4d (diff) | |
| download | zig-e6b3eae490e4d0c427034c3530be4ed5a74e2253.tar.gz zig-e6b3eae490e4d0c427034c3530be4ed5a74e2253.zip | |
Merge pull request #11867 from nektro/patch-2
stage2: ensure builtin packages are always available
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 17 | ||||
| -rw-r--r-- | src/Module.zig | 9 | ||||
| -rw-r--r-- | src/Sema.zig | 4 | ||||
| -rw-r--r-- | src/main.zig | 6 |
4 files changed, 15 insertions, 21 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 869cd43f0f..17ffe356a3 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1494,31 +1494,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { ); errdefer test_pkg.destroy(gpa); - try test_pkg.add(gpa, "builtin", builtin_pkg); - try test_pkg.add(gpa, "root", test_pkg); - try test_pkg.add(gpa, "std", std_pkg); - break :root_pkg test_pkg; } else main_pkg; errdefer if (options.is_test) root_pkg.destroy(gpa); - var other_pkg_iter = main_pkg.table.valueIterator(); - while (other_pkg_iter.next()) |pkg| { - try pkg.*.add(gpa, "builtin", builtin_pkg); - try pkg.*.add(gpa, "std", std_pkg); - } - try main_pkg.addAndAdopt(gpa, "builtin", builtin_pkg); try main_pkg.add(gpa, "root", root_pkg); try main_pkg.addAndAdopt(gpa, "std", std_pkg); - try std_pkg.add(gpa, "builtin", builtin_pkg); - try std_pkg.add(gpa, "root", root_pkg); - try std_pkg.add(gpa, "std", std_pkg); - - try builtin_pkg.add(gpa, "std", std_pkg); - try builtin_pkg.add(gpa, "builtin", builtin_pkg); - const main_pkg_in_std = m: { const std_path = try std.fs.path.resolve(arena, &[_][]const u8{ std_pkg.root_src_directory.path orelse ".", diff --git a/src/Module.zig b/src/Module.zig index 4576538a35..397134d911 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4673,6 +4673,15 @@ pub fn importFile( cur_file: *File, import_string: []const u8, ) !ImportFileResult { + if (std.mem.eql(u8, import_string, "std")) { + return mod.importPkg(mod.main_pkg.table.get("std").?); + } + if (std.mem.eql(u8, import_string, "builtin")) { + return mod.importPkg(mod.main_pkg.table.get("builtin").?); + } + if (std.mem.eql(u8, import_string, "root")) { + return mod.importPkg(mod.root_pkg); + } if (cur_file.pkg.table.get(import_string)) |pkg| { return mod.importPkg(pkg); } diff --git a/src/Sema.zig b/src/Sema.zig index ad8beff0f3..ac9e24a9be 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4674,10 +4674,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr error.OutOfMemory => return error.OutOfMemory, else => unreachable, // we pass null for root_src_dir_path }; - const std_pkg = mod.main_pkg.table.get("std").?; - const builtin_pkg = mod.main_pkg.table.get("builtin").?; - try c_import_pkg.add(sema.gpa, "builtin", builtin_pkg); - try c_import_pkg.add(sema.gpa, "std", std_pkg); const result = mod.importPkg(c_import_pkg) catch |err| return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); diff --git a/src/main.zig b/src/main.zig index bd86cd2bb9..f2291a0646 100644 --- a/src/main.zig +++ b/src/main.zig @@ -858,6 +858,12 @@ fn buildOutputType( ) catch |err| { fatal("Failed to add package at path {s}: {s}", .{ pkg_path.?, @errorName(err) }); }; + + if (mem.eql(u8, pkg_name.?, "std") or mem.eql(u8, pkg_name.?, "root") or mem.eql(u8, pkg_name.?, "builtin")) { + fatal("unable to add package '{s}' -> '{s}': conflicts with builtin package", .{ pkg_name.?, pkg_path.? }); + } else if (cur_pkg.table.get(pkg_name.?)) |prev| { + fatal("unable to add package '{s}' -> '{s}': already exists as '{s}", .{ pkg_name.?, pkg_path.?, prev.root_src_path }); + } try cur_pkg.addAndAdopt(gpa, pkg_name.?, new_cur_pkg); cur_pkg = new_cur_pkg; } else if (mem.eql(u8, arg, "--pkg-end")) { |
