| author | |
| committer | |
| log | df92898ec3f805112150ee4b40e0d02b763524bb |
| tree | 622e6e9dcc7d72c344973ec5ecd28b305246df3b |
| parent | 619f23b3c7a5276ab974478223ec41ce81c91b6c |
Currently, neither configurer nor Maker is aware of the standard zig
package path, and the root path is stored as a bare string rather than
relative to a known base directory. Without changing that, we must
construct a cwd relative path here rather than using knowledge of the
standard package path plus package hash.
Also fixes a bug that would have been prevented by implementing the
accepted proposal https://github.com/ziglang/zig/issues/253158 files changed, 56 insertions(+), 44 deletions(-)
lib/compiler/Maker.zig+6-8| ... | ... | @@ -123,10 +123,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 123 | 123 | .local_cache_root = local_cache_directory, |
| 124 | 124 | .zig_lib_directory = zig_lib_directory, |
| 125 | 125 | .build_root_directory = build_root_directory, |
| 126 | .pkg_root = .{ | |
| 127 | .root_dir = build_root_directory, | |
| 128 | .sub_path = "zig-pkg", | |
| 129 | }, | |
| 130 | 126 | }; |
| 131 | 127 | |
| 132 | 128 | graph.cache.addPrefix(.{ .path = null, .handle = cwd }); |
| ... | ... | @@ -1779,11 +1775,13 @@ pub fn packagePath( |
| 1779 | 1775 | .root_dir = graph.build_root_directory, |
| 1780 | 1776 | .sub_path = sub_path, |
| 1781 | 1777 | }; |
| 1782 | const hash = package.hash.slice(c); | |
| 1783 | const pkg_root = graph.pkg_root; | |
| 1778 | // Currently, neither configurer nor Maker is aware of the standard zig | |
| 1779 | // package path, and the root path is stored as a bare string rather than | |
| 1780 | // relative to a known base directory. Without changing that, we must | |
| 1781 | // construct a cwd relative path here. | |
| 1784 | 1782 | return .{ |
| 1785 | .root_dir = pkg_root.root_dir, | |
| 1786 | .sub_path = try Dir.path.join(arena, &.{ pkg_root.sub_path, hash, sub_path }), | |
| 1783 | .root_dir = .cwd(), | |
| 1784 | .sub_path = try Dir.path.join(arena, &.{ package.root_path.slice(c), sub_path }), | |
| 1787 | 1785 | }; |
| 1788 | 1786 | } |
| 1789 | 1787 |
lib/compiler/Maker/Graph.zig-1| ... | ... | @@ -18,7 +18,6 @@ global_cache_root: Directory, |
| 18 | 18 | local_cache_root: Directory, |
| 19 | 19 | zig_lib_directory: Directory, |
| 20 | 20 | build_root_directory: Directory, |
| 21 | pkg_root: Path, | |
| 22 | 21 | |
| 23 | 22 | debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null, |
| 24 | 23 | incremental: ?bool = null, |
lib/compiler/configurer.zig+12-10| ... | ... | @@ -169,6 +169,7 @@ const Serialize = struct { |
| 169 | 169 | gop.value_ptr.* = @enumFromInt(try wc.addExtra(@as(Configuration.Package, .{ |
| 170 | 170 | .hash = try wc.addString(b.pkg_hash), |
| 171 | 171 | .dep_prefix = try wc.addString(b.dep_prefix), |
| 172 | .root_path = try wc.addString(try b.root.toString(arena)), | |
| 172 | 173 | }))); |
| 173 | 174 | } |
| 174 | 175 | return gop.value_ptr.*; |
| ... | ... | @@ -233,7 +234,7 @@ const Serialize = struct { |
| 233 | 234 | |
| 234 | 235 | fn addSystemLib(s: *Serialize, sl: *const std.Build.Module.SystemLib) !Configuration.SystemLib.Index { |
| 235 | 236 | const wc = s.wc; |
| 236 | return @enumFromInt(try wc.addDeduped(@as(Configuration.SystemLib, .{ | |
| 237 | return try wc.addDeduped(Configuration.SystemLib, .{ | |
| 237 | 238 | .flags = .{ |
| 238 | 239 | .needed = sl.needed, |
| 239 | 240 | .weak = sl.weak, |
| ... | ... | @@ -242,7 +243,7 @@ const Serialize = struct { |
| 242 | 243 | .search_strategy = sl.search_strategy, |
| 243 | 244 | }, |
| 244 | 245 | .name = try wc.addString(sl.name), |
| 245 | }))); | |
| 246 | }); | |
| 246 | 247 | } |
| 247 | 248 | |
| 248 | 249 | fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index { |
| ... | ... | @@ -291,10 +292,10 @@ const Serialize = struct { |
| 291 | 292 | fn addEnvironMap(s: *Serialize, opt_map: ?*std.process.Environ.Map) !?Configuration.EnvironMap.Index { |
| 292 | 293 | const wc = s.wc; |
| 293 | 294 | const map = opt_map orelse return null; |
| 294 | return @enumFromInt(try wc.addDeduped(@as(Configuration.EnvironMap, .{ | |
| 295 | return try wc.addDeduped(Configuration.EnvironMap, .{ | |
| 295 | 296 | .keys = try wc.addStringList(map.array_hash_map.keys()), |
| 296 | 297 | .values = try wc.addStringList(map.array_hash_map.values()), |
| 297 | }))); | |
| 298 | }); | |
| 298 | 299 | } |
| 299 | 300 | |
| 300 | 301 | fn initArgsList(s: *Serialize, args: []const Step.Run.Arg) ![]const Configuration.Step.Run.Arg.Index { |
| ... | ... | @@ -643,9 +644,10 @@ const Serialize = struct { |
| 643 | 644 | comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".fields[2].name, "import_table")); |
| 644 | 645 | comptime assert(@typeInfo(Configuration.Module).@"struct".fields[2].type == Configuration.ImportTable.Index); |
| 645 | 646 | assert(wc.extra.items[@intFromEnum(module_index) + 2] == @intFromEnum(Configuration.ImportTable.Index.invalid)); |
| 646 | wc.extra.items[@intFromEnum(module_index) + 2] = try wc.addDeduped(@as(Configuration.ImportTable, .{ | |
| 647 | const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{ | |
| 647 | 648 | .imports = .{ .mal = imports }, |
| 648 | })); | |
| 649 | }); | |
| 650 | wc.extra.items[@intFromEnum(module_index) + 2] = @intFromEnum(import_table_index); | |
| 649 | 651 | |
| 650 | 652 | return module_index; |
| 651 | 653 | } |
| ... | ... | @@ -687,9 +689,9 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void { |
| 687 | 689 | for (dep_steps, step.dependencies.items) |*dest, src| |
| 688 | 690 | dest.* = @enumFromInt(s.step_map.getIndex(src).?); |
| 689 | 691 | |
| 690 | const deps: Configuration.Deps.Index = @enumFromInt(try wc.addDeduped(@as(Configuration.Deps, .{ | |
| 692 | const deps: Configuration.Deps.Index = try wc.addDeduped(Configuration.Deps, .{ | |
| 691 | 693 | .steps = .{ .slice = dep_steps }, |
| 692 | }))); | |
| 694 | }); | |
| 693 | 695 | |
| 694 | 696 | try wc.steps.ensureTotalCapacity(gpa, s.step_map.entries.capacity); |
| 695 | 697 | wc.steps.appendAssumeCapacity(.{ |
| ... | ... | @@ -1278,10 +1280,10 @@ fn addOptionalResolvedTarget( |
| 1278 | 1280 | optional_resolved_target: ?std.Build.ResolvedTarget, |
| 1279 | 1281 | ) !Configuration.ResolvedTarget.OptionalIndex { |
| 1280 | 1282 | const resolved_target = optional_resolved_target orelse return .none; |
| 1281 | return @enumFromInt(try wc.addDeduped(@as(Configuration.ResolvedTarget, .{ | |
| 1283 | return .init(try wc.addDeduped(Configuration.ResolvedTarget, .{ | |
| 1282 | 1284 | .query = try wc.addTargetQuery(&resolved_target.query), |
| 1283 | 1285 | .result = try wc.addTarget(resolved_target.result), |
| 1284 | }))); | |
| 1286 | })); | |
| 1285 | 1287 | } |
| 1286 | 1288 | |
| 1287 | 1289 | fn addInstallDir(wc: *Configuration.Wip, install_dir: ?std.Build.InstallDir) !Configuration.InstallDestDir { |
lib/std/Build.zig+1| ... | ... | @@ -1896,6 +1896,7 @@ fn markNeededLazyDep(b: *Build, pkg_hash: []const u8) void { |
| 1896 | 1896 | /// In other words, if this function returns `null` it means that the only |
| 1897 | 1897 | /// purpose of completing the configure phase is to find out all the other lazy |
| 1898 | 1898 | /// dependencies that are also required. |
| 1899 | /// | |
| 1899 | 1900 | /// It is allowed to use this function for non-lazy dependencies, in which case |
| 1900 | 1901 | /// it will never return `null`. This allows toggling laziness via |
| 1901 | 1902 | /// build.zig.zon without changing build.zig logic. |
lib/std/Build/Cache/Path.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ pub fn cwd() Path { |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | pub fn initCwd(sub_path: []const u8) Path { |
| 27 | return .{ .root_dir = Cache.Directory.cwd(), .sub_path = sub_path }; | |
| 27 | return .{ .root_dir = .cwd(), .sub_path = sub_path }; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | pub fn join(p: Path, arena: Allocator, sub_path: []const u8) Allocator.Error!Path { |
lib/std/Build/Configuration.zig+17-7| ... | ... | @@ -374,25 +374,28 @@ pub const Wip = struct { |
| 374 | 374 | |
| 375 | 375 | /// Same as `addExtra` but uses a hash map to possibly return an already |
| 376 | 376 | /// existing index instead of appending to `extra`. |
| 377 | pub fn addDeduped(wip: *Wip, extra: anytype) Allocator.Error!u32 { | |
| 377 | pub fn addDeduped(wip: *Wip, comptime T: type, v: T) Allocator.Error!T.Index { | |
| 378 | 378 | const gpa = wip.gpa; |
| 379 | 379 | const revert_index = wip.extra.items.len; |
| 380 | const extra_len = Storage.extraLen(extra); | |
| 381 | try wip.extra.ensureUnusedCapacity(gpa, extra_len); | |
| 382 | const new_index = addExtraAssumeCapacity(wip, extra); | |
| 380 | const upper_bound_len = Storage.extraLen(v); | |
| 381 | try wip.extra.ensureUnusedCapacity(gpa, upper_bound_len); | |
| 382 | try wip.dedupe_table.ensureUnusedCapacityContext(gpa, 1, @as(ExtraSlice.Context, .{ | |
| 383 | .extra = wip.extra.items, | |
| 384 | })); | |
| 385 | const new_index = addExtraAssumeCapacity(wip, v); | |
| 383 | 386 | const len: u32 = @intCast(wip.extra.items.len - new_index); |
| 384 | 387 | assert(len != 0); |
| 385 | const gop = try wip.dedupe_table.getOrPutContext(gpa, .{ | |
| 388 | const gop = wip.dedupe_table.getOrPutAssumeCapacityContext(.{ | |
| 386 | 389 | .index = new_index, |
| 387 | 390 | .len = len, |
| 388 | 391 | }, @as(ExtraSlice.Context, .{ .extra = wip.extra.items })); |
| 389 | 392 | |
| 390 | 393 | if (gop.found_existing) { |
| 391 | 394 | wip.extra.items.len = revert_index; |
| 392 | return gop.key_ptr.index; | |
| 395 | return @enumFromInt(gop.key_ptr.index); | |
| 393 | 396 | } |
| 394 | 397 | |
| 395 | return new_index; | |
| 398 | return @enumFromInt(new_index); | |
| 396 | 399 | } |
| 397 | 400 | |
| 398 | 401 | pub fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 { |
| ... | ... | @@ -1518,6 +1521,7 @@ pub const OptionalGeneratedFileIndex = enum(u32) { |
| 1518 | 1521 | pub const Package = struct { |
| 1519 | 1522 | dep_prefix: String, |
| 1520 | 1523 | hash: String, |
| 1524 | root_path: String, | |
| 1521 | 1525 | |
| 1522 | 1526 | pub const Index = enum(u32) { |
| 1523 | 1527 | root = max_u32, |
| ... | ... | @@ -2075,6 +2079,12 @@ pub const ResolvedTarget = struct { |
| 2075 | 2079 | none = max_u32, |
| 2076 | 2080 | _, |
| 2077 | 2081 | |
| 2082 | pub fn init(i: Index) OptionalIndex { | |
| 2083 | const result: OptionalIndex = @enumFromInt(@intFromEnum(i)); | |
| 2084 | assert(result != .none); | |
| 2085 | return result; | |
| 2086 | } | |
| 2087 | ||
| 2078 | 2088 | pub fn unwrap(this: @This()) ?Index { |
| 2079 | 2089 | return switch (this) { |
| 2080 | 2090 | .none => null, |
src/Package/Fetch.zig+2-2| ... | ... | @@ -782,7 +782,7 @@ fn runResource( |
| 782 | 782 | f.package_root = try ls.pkg_root.join(arena, computed_package_hash.toSlice()); |
| 783 | 783 | renameTmpIntoCache(io, package_sub_path, f.package_root) catch |err| { |
| 784 | 784 | try eb.addRootErrorMessage(.{ .msg = try eb.printString( |
| 785 | "unable to rename temporary directory {f} into package cache directory {f}: {t}", | |
| 785 | "failed renaming temporary directory {f} into package cache directory {f}: {t}", | |
| 786 | 786 | .{ package_sub_path, f.package_root, err }, |
| 787 | 787 | ) }); |
| 788 | 788 | return error.FetchFailed; |
| ... | ... | @@ -802,7 +802,7 @@ fn runResource( |
| 802 | 802 | if (!package_sub_path.eql(tmp_directory_path)) { |
| 803 | 803 | tmp_directory_path.root_dir.handle.deleteDir(io, tmp_directory_path.sub_path) catch |err| switch (err) { |
| 804 | 804 | error.Canceled => |e| return e, |
| 805 | else => |e| log.warn("failed to delete temporary directory {f}: {t}", .{ tmp_directory_path, e }), | |
| 805 | else => |e| log.warn("failed deleting temporary directory {f}: {t}", .{ tmp_directory_path, e }), | |
| 806 | 806 | }; |
| 807 | 807 | } |
| 808 | 808 |
src/main.zig+17-15| ... | ... | @@ -4985,16 +4985,16 @@ fn cmdBuild( |
| 4985 | 4985 | configure_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path }; |
| 4986 | 4986 | |
| 4987 | 4987 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined }; |
| 4988 | const argv_index_zig_lib_dir = make_argv.items.len - 1; | |
| 4988 | const make_argv_index_zig_lib_dir = make_argv.items.len - 1; | |
| 4989 | 4989 | |
| 4990 | 4990 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--build-root", undefined }; |
| 4991 | 4991 | const make_argv_index_build_root = make_argv.items.len - 1; |
| 4992 | 4992 | |
| 4993 | 4993 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--local-cache", undefined }; |
| 4994 | const argv_index_cache_dir = make_argv.items.len - 1; | |
| 4994 | const make_argv_index_cache_dir = make_argv.items.len - 1; | |
| 4995 | 4995 | |
| 4996 | 4996 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--global-cache", undefined }; |
| 4997 | const argv_index_global_cache_dir = make_argv.items.len - 1; | |
| 4997 | const make_argv_index_global_cache_dir = make_argv.items.len - 1; | |
| 4998 | 4998 | |
| 4999 | 4999 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--configuration", undefined }; |
| 5000 | 5000 | const argv_index_configuration_file = make_argv.items.len - 1; |
| ... | ... | @@ -5285,10 +5285,20 @@ fn cmdBuild( |
| 5285 | 5285 | } }); |
| 5286 | 5286 | defer _ = make_runner_task.cancel(io) catch {}; |
| 5287 | 5287 | |
| 5288 | make_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path; | |
| 5288 | const pkg_root: Path = if (override_pkg_dir) |p| | |
| 5289 | .initCwd(p) | |
| 5290 | else if (system_pkg_dir_path) |p| | |
| 5291 | .initCwd(p) | |
| 5292 | else | |
| 5293 | .{ | |
| 5294 | .root_dir = build_root.directory, | |
| 5295 | .sub_path = "zig-pkg", | |
| 5296 | }; | |
| 5297 | ||
| 5298 | make_argv.items[make_argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path; | |
| 5289 | 5299 | make_argv.items[make_argv_index_build_root] = build_root.directory.path orelse cwd_path; |
| 5290 | make_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path; | |
| 5291 | make_argv.items[argv_index_cache_dir] = dirs.local_cache.path orelse cwd_path; | |
| 5300 | make_argv.items[make_argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path; | |
| 5301 | make_argv.items[make_argv_index_cache_dir] = dirs.local_cache.path orelse cwd_path; | |
| 5292 | 5302 | |
| 5293 | 5303 | configure_argv.items[conf_argv_index_build_root] = build_root.directory.path orelse cwd_path; |
| 5294 | 5304 | |
| ... | ... | @@ -5385,15 +5395,7 @@ fn cmdBuild( |
| 5385 | 5395 | .global_cache = dirs.global_cache, |
| 5386 | 5396 | .local_storage = &.{ |
| 5387 | 5397 | .cache_root = .{ .root_dir = dirs.local_cache, .sub_path = "" }, |
| 5388 | .pkg_root = if (override_pkg_dir) |p| | |
| 5389 | .initCwd(p) | |
| 5390 | else if (system_pkg_dir_path) |p| | |
| 5391 | .initCwd(p) | |
| 5392 | else | |
| 5393 | .{ | |
| 5394 | .root_dir = build_root.directory, | |
| 5395 | .sub_path = "zig-pkg", | |
| 5396 | }, | |
| 5398 | .pkg_root = pkg_root, | |
| 5397 | 5399 | }, |
| 5398 | 5400 | .recursive = true, |
| 5399 | 5401 | .debug_hash = false, |