-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starlark: provide a way to probe builtins availability #12735
Comments
Maybe it's a candidate for skylib:
That'd work for old versions, but for newer additions would be nice to have a native way to do that as well |
We've talked about this a lot. It almost seems useful, but you soon want to do something different enough so that you hit the wall you hinted at about conditional load. One of the things we are thinking of is that rule sets versions should be explicitly tied to bazel versions. Depending on bazel version we swap the entire WORKSPACE to get a compatible suite. Of course, home grown rules would also have to be versioned, which could be a burden for monorepos. |
This means that `rules_jvm_external` is only compatible with Bazel 4 and later. That shipped on 2021-01-21, and so should be widely adopted already. Older versions of this ruleset will continue to work for repos using older versions of Bazel so it's not removing any existing functionality, and the new Bazel 5 release should have already shipped. The main reason for doing this is that the native json decoding is significantly faster than the starlark-based one. The following options were explored as alternatives: 1. Making the `json_parse` method check the bazel version and optionally use the `json` module if it was present. This doesn't work because of #12735 2. Create a `json` repository rule that creates a repo that exposes a `json.bzl` file that delegates to the native `json` module if present, or the starlark one if not (as determined by looking at the major version number of bazel). This doesn't work because `maven_install` is used by RJE's own `repositories.bzl` file, so there's no chance to load the repository rule before it's needed. Links: 12735: bazelbuild/bazel#12735
This means that `rules_jvm_external` is only compatible with Bazel 4 and later. That shipped on 2021-01-21, and so should be widely adopted already. Older versions of this ruleset will continue to work for repos using older versions of Bazel so it's not removing any existing functionality, and the new Bazel 5 release should have already shipped. The main reason for doing this is that the native json decoding is significantly faster than the starlark-based one. The following options were explored as alternatives: 1. Making the `json_parse` method check the bazel version and optionally use the `json` module if it was present. This doesn't work because of #12735 2. Create a `json` repository rule that creates a repo that exposes a `json.bzl` file that delegates to the native `json` module if present, or the starlark one if not (as determined by looking at the major version number of bazel). This doesn't work because `maven_install` is used by RJE's own `repositories.bzl` file, so there's no chance to load the repository rule before it's needed. Links: 12735: bazelbuild/bazel#12735
This means that `rules_jvm_external` is only compatible with Bazel 4 and later. That shipped on 2021-01-21, and so should be widely adopted already. Older versions of this ruleset will continue to work for repos using older versions of Bazel so it's not removing any existing functionality, and the new Bazel 5 release should have already shipped. The main reason for doing this is that the native json decoding is significantly faster than the starlark-based one. The following options were explored as alternatives: 1. Making the `json_parse` method check the bazel version and optionally use the `json` module if it was present. This doesn't work because of #12735 2. Create a `json` repository rule that creates a repo that exposes a `json.bzl` file that delegates to the native `json` module if present, or the starlark one if not (as determined by looking at the major version number of bazel). This doesn't work because `maven_install` is used by RJE's own `repositories.bzl` file, so there's no chance to load the repository rule before it's needed. Links: 12735: bazelbuild/bazel#12735
This means that `rules_jvm_external` is only compatible with Bazel 4 and later. That shipped on 2021-01-21, and so should be widely adopted already. Older versions of this ruleset will continue to work for repos using older versions of Bazel so it's not removing any existing functionality, and the new Bazel 5 release should have already shipped. The main reason for doing this is that the native json decoding is significantly faster than the starlark-based one. The following options were explored as alternatives: 1. Making the `json_parse` method check the bazel version and optionally use the `json` module if it was present. This doesn't work because of #12735 2. Create a `json` repository rule that creates a repo that exposes a `json.bzl` file that delegates to the native `json` module if present, or the starlark one if not (as determined by looking at the major version number of bazel). This doesn't work because `maven_install` is used by RJE's own `repositories.bzl` file, so there's no chance to load the repository rule before it's needed. Links: 12735: bazelbuild/bazel#12735
This means that `rules_jvm_external` is only compatible with Bazel 4 and later. That shipped on 2021-01-21, and so should be widely adopted already. Older versions of this ruleset will continue to work for repos using older versions of Bazel so it's not removing any existing functionality, and the new Bazel 5 release should have already shipped. The main reason for doing this is that the native json decoding is significantly faster than the starlark-based one. The following options were explored as alternatives: 1. Making the `json_parse` method check the bazel version and optionally use the `json` module if it was present. This doesn't work because of #12735 2. Create a `json` repository rule that creates a repo that exposes a `json.bzl` file that delegates to the native `json` module if present, or the starlark one if not (as determined by looking at the major version number of bazel). This doesn't work because `maven_install` is used by RJE's own `repositories.bzl` file, so there's no chance to load the repository rule before it's needed. Links: 12735: bazelbuild/bazel#12735
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
#12735 (comment) now has an official implementation at https://github.com/bazel-contrib/bazel_features. |
Description of the problem / feature request:
It seems that it's not possible to test whether some builtin is available or not from within Starlark
Feature requests: what underlying problem are you trying to solve with this feature?
It is nice to have new built-in modules, like json (#3732), but it's hard to use them in Starlark libraries and/or repo rules in a way compatible with older bazel versions.
Example
some.bzl
That would almost work if there was a way to not fail if "json" isn't a global name. Ideally though 2nd load() should also be conditional (maybe on workspace level somehow?).
The text was updated successfully, but these errors were encountered: