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:
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.
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
stdis being resolved fine, butproc_macroisn't.I think I understand what's going on with
SYSROOT_CRATESandSTD_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 justsrc/example/lib.rs: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:
Which corresponds to
SYSROOT_CRATES, and because ofSTD_DEPS, by default crates don't getproc_macro. However, I can't simply add"deps": [{"crate": 4, "name": "proc_macro"}], since crate 4 does not exist in therust-project.json. If I manually add aproc_macrocrate, 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:
Although this indicates to me there are probably two
proc_macrocrates, one withCrateId(4)and one withCrateId(10).TL;DR:
Is manually specifying
proc_macrowhile still usingsysroot_srcthe way to go? Or could having twoproc_macrocrates cause a problem? If so, would it be better to omitsysroot_srcand populate all sysroot crates myself inrust-project.json? In this case, it seems like crates don't getSTD_DEPS, which is fine.I'm just looking for some guidance on which is the way to go for
rust-project.jsonusers. Either approach works fine, although begin able to continue to usesysroot_srcwould be less effort.(Another consideration could be to allow specifying further standard dependencies from the sysroot crates i.e. when using
sysroot_src? Thecratefield indepscould allow other values if this seems like a useful feature.)Thanks for your time and work on Rust Analyzer! It's an invaluable tool.