-
Notifications
You must be signed in to change notification settings - Fork 406
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
Add constraint values for the Rust release channel. #510
Conversation
This could use an example. Is CI setup to run 4.0 yet? |
# channels, for example when depending on features only available in Nightly. | ||
# | ||
# https://doc.rust-lang.org/book/appendix-07-nightly-rust.html | ||
constraint_setting(name = "channel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is not a global name, right? I am not familiar w/ defining constraints.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a target name, it's referenced as @io_bazel_rules_rust//rust/platform/channel
and the constraint values are referenced like @io_bazel_rules_rust//rust/platform/channel:nightly
.
For an example it might be better to use toolchains, since those are better known and have been around for a while. Given the following BUILD targets: platform(
name = "linux-armv7-stable",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
"@io_bazel_rules_rust//rust/platform/channel:stable",
],
)
platform(
name = "linux-armv7-nightly",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
"@io_bazel_rules_rust//rust/platform/channel:nightly",
],
)
toolchain(
name = "rust_darwin-to-linux-armv7-stable",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
target_compatible_with = [
"@platforms//cpu:arm",
"@platforms//os:linux",
"@io_bazel_rules_rust//rust/platform/channel:stable",
],
toolchain = "@rust_darwin-to-linux-armv7-stable//:toolchain_for_arm-unknown-linux-musleabihf_impl",
toolchain_type = "@io_bazel_rules_rust//rust:toolchain",
)
toolchain(
name = "rust_darwin-to-linux-armv7-nightly",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
target_compatible_with = [
"@platforms//cpu:arm",
"@platforms//os:linux",
"@io_bazel_rules_rust//rust/platform/channel:nightly",
],
toolchain = "@rust_darwin-to-linux-armv7-nightly//:toolchain_for_arm-unknown-linux-musleabihf_impl",
toolchain_type = "@io_bazel_rules_rust//rust:toolchain",
) I can use now select whether I want to build with the stable or nightly toolchain using |
I'll go ahead and merge this PR, IMHO it's useful and uncontroversial. Thank you @jmillikin! |
This allows users to define separate toolchains and platforms for stable/beta/nightly, and to
select()
based on which channel is being used in a build.In the upcoming Bazel v4.0, the
target_compatible_with
target attr will allow targets to be skipped based on channel compatibility.