Skip to content

--watch does not pick up sub-Compilation file system inputs such as compiler_rt, glibc, or musl source files #20601

@andrewrk

Description

@andrewrk

Extracted from #20580.

Zig version: 0.14.0-dev.283+1d20ff11d

Steps to reproduce:

In an empty directory:

$ zig init
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
$ zig build --watch
andy@bark ~/t/abc> zig build --watch
Build Summary: 5/5 steps succeeded
install success
├─ install abc success
│  └─ zig build-lib abc Debug native success 702ms MaxRSS:195M
└─ install abc success
   └─ zig build-exe abc Debug native success 759ms MaxRSS:198M
Watching 21 Directories

Then go make a change to lib/zig/compiler_rt.zig in the lib directory corresponding to the zig compiler you are using.

The file is not being watched; no changes are picked up. Instead, changes to compiler_rt and other sub-compilations should be noticed and trigger a recompilation.

The mechanism behind this is in Compilation.update:

pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {

In this function:

  • Pay attention to how comp.file_system_inputs is modified
  • Note this comment:

    zig/src/Compilation.zig

    Lines 2116 to 2121 in 1d20ff1

    // From this point we add a preliminary set of file system inputs that
    // affects both incremental and whole cache mode. For incremental cache
    // mode, the long-lived compiler state will track additional file system
    // inputs discovered after this point. For whole cache mode, we rely on
    // these inputs to make it past AstGen, and once there, we can rely on
    // learning file system inputs from the Cache object.
  • Notice how the Cache Manifest object is the authority on file inputs, but only when using whole cache mode, and it is either a hit, or a successful compilation.

In a future enhancement, the build runner should pass in the set of modified file system inputs to the update() function directly, so that the fstat calls are avoided. That should be a follow-up issue when closing this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions