Skip to content
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

Merged
merged 2 commits into from
Feb 24, 2021

Conversation

jmillikin
Copy link
Contributor

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.

@google-cla google-cla bot added the cla: yes label Nov 29, 2020
@mfarrugi
Copy link
Collaborator

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")
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@jmillikin
Copy link
Contributor Author

jmillikin commented Nov 30, 2020

This could use an example. Is CI setup to run 4.0 yet?

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 --platforms=@my_repo//:linux-armv7-stable or @my_repo//:linux-armv7-nightly flags, similar to a combination of Cargo's options +stable / +nightly and --target.

Base automatically changed from master to main January 28, 2021 20:47
@hlopko
Copy link
Member

hlopko commented Feb 24, 2021

I'll go ahead and merge this PR, IMHO it's useful and uncontroversial. Thank you @jmillikin!

@hlopko hlopko merged commit bbbfcdd into bazelbuild:main Feb 24, 2021
@jmillikin jmillikin deleted the channel-constraints branch October 21, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants