Skip to content

std.Build.Step.Run: avoid file system watches when already tracked by step dependency edges #20631

@andrewrk

Description

@andrewrk

Extracted from #20580.

The make function of std.Build.Step.Run:

fn make(step: *Step, prog_node: std.Progress.Node) !void {

Uses the cache system (std.Build.Cache) to track file system inputs, and then reports those to the build runner via cacheHitAndWatch and writeManifestAndWatch.

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,

                nasm_run.addFileArg(config_asm.getOutput());

In this case, there is already a dependency edge between the config_asm Step and the nasm_run Step, making the file system watch placed on the output of config_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 than o so that o 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 the std.Build.Cache.Path abstraction in order to fully eliminate absolute paths from manifest files. In particular I noticed files relative to the p/ directory inside the global zig cache were being stored in absolute path form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.optimizationzig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions