Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig build: add env_map entries to hash for Step.Run #20874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/std/Build/Step/Run.zig
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,35 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
var man = b.graph.cache.obtain();
defer man.deinit();

if (run.env_map) |env_map| {
const KV = struct { []const u8, []const u8 };
var kv_pairs = try std.ArrayList(KV).initCapacity(arena, env_map.count());
var iter = env_map.iterator();
while (iter.next()) |entry| {
kv_pairs.appendAssumeCapacity(.{ entry.key_ptr.*, entry.value_ptr.* });
}

std.mem.sortUnstable(KV, kv_pairs.items, {}, struct {
fn lessThan(_: void, kv1: KV, kv2: KV) bool {
const k1 = kv1[0];
const k2 = kv2[0];

if (k1.len != k2.len) return k1.len < k2.len;

for (k1, k2) |c1, c2| {
if (c1 == c2) continue;
return c1 < c2;
}
unreachable; // two keys cannot be equal
}
}.lessThan);

for (kv_pairs.items) |kv| {
man.hash.addBytes(kv[0]);
man.hash.addBytes(kv[1]);
}
}

for (run.argv.items) |arg| {
switch (arg) {
.bytes => |bytes| {
Expand Down
Loading