Remove incomplete static environment checking
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
The static environment checking is supposed to enforce that dependencies are compatible with all of the target's compatible environments. However, it doesn't hold its promise and should therefore be removed. To get correct environment checking, users need to settle on one specific environment (per group) and specify it through `--target_environment`.
```
environment(name = "env")
environment(name = "default")
environment_group(
name = "group",
defaults = [":default"],
environments = [":default", ":env"],
)
config_setting(
name = "setting",
define_values = {"key": "value"},
)
cc_library(
name = "foo",
compatible_with = [":env"],
deps = select({
":setting": [":bar"],
"//conditions:default": [":bar"],
}),
)
cc_library(name = "bar")
```
`bazel build :foo` succeeds but should fail.
With any of the following changes, it fails as expected:
- Build with `--target_environment=:env`
- Remove `":setting": [":bar"],` in `select`.
- Remove `default` environment.
Background: TensorFlow uses compatible_with for GCE builds from google3. Marking just the actual dependencies compatible with GCE is an unrealistic amount of work for the ever changing build graph. Instead, entire packages have been marked compatible with GCE to the point where pretty much every TensorFlow target is compatible with GCE. This is causing issues for external dependencies that cannot (e.g. CUDA) or do not want to (e.g. TFRT) be marked compatible with GCE. Without static environment checking, TensorFlow targets marked compatible with GCE but not actually part of the `--target_environment=gce` build could use dependencies that are not marked compatible with GCE.
I'm using bazel 5.0.0 on Linux.
Contributor guide
Research direction
Reproduce the example with `bazel build :foo`, then locate the static environment-checking implementation and tests covering `compatible_with`, `environment_group`, and `select`; the issue names no files. Compare behavior with and without `--target_environment=:env`, and consider the work done when incomplete static checking is removed while explicit target-environment checking remains correct.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100