bazel__book/notes.md

52 lines
2 KiB
Markdown

# Misc notes
## Extensions
- `WORKSPACE`, and `BUILD` were originally without an extension,
but since v0.25, they support `.bazel`, but not `.bzl`.
`MODULE` requires a `.bazel` extension to be recognized by Bzlmod.
- These are meant to be declarative files, although legacy `WORKSPACE` could also contain code.
- They cannot contain Starlark `def` or the `load` instruction
- macros and rules contain the Starlark logic, normally with `.bzl` extension.
For legacy compatibility, they can also use `.sky` extension from when Starlark was called Skylark.
The `.gn` extension, as in `BUILD.gn` is used by the Generate Ninja tool,
which is similar to Bazel, but not compatible with it.
## References
Within a script, a reference like `:foo` refers to the target named `foo` in the current package.
## Upgrading
Bazel uses MVS for version selection, just like Go modules.
## Placeholders
Bazel defines 3 placeholders usable in some files:
| Placeholder | Resolution | Use cases |
|---------------|-------------------------------|-----------------------------------------------------------------|
| `%workspace%` | Root of the current workspace | local disk cache, log redirects, project-specific tools |
| `%user_home%` | $HOME / %USERPROFILE% | User-specific caches or shared credential files |
| `%usedid%` | Username of the current user | Creating unique subdirs in shared folders e.g., `/tmp/%userid%` |
It is a bad idea to reference :
- `/tmp`: won't work on Windows
- `$HOME`, even as `${HOME}` : may not be replaced if not run from the CLI by a full shell.
- `~` : not recognized outside RC files; even there, only works as first character.
Contrary to some Gemini/Claude assertions,
these placeholders are not supported in the RC files, though.
## Build cache
Bazel does NOT limit the size of the build cache, or expire items in it.
When deploying a local cache, add a cron task to clean it up, like
```
find <pathtocache> -type f -atime +30 -delete
```