Bazel can write to the source folder!
Blog post from Aspect Build
Bazel, an open-source build tool developed by Google, is often misunderstood due to internal idioms that are inadvertently associated with it, leading to misconceptions such as the belief that Bazel cannot write to the source folder. While intermediate outputs in Bazel are typically used as inputs for other build targets and stored in the 'bazel-out' directory, there are scenarios where outputs need to be placed in the source folder, such as for editor plugins, test files, or documentation. Although standard commands like 'bazel build' and 'bazel test' cannot modify the source tree, 'bazel run' can, as it sets the environment variable BUILD_WORKSPACE_DIRECTORY, enabling source updates. This leads to the "Write to Sources" pattern, where 'bazel run' updates files and 'bazel test' ensures they don't drift from Bazel-generated outputs, although it may cause issues if the source files are outdated before tests are run. Existing rules like Aspect's 'write_source_files' or Chuck Grindel's 'updatesrc' can facilitate this process, while custom solutions can be implemented in a BUILD.bazel file to maintain synchrony between generated and source files, with many core Bazel rulesets adopting this approach to manage API markdown files.
No tracked trend matches for this post yet.
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.