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

Don't register rust_host_tools twice #3188

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions rust/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,6 @@ def _rust_host_tools_impl(module_ctx):
**attrs
)

# If no tags were specified, create a default repository.
if not mod.tags.host_tools:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be called if no module defines host_tools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rules_rust's MODULE.bazel defines host tools already, so it will be always defined. Or I am missing something and it may not be defined in some other way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just seems brittle to me for folks to be depending on the name of a particular dependency in rules_rust's MODULE.bazel file. That's why I tried to have the module extension itself always provide the repository and encode the consistent name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reference, without this change currently one gets following error if one does not specify host_tools tag:

ERROR: (...)/external/rules_rust+/rust/extensions.bzl:262:44: Traceback (most recent call last):
        File "(...)/external/rules_rust+/rust/extensions.bzl", line 262, column 44, in _rust_host_tools_impl
                rust_toolchain_tools_repository(
Error in repository_rule: A repo named rust_host_tools is already generated by this module extension at (...)/external/rules_rust+/rust/extensions.bzl:274:44
ERROR: Analysis of target '//:generate_rustc_env_file' failed; build aborted: error evaluating module extension @@rules_rust+//rust:extensions.bzl%rust_host_tools

I guess for bazel-lsp workaround would be simply to specify some host_tool with unique name (like bazel_lsp_rust_host_tools). Other solution would be in rules_rust's MODULE to change name to smthg like rules_rust_internal_host_tools, which will require users to use some name, or roll back this change, but move this condition outside of loop as you mentioned.

Wonder whether the best solution could be to expose those toolchain files directly in @rules_rust, like @rules_rust//bin:cargo, something similar as you can do with go by running bazel run @io_bazel_rules_go//go. This way it would use binaries for configured toolchain.

attrs = {
"name": "rust_host_tools",
"version": rust_common.default_version,
}
rust_toolchain_tools_repository(
exec_triple = host_triple.str,
target_triple = host_triple.str,
**attrs
)

metadata_kwargs = {}
if bazel_features.external_deps.extension_metadata_has_reproducible:
metadata_kwargs["reproducible"] = True
Expand Down
Loading