authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-29 18:18:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
logfa235757671490746d31a61a9b836ddc6320d3dc
tree1452b78ee0e2dbbfc2e06b003e71cee722071a8f
parent5f626d28c14bfded775ae779dcde5b2435d4ac13

maker: fix the has side effects logic in run step


2 files changed, 17 insertions(+), 6 deletions(-)

lib/compiler/Maker.zig+3-1
...@@ -1669,8 +1669,10 @@ fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {...@@ -1669,8 +1669,10 @@ fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn {
1669}1669}
16701670
1671fn cleanTmpFiles(io: Io, steps: []const Configuration.Step.Index) void {1671fn cleanTmpFiles(io: Io, steps: []const Configuration.Step.Index) void {
1672 std.log.err("TODO implement cleanTmpFiles", .{});
1673 if (true) return;
1674
1672 for (steps) |step_index| {1675 for (steps) |step_index| {
1673 if (true) @panic("TODO");
1674 const wf = step_index.cast(std.Build.Step.WriteFile) orelse continue;1676 const wf = step_index.cast(std.Build.Step.WriteFile) orelse continue;
1675 if (wf.mode != .tmp) continue;1677 if (wf.mode != .tmp) continue;
1676 const path = wf.generated_directory.path orelse continue;1678 const path = wf.generated_directory.path orelse continue;
lib/compiler/Maker/Step/Run.zig+14-5
...@@ -70,7 +70,8 @@ pub fn make(...@@ -70,7 +70,8 @@ pub fn make(
70 man.hash.add(conf_run.flags.color);70 man.hash.add(conf_run.flags.color);
71 man.hash.add(conf_run.flags.disable_zig_progress);71 man.hash.add(conf_run.flags.disable_zig_progress);
7272
73 var dep_file_count: usize = 0;73 var any_dep_files = false;
74 var any_output_args = false;
7475
75 for (conf_run.args.slice) |arg_index| {76 for (conf_run.args.slice) |arg_index| {
76 const arg = arg_index.get(conf);77 const arg = arg_index.get(conf);
...@@ -161,9 +162,10 @@ pub fn make(...@@ -161,9 +162,10 @@ pub fn make(
161 man.hash.addBytesZ(prefix);162 man.hash.addBytesZ(prefix);
162 man.hash.addBytesZ(basename);163 man.hash.addBytesZ(basename);
163 man.hash.addBytesZ(suffix);164 man.hash.addBytesZ(suffix);
164
165 man.hash.add(arg.flags.dep_file);165 man.hash.add(arg.flags.dep_file);
166 dep_file_count += @intFromBool(arg.flags.dep_file);166
167 any_dep_files = any_dep_files or arg.flags.dep_file;
168 any_output_args = true;
167169
168 // Add a placeholder into the argument list because we need the170 // Add a placeholder into the argument list because we need the
169 // manifest hash to be updated with all arguments before the171 // manifest hash to be updated with all arguments before the
...@@ -233,7 +235,14 @@ pub fn make(...@@ -233,7 +235,14 @@ pub fn make(
233 _ = man.hash.addBytes(try cwd_path.toString(arena));235 _ = man.hash.addBytes(try cwd_path.toString(arena));
234 }236 }
235237
236 const has_side_effects = conf_run.flags.has_side_effects;238 // Whether the Run step has side effects *other than* updating the output arguments.
239 const has_side_effects = conf_run.flags.has_side_effects or switch (conf_run.flags.stdio) {
240 .infer_from_args => !any_output_args and
241 conf_run.captured_stdout.value == null and
242 conf_run.captured_stderr.value == null,
243 .inherit => true,
244 .check, .zig_test => false,
245 };
237246
238 if (!has_side_effects and try step.cacheHitAndWatch(maker, &man)) {247 if (!has_side_effects and try step.cacheHitAndWatch(maker, &man)) {
239 // Cache hit; skip running command.248 // Cache hit; skip running command.
...@@ -244,7 +253,7 @@ pub fn make(...@@ -244,7 +253,7 @@ pub fn make(
244 return;253 return;
245 }254 }
246255
247 if (dep_file_count == 0) {256 if (!any_dep_files) {
248 // We already know the final output paths; use them directly.257 // We already know the final output paths; use them directly.
249 const digest = if (has_side_effects) man.hash.final() else man.final();258 const digest = if (has_side_effects) man.hash.final() else man.final();
250 const output_dir_path = "o" ++ Dir.path.sep_str ++ &digest;259 const output_dir_path = "o" ++ Dir.path.sep_str ++ &digest;