diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-01-25 17:59:48 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-01-25 22:20:34 -0800 |
| commit | bea958df4d0c5fc38633f09b6490c16e24a03155 (patch) | |
| tree | 2820c9d4c87ff84baffa232d7a00a72949786f62 | |
| parent | ce58f68903f13a90f3bb2a566755e4c74b56ecdf (diff) | |
| download | zig-bea958df4d0c5fc38633f09b6490c16e24a03155.tar.gz zig-bea958df4d0c5fc38633f09b6490c16e24a03155.zip | |
Compilation: preserve "builtin" as the first dependency
Previously, sorting dependencies would reorder the builtin dependency
and cause `Package.Module.getBuiltinDependency` to stop working.
| -rw-r--r-- | src/Compilation.zig | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 2e1a5a6e4f..6dfd46796d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1143,12 +1143,14 @@ fn addModuleTableToCacheHash( try seen_table.put(gpa, main_mod, {}); const SortByName = struct { + has_builtin: bool, names: []const []const u8, - pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool { - const lhs_key = ctx.names[lhs_index]; - const rhs_key = ctx.names[rhs_index]; - return mem.lessThan(u8, lhs_key, rhs_key); + pub fn lessThan(ctx: @This(), lhs: usize, rhs: usize) bool { + return if (ctx.has_builtin and (lhs == 0 or rhs == 0)) + lhs < rhs + else + mem.lessThan(u8, ctx.names[lhs], ctx.names[rhs]); } }; @@ -1175,7 +1177,11 @@ fn addModuleTableToCacheHash( }, } - mod.deps.sortUnstable(SortByName{ .names = mod.deps.keys() }); + mod.deps.sortUnstable(SortByName{ + .has_builtin = mod.deps.count() >= 1 and + mod.deps.values()[0].isBuiltin(), + .names = mod.deps.keys(), + }); hash.addListOfBytes(mod.deps.keys()); |
