rust-analyzer/crates/project-model/src
bors c405509f2e Auto merge of #15560 - davidbarsky:davidbarsky/use-sysroot-rustc-to-determine-cfgs, r=Veykril
project-model: when using `rust-project.json`, prefer the sysroot-defined rustc over discovery in `$PATH`

At the moment, rust-analyzer discovers `rustc` via the `$PATH` even if the `sysroot` field is defined in a `rust-project.json`. However, this does not work for users who do not have rustup installed, resulting in any `cfg`-based inference in rust-analzyer not working correctly. In my (decently naive!) opinion, it makes more sense to rely on the `sysroot` field in the `rust-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:
- The path to the sysroot in my employer's monorepo changes depending on which platform a user is on. For example, if they're on Linux, they'd want to use the sysroot defined at path `a`, whereas if they're on macOS, they'd want to use the sysroot at path `b` (I wrote the sysroot resolution functionality [here](765da4ca1e/integrations/rust-project/src/sysroot.rs (L39)), if you're curious).
- The location of the sysroot can (and does!) change, especially as people figure out how to make Rust run successfully on non-Linux platforms (e.g., iOS, Android, etc.) in a monorepo. Updating people's `$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](https://github.com/facebook/buck2/tree/main/integrations/rust-project) and was able to successfully load a project with and without the `sysroot`/`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.
2023-09-08 18:14:25 +00:00
..
build_scripts.rs internal: use consistent style for error handling 2023-06-19 13:01:47 +01:00
cargo_workspace.rs Optimize DepKindInfo -> DepKind conversion 2023-07-21 17:10:42 +09:00
cfg_flag.rs Cleanup crate_graph construction 2023-03-31 14:14:04 +02:00
lib.rs internal: use consistent style for error handling 2023-06-19 13:01:47 +01:00
manifest_path.rs internal: use consistent style for error handling 2023-06-19 13:01:47 +01:00
project_json.rs Add AbsPath::absolutize 2023-05-13 11:51:28 +02:00
rustc_cfg.rs Update crates/project-model/src/rustc_cfg.rs 2023-09-08 14:07:59 -04:00
sysroot.rs project-model: when using rust-project.json, prefer the sysroot-defined rustc over an env-based one 2023-09-07 11:46:14 -04:00
target_data_layout.rs internal: use consistent style for error handling 2023-06-19 13:01:47 +01:00
tests.rs Allow setting cfgs 2023-05-28 13:43:21 +02:00
workspace.rs Auto merge of #15560 - davidbarsky:davidbarsky/use-sysroot-rustc-to-determine-cfgs, r=Veykril 2023-09-08 18:14:25 +00:00