std.Build.Step.Run: avoid file system watches when already tracked by step dependency edges #20631
Labels
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
optimization
zig build system
std.Build, the build runner, `zig build` subcommand, package management
Milestone
Extracted from #20580.
The
make
function ofstd.Build.Step.Run
:zig/lib/std/Build/Step/Run.zig
Line 598 in 464537d
Uses the cache system (
std.Build.Cache
) to track file system inputs, and then reports those to the build runner viacacheHitAndWatch
andwriteManifestAndWatch
.This has a couple of shortcomings.
Firstly, a failed run step fails to report its file system inputs, meaning that those files will not be watched. Instead, even a failed run step needs to register its file inputs to the cache system so that they can be tracked.
Secondly, it is common for Run steps to be given build system outputs as inputs. For example,
In this case, there is already a dependency edge between the
config_asm
Step and thenasm_run
Step, making the file system watch placed on the output ofconfig_asm
a waste of resources.As part of this issue, I suggest to take note of all file system watch directories, and eliminate cases where
zig-cache/o/
directories are watched, because those will always be handled instead by Step dependency edges.This is even true for incremental cache mode which will result in mutations to those files within the
o
directory. As a follow-up issue to this one, incremental cache mode should use a different subdirectory thano
so thato
can be used exclusively for artifacts that are never mutated.As part of implementing this issue, I suggest to revisit the
std.Build.Cache
implementation, particularly with an eye for using thestd.Build.Cache.Path
abstraction in order to fully eliminate absolute paths from manifest files. In particular I noticed files relative to thep/
directory inside the global zig cache were being stored in absolute path form.The text was updated successfully, but these errors were encountered: