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

Use canonical repo name for aspects #2450

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

cameron-martin
Copy link
Contributor

Currently when running gen_rust_project, the aspect given to bazel has the canonical repo name but only a single @. This does not work with bzlmod, since it tries to resolve this using the repository mappings, and complains that the repository does not exist:

ERROR: Unable to find package for @@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust~0.38.0' requested from @@]' could not be resolved: No repository visible as '@rules_rust~0.38.0' from main repository.
ERROR: Analysis of aspects '[@@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl%rust_analyzer_aspect] with parameters {} on //prost:prost_toolchain_impl' failed; build aborted: Unable to find package for @@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust~0.38.0' requested from @@]' could not be resolved: No repository visible as '@rules_rust~0.38.0' from main repository.

This adds an extra @, so that the repository in the label is of canonical form.

Fixes #2449

Currently when running `gen_rust_project`, the aspect given to bazel has the canonical repo name but only a single `@`. This does not work with bzlmod, since it tries to resolve this using the repository mappings, and complains that the repository does not exist:

```
ERROR: Unable to find package for @@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust~0.38.0' requested from @@]' could not be resolved: No repository visible as '@rules_rust~0.38.0' from main repository.
ERROR: Analysis of aspects '[@@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl%rust_analyzer_aspect] with parameters {} on //prost:prost_toolchain_impl' failed; build aborted: Unable to find package for @@[unknown repo 'rules_rust~0.38.0' requested from @@]//rust:defs.bzl: The repository '@@[unknown repo 'rules_rust~0.38.0' requested from @@]' could not be resolved: No repository visible as '@rules_rust~0.38.0' from main repository.
```

This adds an extra `@`, so that the repository in the label is of canonical form.
cameron-martin added a commit to cameron-martin/bazel-lsp that referenced this pull request Jan 31, 2024
@illicitonion
Copy link
Collaborator

Thanks! Could you add a test which fails before and passes after this change? We have some tests in https://github.com/bazelbuild/rules_rust/blob/main/examples/bzlmod/hello_world/BUILD.bazel for testing similar things, or can add extra run_targets to

ubuntu2004_bzlmod_bcr:
name: bzlmod BCR presubmit
platform: ubuntu2004
working_directory: examples/bzlmod/hello_world
run_targets:
- "//third-party:vendor"
test_targets:
- "//..."
macos_bzlmod_bcr:
name: bzlmod BCR presubmit
platform: macos
working_directory: examples/bzlmod/hello_world
run_targets:
- "//third-party:vendor"
test_targets:
- "//..."
and
run_targets:
- "//third-party:vendor"
if we need to be invoking bazel run explicitly.

@cameron-martin
Copy link
Contributor Author

cameron-martin commented Jan 31, 2024

Adding a regular bazel test is trickier because gen_rust_project needs to invoke bazel in the same workspace that the tool is built from. I've added these to run_targets instead.

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

Thanks!

@illicitonion illicitonion merged commit 0f777e1 into bazelbuild:main Feb 1, 2024
3 checks passed
@cameron-martin cameron-martin deleted the canonical-aspects branch February 1, 2024 17:36
cameron-martin added a commit to cameron-martin/bazel-lsp that referenced this pull request Feb 18, 2024
Now that bazelbuild/rules_rust#2450 is fixed, we
can use a `rust-project.json` instead of `Cargo.toml` for IDE features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gen_rust_project does not work with bzlmod
2 participants