Skip to content

rust-project.json sysroot crates question #9726

@tobywf

Description

@tobywf

I've followed the instructions for non-Cargo based projects, and it largely works great, so thank you for implementing this. There's a small issue about picking up sysroot crates that I'm hitting, where std is being resolved fine, but proc_macro isn't.

I think I understand what's going on with SYSROOT_CRATES and STD_DEPS, but still have some questions around the best way to reference other sysroot crates (further down). For context, take this minimal working example, with just src/example/lib.rs:

use std;
use proc_macro;

And rust-project.json:

{
  "sysroot_src": "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/",
  "crates": [
    {
      "cfg": [],
      "deps": [],
      "edition": "2018",
      "env": {},
      "is_workspace_member": true,
      "root_module": "src/example/lib.rs"
    }
  ]
}

The status tells me:

file info:
crate: CrateId(10)
deps: core=CrateId(1), alloc=CrateId(0), std=CrateId(6)

Which corresponds to SYSROOT_CRATES, and because of STD_DEPS, by default crates don't get proc_macro. However, I can't simply add "deps": [{"crate": 4, "name": "proc_macro"}], since crate 4 does not exist in the rust-project.json. If I manually add a proc_macro crate, then it works:

{
  "sysroot_src": "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/",
  "crates": [
    {
      "cfg": [],
      "deps": [],
      "edition": "2018",
      "env": {},
      "is_workspace_member": false,
      "root_module": "/Users/user/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/lib.rs"
    },
    {
      "cfg": [],
      "deps": [
        {
          "crate": 0,
          "name": "proc_macro"
        }
      ],
      "edition": "2018",
      "env": {},
      "is_workspace_member": true,
      "root_module": "src/example/lib.rs"
    }
  ]
}

And I get:

file info:
crate: CrateId(11)
deps: core=CrateId(1), alloc=CrateId(0), std=CrateId(6), proc_macro=CrateId(10)

Although this indicates to me there are probably two proc_macro crates, one with CrateId(4) and one with CrateId(10).

TL;DR:

Is manually specifying proc_macro while still using sysroot_src the way to go? Or could having two proc_macro crates cause a problem? If so, would it be better to omit sysroot_src and populate all sysroot crates myself in rust-project.json? In this case, it seems like crates don't get STD_DEPS, which is fine.

I'm just looking for some guidance on which is the way to go for rust-project.json users. Either approach works fine, although begin able to continue to use sysroot_src would be less effort.

(Another consideration could be to allow specifying further standard dependencies from the sysroot crates i.e. when using sysroot_src? The crate field in deps could allow other values if this seems like a useful feature.)

Thanks for your time and work on Rust Analyzer! It's an invaluable tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-actionableSomeone could pick this issue up and work on it right now

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions