From 7ae92f782cc7e24576894983fc027ac6260d0c43 Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Wed, 31 Jan 2024 00:29:08 +0000 Subject: [PATCH 1/2] Use canonical repo name for aspects 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. --- tools/tool_utils.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tool_utils.bzl b/tools/tool_utils.bzl index de876b1403..4ce78d80e2 100644 --- a/tools/tool_utils.bzl +++ b/tools/tool_utils.bzl @@ -12,4 +12,4 @@ def aspect_repository(): """ if native.repository_name() == "@": return "" - return native.repository_name() + return "@" + native.repository_name() From 74fb8c741c31cce0d92712b7775e116c12aec782 Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Wed, 31 Jan 2024 21:41:06 +0000 Subject: [PATCH 2/2] Add tests --- .bazelci/presubmit.yml | 2 ++ .bcr/presubmit.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 6281c449fc..8004fb1e8c 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -644,6 +644,7 @@ tasks: working_directory: examples/bzlmod/hello_world run_targets: - "//third-party:vendor" + - "@rules_rust//tools/rust_analyzer:gen_rust_project" test_targets: - "//..." macos_bzlmod_bcr: @@ -652,6 +653,7 @@ tasks: working_directory: examples/bzlmod/hello_world run_targets: - "//third-party:vendor" + - "@rules_rust//tools/rust_analyzer:gen_rust_project" test_targets: - "//..." diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml index d5223107f6..4d1810a4db 100644 --- a/.bcr/presubmit.yml +++ b/.bcr/presubmit.yml @@ -9,5 +9,6 @@ bcr_test_module: platform: ${{ platform }} run_targets: - "//third-party:vendor" + - "@rules_rust//tools/rust_analyzer:gen_rust_project" test_targets: - "//..."