Practical Bazel: local_archive() Workspace Rule
In general, one should never check in binary artifacts into Git; it is better
to retrieve them from an artifact repository or a website using http_archive()
.
However, sometimes convenience is more important than ideological purity.
To handle these cases, I wrote a simple workspace rule named local_archive()
.
http_archive()
is one of the most commonly used workspace rules. Besides
downloading archives from HTTP, it also supports a number of other useful
features such:
- SHA256 validation of the downloaded file to prevent injection attacks
- Automatic extraction of the contents of the archive
- A
build_file
attribute which can be used to provide post-download Bazel build instructions - A
strip_prefix
attribute, to remove a common prefix from downloaded archives post-extraction
There is no equivalent to http_archive()
for locally-stored archives, so
I wrote a simple one. It is included below:
|
|
Use it as follows:
|
|