Skip to content

Commit

Permalink
Minor cleanup of bzl files
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Mar 27, 2024
1 parent fc601ba commit 8f6e8d9
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 50 deletions.
146 changes: 111 additions & 35 deletions crate_universe/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ _OPT_BOOL_VALUES = {
}

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:
Expand Down Expand Up @@ -342,7 +346,10 @@ def _crate_impl(module_ctx):
_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"],
Expand All @@ -355,44 +362,113 @@ _from_cargo = tag_class(
# 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.",
),
),
)

Expand Down
46 changes: 31 additions & 15 deletions rust/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,41 @@ def _rust_impl(module_ctx):
)

_COMMON_TAG_KWARGS = dict(
allocator_library = attr.string(default = "@rules_rust//ffi/cc/allocator_library"),
dev_components = attr.bool(default = False),
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),
rustfmt_version = attr.string(
default = DEFAULT_NIGHTLY_VERSION,
),
sha256s = attr.string_dict(),
urls = attr.string_list(default = DEFAULT_STATIC_RUST_URL_TEMPLATES),
urls = attr.string_list(
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_HOST_TOOLS_TAG = tag_class(attrs = dict(
version = attr.string(),
**_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(),
versions = attr.string_list(
default = [],
),
**_COMMON_TAG_KWARGS
),
)

_RUST_HOST_TOOLS_TAG = tag_class(
attrs = dict(
version = attr.string(),
**_COMMON_TAG_KWARGS
),
)

rust = module_extension(
implementation = _rust_impl,
Expand Down

0 comments on commit 8f6e8d9

Please sign in to comment.