Minor cleanup of bzl files (#2573)
diff --git a/crate_universe/extension.bzl b/crate_universe/extension.bzl
index a1c6a36..bbad6ab 100644
--- a/crate_universe/extension.bzl
+++ b/crate_universe/extension.bzl
@@ -24,7 +24,11 @@
}
def optional_bool(doc):
- return attr.string(doc = doc, values = _OPT_BOOL_VALUES.keys(), default = "auto")
+ return attr.string(
+ doc = doc,
+ values = _OPT_BOOL_VALUES.keys(),
+ default = "auto",
+ )
def _get_or_insert(d, key, value):
if key not in d:
@@ -342,7 +346,10 @@
_from_cargo = tag_class(
doc = "Generates a repo @crates from a Cargo.toml / Cargo.lock pair",
attrs = dict(
- name = attr.string(doc = "The name of the repo to generate", default = "crates"),
+ name = attr.string(
+ doc = "The name of the repo to generate",
+ default = "crates",
+ ),
cargo_lockfile = CRATES_VENDOR_ATTRS["cargo_lockfile"],
manifests = CRATES_VENDOR_ATTRS["manifests"],
cargo_config = CRATES_VENDOR_ATTRS["cargo_config"],
@@ -355,44 +362,113 @@
# This should be kept in sync with crate_universe/private/crate.bzl.
_annotation = tag_class(
attrs = dict(
- repositories = attr.string_list(doc = "A list of repository names specified from `crate.from_cargo(name=...)` that this annotation is applied to. Defaults to all repositories.", default = []),
- crate = attr.string(doc = "The name of the crate the annotation is applied to", mandatory = True),
- version = attr.string(doc = "The versions of the crate the annotation is applied to. Defaults to all versions.", default = "*"),
- additive_build_file_content = attr.string(doc = "Extra contents to write to the bottom of generated BUILD files."),
- additive_build_file = attr.label(doc = "A file containing extra contents to write to the bottom of generated BUILD files."),
- alias_rule = attr.string(doc = "Alias rule to use instead of `native.alias()`. Overrides [render_config](#render_config)'s 'default_alias_rule'."),
- build_script_data = _relative_label_list(doc = "A list of labels to add to a crate's `cargo_build_script::data` attribute."),
- build_script_tools = _relative_label_list(doc = "A list of labels to add to a crate's `cargo_build_script::tools` attribute."),
- build_script_data_glob = attr.string_list(doc = "A list of glob patterns to add to a crate's `cargo_build_script::data` attribute"),
- build_script_deps = _relative_label_list(doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute."),
- build_script_env = attr.string_dict(doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute."),
- build_script_proc_macro_deps = _relative_label_list(doc = "A list of labels to add to a crate's `cargo_build_script::proc_macro_deps` attribute."),
- build_script_rundir = attr.string(doc = "An override for the build script's rundir attribute."),
- build_script_rustc_env = attr.string_dict(doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute."),
- build_script_toolchains = attr.label_list(doc = "A list of labels to set on a crates's `cargo_build_script::toolchains` attribute."),
- compile_data = _relative_label_list(doc = "A list of labels to add to a crate's `rust_library::compile_data` attribute."),
- compile_data_glob = attr.string_list(doc = "A list of glob patterns to add to a crate's `rust_library::compile_data` attribute."),
- crate_features = attr.string_list(doc = "A list of strings to add to a crate's `rust_library::crate_features` attribute."),
- data = _relative_label_list(doc = "A list of labels to add to a crate's `rust_library::data` attribute."),
- data_glob = attr.string_list(doc = "A list of glob patterns to add to a crate's `rust_library::data` attribute."),
- deps = _relative_label_list(doc = "A list of labels to add to a crate's `rust_library::deps` attribute."),
- extra_aliased_targets = attr.string_dict(doc = "A list of targets to add to the generated aliases in the root crate_universe repository."),
- gen_binaries = attr.string_list(doc = "As a list, the subset of the crate's bins that should get `rust_binary` targets produced."),
- gen_all_binaries = attr.bool(doc = "If true, generates `rust_binary` targets for all of the crates bins"),
- disable_pipelining = attr.bool(doc = "If True, disables pipelining for library targets for this crate."),
+ repositories = attr.string_list(
+ doc = "A list of repository names specified from `crate.from_cargo(name=...)` that this annotation is applied to. Defaults to all repositories.",
+ default = [],
+ ),
+ crate = attr.string(
+ doc = "The name of the crate the annotation is applied to",
+ mandatory = True,
+ ),
+ version = attr.string(
+ doc = "The versions of the crate the annotation is applied to. Defaults to all versions.",
+ default = "*",
+ ),
+ additive_build_file_content = attr.string(
+ doc = "Extra contents to write to the bottom of generated BUILD files.",
+ ),
+ additive_build_file = attr.label(
+ doc = "A file containing extra contents to write to the bottom of generated BUILD files.",
+ ),
+ alias_rule = attr.string(
+ doc = "Alias rule to use instead of `native.alias()`. Overrides [render_config](#render_config)'s 'default_alias_rule'.",
+ ),
+ build_script_data = _relative_label_list(
+ doc = "A list of labels to add to a crate's `cargo_build_script::data` attribute.",
+ ),
+ build_script_tools = _relative_label_list(
+ doc = "A list of labels to add to a crate's `cargo_build_script::tools` attribute.",
+ ),
+ build_script_data_glob = attr.string_list(
+ doc = "A list of glob patterns to add to a crate's `cargo_build_script::data` attribute",
+ ),
+ build_script_deps = _relative_label_list(
+ doc = "A list of labels to add to a crate's `cargo_build_script::deps` attribute.",
+ ),
+ build_script_env = attr.string_dict(
+ doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute.",
+ ),
+ build_script_proc_macro_deps = _relative_label_list(
+ doc = "A list of labels to add to a crate's `cargo_build_script::proc_macro_deps` attribute.",
+ ),
+ build_script_rundir = attr.string(
+ doc = "An override for the build script's rundir attribute.",
+ ),
+ build_script_rustc_env = attr.string_dict(
+ doc = "Additional environment variables to set on a crate's `cargo_build_script::env` attribute.",
+ ),
+ build_script_toolchains = attr.label_list(
+ doc = "A list of labels to set on a crates's `cargo_build_script::toolchains` attribute.",
+ ),
+ compile_data = _relative_label_list(
+ doc = "A list of labels to add to a crate's `rust_library::compile_data` attribute.",
+ ),
+ compile_data_glob = attr.string_list(
+ doc = "A list of glob patterns to add to a crate's `rust_library::compile_data` attribute.",
+ ),
+ crate_features = attr.string_list(
+ doc = "A list of strings to add to a crate's `rust_library::crate_features` attribute.",
+ ),
+ data = _relative_label_list(
+ doc = "A list of labels to add to a crate's `rust_library::data` attribute.",
+ ),
+ data_glob = attr.string_list(
+ doc = "A list of glob patterns to add to a crate's `rust_library::data` attribute.",
+ ),
+ deps = _relative_label_list(
+ doc = "A list of labels to add to a crate's `rust_library::deps` attribute.",
+ ),
+ extra_aliased_targets = attr.string_dict(
+ doc = "A list of targets to add to the generated aliases in the root crate_universe repository.",
+ ),
+ gen_binaries = attr.string_list(
+ doc = "As a list, the subset of the crate's bins that should get `rust_binary` targets produced.",
+ ),
+ gen_all_binaries = attr.bool(
+ doc = "If true, generates `rust_binary` targets for all of the crates bins",
+ ),
+ disable_pipelining = attr.bool(
+ doc = "If True, disables pipelining for library targets for this crate.",
+ ),
gen_build_script = attr.string(
doc = "An authorative flag to determine whether or not to produce `cargo_build_script` targets for the current crate. Supported values are 'on', 'off', and 'auto'.",
values = _OPT_BOOL_VALUES.keys(),
default = "auto",
),
- patch_args = attr.string_list(doc = "The `patch_args` attribute of a Bazel repository rule. See [http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args)"),
- patch_tool = attr.string(doc = "The `patch_tool` attribute of a Bazel repository rule. See [http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool)"),
- patches = attr.label_list(doc = "The `patches` attribute of a Bazel repository rule. See [http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches)"),
- proc_macro_deps = _relative_label_list(doc = "A list of labels to add to a crate's `rust_library::proc_macro_deps` attribute."),
- rustc_env = attr.string_dict(doc = "Additional variables to set on a crate's `rust_library::rustc_env` attribute."),
- rustc_env_files = _relative_label_list(doc = "A list of labels to set on a crate's `rust_library::rustc_env_files` attribute."),
- rustc_flags = attr.string_list(doc = "A list of strings to set on a crate's `rust_library::rustc_flags` attribute."),
- shallow_since = attr.string(doc = "An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code."),
+ patch_args = attr.string_list(
+ doc = "The `patch_args` attribute of a Bazel repository rule. See [http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args)",
+ ),
+ patch_tool = attr.string(
+ doc = "The `patch_tool` attribute of a Bazel repository rule. See [http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool)",
+ ),
+ patches = attr.label_list(
+ doc = "The `patches` attribute of a Bazel repository rule. See [http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches)",
+ ),
+ proc_macro_deps = _relative_label_list(
+ doc = "A list of labels to add to a crate's `rust_library::proc_macro_deps` attribute.",
+ ),
+ rustc_env = attr.string_dict(
+ doc = "Additional variables to set on a crate's `rust_library::rustc_env` attribute.",
+ ),
+ rustc_env_files = _relative_label_list(
+ doc = "A list of labels to set on a crate's `rust_library::rustc_env_files` attribute.",
+ ),
+ rustc_flags = attr.string_list(
+ doc = "A list of strings to set on a crate's `rust_library::rustc_flags` attribute.",
+ ),
+ shallow_since = attr.string(
+ doc = "An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code.",
+ ),
),
)
diff --git a/rust/extensions.bzl b/rust/extensions.bzl
index 77b6920..f787dcb 100644
--- a/rust/extensions.bzl
+++ b/rust/extensions.bzl
@@ -117,25 +117,60 @@
)
_COMMON_TAG_KWARGS = dict(
- allocator_library = attr.string(default = "@rules_rust//ffi/cc/allocator_library"),
- dev_components = attr.bool(default = False),
- edition = attr.string(),
- rustfmt_version = attr.string(default = DEFAULT_NIGHTLY_VERSION),
- sha256s = attr.string_dict(),
- urls = attr.string_list(default = DEFAULT_STATIC_RUST_URL_TEMPLATES),
+ allocator_library = attr.string(
+ doc = "Target that provides allocator functions when rust_library targets are embedded in a cc_binary.",
+ default = "@rules_rust//ffi/cc/allocator_library",
+ ),
+ dev_components = attr.bool(
+ doc = "Whether to download the rustc-dev components (defaults to False). Requires version to be \"nightly\".",
+ default = False,
+ ),
+ edition = attr.string(
+ doc = (
+ "The rust edition to be used by default (2015, 2018, or 2021). " +
+ "If absent, every rule is required to specify its `edition` attribute."
+ ),
+ ),
+ rustfmt_version = attr.string(
+ doc = "The version of the tool among \"nightly\", \"beta\", or an exact version.",
+ default = DEFAULT_NIGHTLY_VERSION,
+ ),
+ sha256s = attr.string_dict(
+ doc = "A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details.",
+ ),
+ urls = attr.string_list(
+ doc = "A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).",
+ default = DEFAULT_STATIC_RUST_URL_TEMPLATES,
+ ),
)
-_RUST_TOOLCHAIN_TAG = tag_class(attrs = dict(
- extra_target_triples = attr.string_list(default = DEFAULT_EXTRA_TARGET_TRIPLES),
- rust_analyzer_version = attr.string(),
- versions = attr.string_list(default = []),
- **_COMMON_TAG_KWARGS
-))
+_RUST_TOOLCHAIN_TAG = tag_class(
+ attrs = dict(
+ extra_target_triples = attr.string_list(
+ default = DEFAULT_EXTRA_TARGET_TRIPLES,
+ ),
+ rust_analyzer_version = attr.string(
+ doc = "The version of Rustc to pair with rust-analyzer.",
+ ),
+ versions = attr.string_list(
+ doc = (
+ "A list of toolchain versions to download. This paramter only accepts one versions " +
+ "per channel. E.g. `[\"1.65.0\", \"nightly/2022-11-02\", \"beta/2020-12-30\"]`."
+ ),
+ default = [],
+ ),
+ **_COMMON_TAG_KWARGS
+ ),
+)
-_RUST_HOST_TOOLS_TAG = tag_class(attrs = dict(
- version = attr.string(),
- **_COMMON_TAG_KWARGS
-))
+_RUST_HOST_TOOLS_TAG = tag_class(
+ attrs = dict(
+ version = attr.string(
+ doc = "The version of Rust to use for tools executed on the Bazel host.",
+ ),
+ **_COMMON_TAG_KWARGS
+ ),
+)
rust = module_extension(
implementation = _rust_impl,