rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

bazel cache polluted, rust_analyzer json missing "is_test"

Open sthornington opened this issue 2 months ago • 3 comments

Hi folks,

We have a bazel install with a shared disk cache, and also a remote cache, using rules_rust pretty much "stock". However, the other day, when we upgraded rules_rust to something recent, a bunch of builds started failing because some json files to do with rust_analyzer artifacts were causing problems because they were missing an "is_test" field.

I kinda figure that a recent rust_analyzer update in a recent rust toolchain update added this field, and therefore things were expecting it, but that for some reason, the version of the rust toolchain selected by rules_rust by default was not included in the bazel hashes/stamps, and therefore everything was erroneously using old incompatible cached artifacts whose hash had not changed.

Is this expected? Is there a simple way to get rules_rust toolchains to stamp things including the version of the rust compiler/toolchain version so that when the rust compiler version is changed, all the cached artifacts are invalidated?

I'm, for now, going to try passing versions = [MY_RUST_VERSION] in the rust_register_toolchains to see if that adds the requisite stamping, but I am not confident that this will do the trick.... Thanks!

sthornington avatar Oct 24 '25 21:10 sthornington

This is an example of the problem in reverse, I think, but I am not 100% sure:

Error: Failed to deserialize file: /scratch/gitlab-runner/bazel_base/2adff033393966ff383377ea5f1b0c20/execroot/__main__/bazel-out/k8-dbg/bin/external/crate_index__equivalent-1.0.2/equivalent.rust_analyzer_crate_spec.json
Caused by:
    unknown field `is_test`, expected one of `aliases`, `crate_id`, `display_name`, `edition`, `root_module`, `is_workspace_member`, `deps`, `proc_macro_dylib_path`, `source`, `cfg`, `env`, `target`, `crate_type` at line 30 column 14

sthornington avatar Oct 24 '25 21:10 sthornington

This feels related to https://github.com/bazelbuild/rules_rust/issues/2774, would a bazel clean solve this?

UebelAndre avatar Oct 24 '25 21:10 UebelAndre

I can see if I can find a place to put a bazel clean in these CI pipelines yeah....

sthornington avatar Oct 24 '25 23:10 sthornington