bazelbuild / bazelbuild/rules_rust

gen_rust_project seems to be confused by different compilation modes.

Open
#2,722 1 comment 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

Hello! I'm having an issue where this command does not generate a correct `rust-project.json` for my project. Specifically, it excludes some crates:

```
RUST_LOG=trace bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
```

I see a line like this for each of the excluded crates:

```
[2024-07-02T19:03:23Z WARN gen_rust_project_lib::aquery] Skipping missing crate_spec file: "/private/var/tmp/_bazel_adam.faulkner/065dfc4b5a8c72f61fb4b946404058a5/execroot/_main/bazel-out/darwin_arm64-opt/bin/server_shared/rust/collections/collections.rust_analyzer_crate_spec.json"
```

I noticed that these `crate_spec.json` files actually are generated for `darwin_arm64-fastbuild`, so I tried to build these using this command:

```
bazel build -c opt --norun_validations --aspects=@rules_rust//rust:defs.bzl%rust_analyzer_aspect --output_groups=rust_analyzer_crate_spec,rust_generated_srcs //...
```

After this, the `gen_rust_project` command started working. I've found a few other workarounds as well, including defining "dummy" test targets in these projects that are excluded.

I tried to read the code and understand what is going on, but I was not able to really understand what is going on here. It seems like there's probably some code that assumes an optimized build was created, but the build command does not run in this mode.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.