Skip to content

Commit 2eb1bf5

Browse files
philsccopybara-github
authored andcommitted
Update docs and tests to use the @platforms//:incompatible constraint
With e03cb63 bazel now distributes the 0.0.2 release of bazelbuild/platforms. This lets us use the `@platforms//:incompatible` constraint instead of setting up our own. This patch updates the docs and the relevant tests to use the commonly available constraint. Closes #12690. PiperOrigin-RevId: 347678913
1 parent 7428006 commit 2eb1bf5

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

site/docs/platforms.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,16 @@ FAILED: Build did NOT complete successfully
169169

170170
### More expressive constraints
171171

172-
For more flexibility in expressing constraints, create a user-defined
172+
For more flexibility in expressing constraints, use the
173+
`@platforms//:incompatible`
173174
[`constraint_value`](platform.html#constraint_value) that no platform
174-
satisfies. For example, Put the following somewhere in your project and change
175-
`//:not_compatible` in the subsequent examples to match your location.
175+
satisfies.
176176

177-
```python
178-
constraint_setting(name = "not_compatible_setting")
179-
180-
constraint_value(
181-
name = "not_compatible",
182-
constraint_setting = ":not_compatible_setting",
183-
)
184-
```
185-
186-
Use [`select()`](functions.html#select) in combination with `:not_compatible`
187-
to express more complicated restrictions. For example, use it to implement
188-
basic OR logic. The following marks a library compatible with macOS and Linux,
189-
but no other platforms. Note that an empty constraints list is equivalent to
190-
"compatible with everything".
177+
Use [`select()`](functions.html#select) in combination with
178+
`@platforms//:incompatible` to express more complicated restrictions. For
179+
example, use it to implement basic OR logic. The following marks a library
180+
compatible with macOS and Linux, but no other platforms. Note that an empty
181+
constraints list is equivalent to "compatible with everything".
191182

192183
```python
193184
cc_library(
@@ -196,18 +187,18 @@ cc_library(
196187
target_compatible_with = select({
197188
"@platforms//os:osx": [],
198189
"@platforms//os:linux": [],
199-
"//conditions:default": ["//:not_compatible"],
190+
"//conditions:default": ["@platforms//:incompatible"],
200191
],
201192
)
202193
```
203194

204195
The above can be interpreted as follows:
205196

206-
1. If we are targeting macOS, then this target has no constraints.
207-
2. If we are targeting Linux, then this target has no constraints.
208-
3. Otherwise the target has the `:not_compatible` constraint. Because
209-
`:not_compatible` is not part of any platforms, the target is deemed
210-
incompatible.
197+
1. When targeting macOS, the target has no constraints.
198+
2. When targeting Linux, the target has no constraints.
199+
3. Otherwise, the target has the `@platforms//:incompatible` constraint. Because
200+
`@platforms//:incompatible` is not part of any platform, the target is
201+
deemed incompatible.
211202

212203
To make your constraints more readable, use
213204
[skylib](https://github.com/bazelbuild/bazel-skylib)'s
@@ -221,7 +212,7 @@ cc_library(
221212
name = "non_arm_lib",
222213
srcs = "non_arm_lib.cc",
223214
target_compatible_with = select({
224-
"@platforms//cpu:arm": ["//:not_compatible"],
215+
"@platforms//cpu:arm": ["@platforms//:incompatible"],
225216
"//conditions:default": [],
226217
],
227218
)

src/test/shell/integration/target_compatible_with_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ EOF
8181
# We're not validating visibility here. Let everything access these targets.
8282
package(default_visibility = ["//visibility:public"])
8383
84+
# TODO(philsc): Get rid of this and use @platforms//:incompatible instead.
85+
# Right now it's problematic because Google CI doesn't support @platforms.
8486
constraint_setting(name = "not_compatible_setting")
8587
8688
constraint_value(

src/test/shell/integration/target_compatible_with_test_external_repo.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ EOF
8080
# We're not validating visibility here. Let everything access these targets.
8181
package(default_visibility = ["//visibility:public"])
8282
83-
constraint_setting(name = "not_compatible_setting")
84-
85-
constraint_value(
86-
name = "not_compatible",
87-
constraint_setting = ":not_compatible_setting",
88-
)
89-
9083
constraint_setting(name = "foo_version")
9184
9285
constraint_value(

0 commit comments

Comments
 (0)