aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-01-22 16:12:40 +0000
committermlugg <mlugg@mlugg.co.uk>2023-01-22 19:00:03 +0000
commit6d71d79dc27ddd6f66913a34fd6cd40691a8c959 (patch)
treed6fd9f56beb9ba26545a12f5fa827d91aec81972 /src/Compilation.zig
parentc0284e242f7d78955204dc8a627fecd45aa5e521 (diff)
downloadzig-6d71d79dc27ddd6f66913a34fd6cd40691a8c959.tar.gz
zig-6d71d79dc27ddd6f66913a34fd6cd40691a8c959.zip
Package: store package name directly
By @Vexu's suggestion, since fetching the name from the parent package is error-prone and complex, and optimising Package for size isn't really a priority.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index b0af925e29..98e38f4305 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1610,6 +1610,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const builtin_pkg = try Package.createWithDir(
gpa,
+ "builtin",
zig_cache_artifact_directory,
null,
"builtin.zig",
@@ -1618,6 +1619,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const std_pkg = try Package.createWithDir(
gpa,
+ "std",
options.zig_lib_directory,
"std",
"std.zig",
@@ -1625,11 +1627,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
errdefer std_pkg.destroy(gpa);
const root_pkg = if (options.is_test) root_pkg: {
+ // TODO: we currently have two packages named 'root' here, which is weird. This
+ // should be changed as part of the resolution of #12201
const test_pkg = if (options.test_runner_path) |test_runner|
- try Package.create(gpa, null, test_runner)
+ try Package.create(gpa, "root", null, test_runner)
else
try Package.createWithDir(
gpa,
+ "root",
options.zig_lib_directory,
null,
"test_runner.zig",
@@ -1640,9 +1645,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
} else main_pkg;
errdefer if (options.is_test) root_pkg.destroy(gpa);
- 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 main_pkg.addAndAdopt(gpa, builtin_pkg);
+ try main_pkg.add(gpa, root_pkg);
+ try main_pkg.addAndAdopt(gpa, std_pkg);
const main_pkg_is_std = m: {
const std_path = try std.fs.path.resolve(arena, &[_][]const u8{
@@ -5320,6 +5325,7 @@ fn buildOutputFromZig(
var main_pkg: Package = .{
.root_src_directory = comp.zig_lib_directory,
.root_src_path = src_basename,
+ .name = "root",
};
defer main_pkg.deinitTable(comp.gpa);
const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len];