-
Notifications
You must be signed in to change notification settings - Fork 1.9k
internal: project-model: when using rust-project.json, prefer the sysroot-defined rustc over discovery in $PATH
#15560
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
internal: project-model: when using rust-project.json, prefer the sysroot-defined rustc over discovery in $PATH
#15560
Conversation
…ined rustc over an env-based one
839409a to
553152e
Compare
davidbarsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No rush on reviewing this, but I wanted to leave comments on the approach I took here since changes inside of project-model can be kinda tricky.
| use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath}; | ||
| use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath, Sysroot}; | ||
|
|
||
| pub(crate) enum RustcCfgConfig<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name here is a little generic, but I'm struggling to think of anything better. In any case, I hope that the doc comment helps a little.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire module is slightly mislabeled by now I feel like, not sure what a better name for this would be though. Maybe builtin_cfg and the like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtin_cfg is a good option. While we're bikeshedding, what do you think something like target_cfg since the output consists of things like:
Veykril
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me
|
@bors delegate+ |
|
✌️ @davidbarsky, you can now approve this pull request! If @Veykril told you to " |
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
|
☀️ Test successful - checks-actions |
rust-project.json, prefer the sysroot-defined rustc over discovery in $PATHrust-project.json, prefer the sysroot-defined rustc over discovery in $PATH
At the moment, rust-analyzer discovers
rustcvia the$PATHeven if thesysrootfield is defined in arust-project.json. However, this does not work for users who do not have rustup installed, resulting in anycfg-based inference in rust-analzyer not working correctly. In my (decently naive!) opinion, it makes more sense to rely on thesysrootfield in therust-project.json.One might ask "why not add
rustcto the$PATH?" That is a reasonable question, but that doesn't work for my use case:a, whereas if they're on macOS, they'd want to use the sysroot at pathb(I wrote the sysroot resolution functionality here, if you're curious).$PATHcompany-wide is hard while updating a config inside a CLI is pretty easy.Testing
I've created a
rust-project.jsonusing rust-project and was able to successfully load a project with and without thesysroot/sysroot_srcfields—without those fields, rust-analyzer fell back to the$PATHbased approach, as evidenced by[DEBUG project_model::rustc_cfg] using rustc from env rustc="rustc"showing up in the logs.