-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
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:
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 <[email protected]>
☀️ Test successful - checks-actions |
rust-project.json
, prefer the sysroot-defined rustc over discovery in $PATH
rust-project.json
, prefer the sysroot-defined rustc over discovery in $PATH
At the moment, rust-analyzer discovers
rustc
via the$PATH
even if thesysroot
field 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 thesysroot
field in therust-project.json
.One might ask "why not add
rustc
to 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).$PATH
company-wide is hard while updating a config inside a CLI is pretty easy.Testing
I've created a
rust-project.json
using rust-project and was able to successfully load a project with and without thesysroot
/sysroot_src
fields—without those fields, rust-analyzer fell back to the$PATH
based approach, as evidenced by[DEBUG project_model::rustc_cfg] using rustc from env rustc="rustc"
showing up in the logs.