bazelbuild / bazelbuild/bazel

Packages are re-evaluated when `load`ed `.bzl` files are touched

Open
#27,177 0 comments 0 reactions 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

When a `load`ed `.bzl` file is touched (no contents change), then transitively all bzl files and the packages that load them, are re-evaluated. After the contents of the bzl are hashed, it should stop re-loading packages if hasn't changed.

### Which category does this issue belong to?

Performance

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Check out any rules repo, for example [rules_swift](https://github.com/bazelbuild/rules_swift). Add effectively empty `touch.bzl` at the root of the repo:
```
NOT_USED = {}
```

In one of the custom rules, `load` this file (e.g. in `swift/swift_library.bzl`):

```
load("//:touch.bzl", "NOT_USED")
```

Then perform analysis twice (to perform loading, then show no additional loading happens on the second build):

```
$ bazel build //examples/... --nobuild
INFO: Analyzed 94 targets (25 packages loaded, 1695 targets configured).
INFO: Found 94 targets...
INFO: Elapsed time: 0.221s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
$ bazel build //examples/... --nobuild
INFO: Analyzed 94 targets (0 packages loaded, 0 targets configured).
INFO: Found 94 targets...
INFO: Elapsed time: 0.119s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
```

Finally touch `touch.bzl` and perform analysis again, seeing that packages are re-evaluated:

```
$ touch touch.bzl
$ bazel build //examples/... --nobuild
INFO: Analyzed 94 targets (25 packages loaded, 1695 targets configured).
INFO: Found 94 targets...
INFO: Elapsed time: 0.223s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
```

### Which operating system are you running Bazel on?

macOS 15.7.1

### What is the output of `bazel info release`?

release 8.4.2

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

https://bazelbuild.slack.com/archives/CA31HN1T3/p1759783957774599. @fmeum asked me to file an issue.

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior with touch.bzl loaded from swift/swift_library.bzl in a rules_swift checkout, using the two bazel build commands before and after touching the file. Then trace Bazel's loading and package invalidation path. Done means touching an unchanged loaded .bzl does not re-evaluate dependent packages, while content changes still do.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.