-
Notifications
You must be signed in to change notification settings - Fork 440
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
[not resolved, just worked around]@rules_rust//tools/rustfmt
only runs on built targets
#749
Comments
@hlopko do you have any thoughts on why this might be the case? 😅 |
|
I think this was a false alarm. I'm able to format sources from a clean build without building anything by applying the following diff: diff --git a/tools/rustfmt/srcs/main.rs b/tools/rustfmt/srcs/main.rs
index 5f17316..0d302a6 100644
--- a/tools/rustfmt/srcs/main.rs
+++ b/tools/rustfmt/srcs/main.rs
@@ -76,7 +76,7 @@ fn query_rustfmt_targets(options: &Config) -> Vec<String> {
fn generate_rustfmt_target_manifests(options: &Config, targets: &[String]) {
let build_args = vec![
"build",
- "--aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect",
+ "--aspects=//rust:defs.bzl%rustfmt_aspect",
"--output_groups=rustfmt_manifest",
];
It turns out when the following is evaluated: rules_rust/rust/private/rustfmt.bzl Lines 16 to 17 in 7bf61a8
There is a difference between |
What kind of difference? Targets coming from |
Sorry for the delay here. With this diff, if you diff --git a/.bazelrc b/.bazelrc
index db9695b..a61cbe3 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -2,5 +2,5 @@
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file
# Enable rustfmt for all targets in the workspace
-build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
+build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
diff --git a/rust/private/rustfmt.bzl b/rust/private/rustfmt.bzl
index 9c59f48..789791a 100644
--- a/rust/private/rustfmt.bzl
+++ b/rust/private/rustfmt.bzl
@@ -13,6 +13,11 @@ def _find_rustfmtable_srcs(target, aspect_ctx = None):
Returns:
list: A list of formattable sources (`File`).
"""
+
+ if aspect_ctx and aspect_ctx.rule.kind in ["rust_library", "rust_binary", "rust_test"]:
+ print(target)
+ crate_info = target[rust_common.crate_info]
+
if rust_common.crate_info not in target:
return [] This is that error
I forget what the failure mode was that lead me to an error message that lead me to find this works from the repo root if diff --git a/.bazelrc b/.bazelrc
index db9695b..a61cbe3 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -2,5 +2,5 @@
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file
# Enable rustfmt for all targets in the workspace
-build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
+build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks Unfortunately, it doesn't and |
Oh that's a Bazel bug. I just found bazelbuild/bazel#11734. |
Ah, neat. Should I close this issue then? |
Yeah let's do that. Bazel team, if you're reading this, this is not resolved, we are just using a workaround and we don't want to keep the issue open only to wait for the fix in Bazel :) |
@rules_rust//tools/rustfmt
only runs on built targets@rules_rust//tools/rustfmt
only runs on built targets
I noticed if I run
bazel clean
, then intentionally ruin formatting in a source file for one of my rust targets, then runbazel run @rules_rust//tools/rustfmt
, that my target isn't formatted. In fact, no target is formatted. Under the hood, that binary is running a bazel build command with the following arguments:rules_rust/tools/rustfmt/srcs/main.rs
Lines 78 to 80 in d6cf2ec
My thought was
--output_groups=rustfmt_manifest
would tell bazel that this is the only target that needs to be produced and only do work to generate that. But alas, no manifest is generated. Is there something I'm missing about the use of output_groups? I thought this would workThe text was updated successfully, but these errors were encountered: