Skip to content
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

rust-project.json points to non-existing file #2991

Open
otiv-willem-vanhulle opened this issue Nov 7, 2024 · 4 comments
Open

rust-project.json points to non-existing file #2991

otiv-willem-vanhulle opened this issue Nov 7, 2024 · 4 comments

Comments

@otiv-willem-vanhulle
Copy link

When I run

bazel run @rules_rust//tools/rust_analyzer:gen_rust_project

in my Bazel/Rust project, the generated rust-project.json contains an entry for an code-generated crate, but the path in root_module of the crate entry does not exist. Removing the rust_project.json and re-running it doesn't fix it. I have tried disabling the disk_cache, but the command above still generates the wrong root_module.

This is an example output

{
  "sysroot": "/home/wvhulle/.cache/bazel/_bazel_wvhulle/2f024897ff0f2736b273e0e86d0d74ec//external/rules_rust~~rust~rust_analyzer_1.80.0_tools",
  "sysroot_src": "/home/wvhulle/.cache/bazel/_bazel_wvhulle/2f024897ff0f2736b273e0e86d0d74ec/external/rules_rust~~rust~rust_analyzer_1.80.0_tools/lib/rustlib/src/library",
  "crates": [
    {
      "display_name": "middleware_messages",
      "root_module": "/home/wvhulle/.cache/bazel/_bazel_wvhulle/2f024897ff0f2736b273e0e86d0d74ec/execroot/_main/bazel-out/k8-fastbuild/bin/otiv3/middleware_types/middleware_messages.lib.rs",
      "edition": "2021",
      "deps": [],
      "is_workspace_member": true,
      "cfg": [
        "test",
        "debug_assertions"
      ],}]}

The file /home/wvhulle/.cache/bazel/_bazel_wvhulle/2f024897ff0f2736b273e0e86d0d74ec/execroot/_main/bazel-out/k8-fastbuild/bin/otiv3/middleware_types/middleware_messages.lib.rs does not exist although the target can be build without problem.

I have tried to disable the disk cache completely, removing the disk cache at ~/.cache/bazel completely and also changing the location with --disk_cache=~/.cache/bazel_disk_cache.

It seems like the wrong path is generated pointing to a non-existing location in the cache. Sometimes it suddenly works, but often it is just broken and I don't understand why.

@otiv-willem-vanhulle
Copy link
Author

I seem to make some progress if remove all disk cache options from .bazelrc: common --disk_cache=~/.cache/bazel_disk_cache. It seems like there is a bug that causes the rust-project.json not to detect the usage of an alternative disk_cache. When I don't specify the cache and start from a clean state, things seem to work at first sight.

@martingms
Copy link

What does your BUILD file look like? I'm having a lot of issues with crates that contains srcs that are a mix between generated and non-generated, some of which are (in my case) fixed by #3040, but unsure whether that's the right fix.

@otiv-willem-vanhulle
Copy link
Author

@martingms I cannot share the build file, it is part of a private repository. We have several build files. The build file that should generate the *.lib.rs file doesn't. It uses Prost and Tonic to generate a Rust source code file, but the source code file doesn't appear.

I have noticed that if I disable the local disk cache temporarily in configuration settings and then build the generated source file by calling Bazel build directly, suddenly the file is generated in the right place, as specified by rust-project.json. Afterwards I can enable the disk cache again and the generated file stays.

I have tried reproducing this and I have had some success. But it takes a lot of time. Whenever I notice I have a generated rust-project.json file that points to something that doesn't exist, there are some steps I can take.

  1. I use find to verify the lib.rs file really doesn't exist anywhere on my system.
  2. I disable the disk cache in .bazelrc.
  3. I remove every Bazel cache folder from my home folder.
  4. I rebuild the code generation target. This will take very long.
  5. Regenerate rust-project.json.
  6. The file mentioned in rust-project.json appears suddenly in my cache.

It is quite painful and should work out of the box without disabling the cache.

@martingms how do you think your patch would fix that?

@martingms
Copy link

Right, that sounds probably unrelated to my issue then -- I have a lib.rs that is manually written, but generated srcs next to it.

Generated code and rust-project.json is still kinda rough in general!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants