-
Notifications
You must be signed in to change notification settings - Fork 460
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
Bazel query is broken for Rust targets #2383
Comments
It looks like Bazel 7 made cc @cfredric @hlopko as authors of the feature cc @gregestren - it looks like rules_rust was depending on not reading through |
@gregestren Could you please advise what to do here? |
It looks like the standard attribute
The long-standing behavior of Why are you using an You're correct: we changed how |
That all makes sense in terms of how we got here, and I don't disagree with the behaviour of The background here in terms of rules_rust is that Google effectively wanted to add an optional implicit dependency to all of its rust code (#1008), and there hasn't historically been a very nice way of doing so. Macros are hard because you can't force other rulesets to use them. Possibly the extensible rules stuff Ivo is working on could help, though still has the "how do you force other rulesets to use it" problem. That implicit dependency, unfortunately, requires additional repositories to be registered in the workspace. We ideally don't want to do this automatically for the 99% of non-Google users who don't use this feature (and in a pre-bzlmod world it may be hard to do so, as it would possibly require our users add a second initialisation function to their WORKSPACE file, as that repository would depend on symbols we initialise in the function they already call). This broke query because we didn't register these repositories by default, and @hlopko found the cute workaround that was in place. So I guess the question is: How should Google be adding this dependency for their own code and not impact anyone else? Is there a reasonable way for them to extend the rules (or will there be soon)? Is there a way to register a dependency which doesn't show up to query unless it's enabled (maybe we could do something ugly like add this target as a dependency of a toolchain and either use an optional toolchain to enable it or have Google enable a custom toolchain which includes the dep where the default toolchain wouldn't)? Or any other cute ideas? |
The best ways, in rough order:
|
I'm happy to try rule extensions if they are suitable to solve this problem; @comius are they in good enough shape to be reliably depended upon? Could you point me to documentation/example usage? |
I didn't read through in detail, but could rules_rust/rust/private/rust.bzl Lines 531 to 533 in e6a1ee4
be replaced by a direct dependency on a The current selection is on rules_rust/util/import/BUILD.bazel Line 72 in e6a1ee4
Can whatever sets that boolean to |
I talked about this issue to @krasimirgg and @hlopko. We may have a need for having the import macro in OSS in the future, at which point we'll need to revisit this again; but for now it's okay to replace the import macro with a dummy in |
As discussed over at bazelbuild#2383
Drop import macro (bazelbuild#2411) As discussed over at bazelbuild#2383 Fix rustfmt toolchains when consuming rules_rust with bzlmod. (bazelbuild#2410) Fixes bazelbuild#2260 Provide a better error message when trying to generate rust-project.json (bazelbuild#2196) Currently when trying to generate a `rust-project.json`, if there aren't actually any Rust targets defined, the script mysteriously fails. This adds a better error message. Update android example to use Starlark version of android_ndk_repository (bazelbuild#2417) The native version of `android_ndk_repository` rule no longer work with the newer ndk versions. When I set `ANDROID_NDK_HOME` to `/usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125`, the rule expects a different structure from the Android NDK path. ``` ERROR: /usr/local/vinhdaitran/github/rules_rust/examples/android/WORKSPACE.bazel:67:23: fetching android_ndk_repository rule //external:androidndk: java.io.IOException: Expected directory at /usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125/platforms but it is not a directory or it does not exist. Unable to read the Android NDK at /usr/local/vinhdaitran/Android/Sdk/ndk/26.1.10909125, the path may be invalid. Is the path in android_ndk_repository() or ANDROID_NDK_HOME set correctly? If the path is correct, the contents in the Android NDK directory may have been modified. ``` Using the Starlark version of the rule, as recommended in https://bazel.build/reference/be/android#android_ndk_repository, fixes the issue. cc: @keith Allow ~ in repository names (bazelbuild#2427) Fixes bazelbuild#2426 Prepare rust rules for Starlark CcToolchainInfo. (bazelbuild#2424) bazelbuild#2425
It wasn't immediately clear to me from the discussion above, so for anyone else who may be hitting this issue when trying to upgrade to Bazel 7: it's fixed in 0.38.0. |
bazel version: 7.0.0
rules_rust version: 0.36.1
Sample: example.zip
To reproduce, run:
bazel query "deps(//:main)"
Output:
It looks like there is an implicit dependency on
@rules_rust/util/import
for all rust rules, but these dependencies are not included throughrules_rust_dependencies
.I'm guessing this dependency is coming from:
rules_rust/rust/private/rust.bzl
Lines 531 to 533 in e6a1ee4
The simplest fix seems like it would be to add
import_deps
torules_rust_dependencies
. However, I'm also wondering if it's really necessary for all rules to depend on@rules_rust/util/import
.This issue prevents usage of
bazel query
with rust targets, and breaks workflows that depend onbazel query
, e.g.ibazel
.The text was updated successfully, but these errors were encountered: