https://github.com/helly25/bzl
Collection of Bazel support functionality.
https://github.com/helly25/bzl
Last synced: about 1 month ago
JSON representation
Collection of Bazel support functionality.
- Host: GitHub
- URL: https://github.com/helly25/bzl
- Owner: helly25
- License: apache-2.0
- Created: 2025-03-14T20:03:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-15T09:49:59.000Z (over 1 year ago)
- Last Synced: 2025-03-15T10:18:47.441Z (over 1 year ago)
- Language: Starlark
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Helly25 bzl, a Bazel support library
This library provides [Bazel](http://bazel.build) [Starlark](https://bazel.build/rules/language) functionality meant to help in maintaining other libraries.
[](https://github.com/helly25/bzl/actions/workflows/main.yml)
## Versions
Implements versioning functions that mostly follow [Semver](https://semver.org/).
Comparators correctly respect major, minor and patch components, as well as
Semver compliant 'pre-release' and 'build' components. The pre-release and build
components are split at ".". Comparing pre-release parts works for alphabetical
prefixes and numeric suffixes, so 'alpha', 'beta' and 'rc' as well as numbered
version of those (e.g. 'alpha1' or rc-1') are supported. For pre-releases and
build pieces a single '-' in front of the numeric parts is dropped (e.g. 'rc-1'
becomes 'rc' + '1' while 'alpha--2' becomes 'alpha-' + '2').
The full functionality is exposed as a singele struct containing all functions.
The version parameters support:
- a string that can be parsed according to:
`major`['.' `minor` [ '.' `patch` [ '.' `digits`]\*]] ['-' [^+]+] ['+' .\*]
- a `list` or `tuple` where each component is a version part. If present, then:
- a pre-release component must be separated by a single "-" and split by ".".
- a build component must be separated by a single "+" and split by "."
- a single `int` which will be the major version.
- anything else is an error and the functions will `fail`.
- unlike Semver, the function allows any number of numeric version components.
Note: Most functions support a `skip_build` parameter. If `True`, then any
present build component will be dropped. Conclusively the parameter is `True`
by default for parsing and `False` for comparisons since Semver dictates that
that the build component must be ignored for precedence (see
[Semver-10](https://semver.org/#spec-item-10)).
The functionality has exhaustive tests. If something still works wrong please,
file a bug report or propose a fix.
Example:
```bazel
my_version = "25.33.42"
min_version = (10, 11, 12)
if _versions.lt(my_version, min_version):
fail("My version {my_version} is earlier than {min_version}.".format(
my_version = my_version,
min_version = min_version,
))
```
Provides:
* `load("@helly25_bzl//bzl/versions:versions_bzl", _versions = "versions")`
* `versions` is a single import structure:
* `parse`: Parses a version.
* `ge`: Implements `L >= R`.
* `gt`: Implements `L > R`.
* `le`: Implements `L <= R`.
* `lt`: Implements `L < R`.
* `eq`: Implements `L == R`.
* `ne`: Implements `L != R`.
* `cmp`: Implements `L <=> R` aka `(L < R) - (L > R)`.
* `compare`: Implements `L OP R`.
* `check_one_requirement`: Checks a version adheres to a single requirement.
* `check_all_requirements`: Checks a version adheres to a requirements list.
* `parse_requirements`: Parses a requirements specification.
## Installation
The library is available for both Bazelmod and Workspace installations and works
on MacOS, Ubuntu and Windows with Bazel version 7.x and 8.x (Other systems are
simply not tested). However future version may drop Windows support.
### For MODULES.bazel
See https://github.com/helly25/bzl/releases to replace the version number.
```
bazel_dep(name = "helly25_bzl", version = "0.0.0")
```
### For WORKSPACE
```bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "helly25_bzl",
url = "https://github.com/helly25/bzl/releases/download/0.0.0/bzl-0.0.0.tar.gz",
sha256 = "...." # see https://github.com/helly25/bzl/releases for version numbers SHA256 codes.
)
```
### Dependencies
* `bazel_skylib`.