Bazel: Avoiding eager fetches
Blog post from Aspect Build
Bazel is a build tool that manages dependencies and fetches them as needed, ensuring consistency across developers' environments by downloading only what is required for specific build targets. However, "eager fetches" can occur, where unnecessary dependencies are downloaded during the analysis phase, leading to delays, especially on the first build or when repositories get invalidated. Eager fetches are problematic when they include slow install steps, and Bazel's repository cache only helps for certain network fetches but not for computations needed to install dependencies. To address eager fetches, users can refactor the WORKSPACE file, vendor pre-computed results, or defer repository rule work to a later action in the build graph. For BUILD file eager fetches, it's crucial to design the file graph efficiently and minimize the size of external repositories. Reporting issues to maintainers and creating CI tests outside of Bazel can help prevent regressions, as eager fetches are often unnoticed until they cause significant build delays.