xref: /aosp_15_r20/external/bazelbuild-rules_rust/rust/toolchain/channel/channel.bzl (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1"""Rules for representing Rust toolchain channels"""
2
3_CHANNELS = [
4    "beta",
5    "nightly",
6    "stable",
7]
8
9RustToolchainChannelInfo = provider(
10    doc = "A provider describing the Rust toolchain channel.",
11    fields = {
12        "value": "string: Can be {}".format(_CHANNELS),
13    },
14)
15
16def _rust_toolchain_channel_flag_impl(ctx):
17    value = ctx.build_setting_value
18    if value not in _CHANNELS:
19        fail(str(ctx.label) + " build setting allowed to take values {" +
20             ", ".join(_CHANNELS) + "} but was set to unallowed value " +
21             value)
22    return RustToolchainChannelInfo(value = value)
23
24rust_toolchain_channel_flag = rule(
25    doc = "A build setting which represents the Rust toolchain channel. The allowed values are {}".format(_CHANNELS),
26    implementation = _rust_toolchain_channel_flag_impl,
27    build_setting = config.string(
28        flag = True,
29    ),
30)
31