diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-09 11:33:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-09 11:33:31 +0100 |
commit | 6c0cdc5f550c0ccef762fcff7d1fbee9b6245027 (patch) | |
tree | 3e56ee06982fddc9e10127999d4ee7a0e6071399 /crates/project_model/src/workspace.rs | |
parent | cf4d4f646b6227242b2d4e216e8e30b5e111e02e (diff) | |
parent | b7e6537935d421afd7e02585aaa5cec92bee63b0 (diff) |
Merge #8774
8774: feat: Honor `.cargo/config.toml` r=matklad a=Veykril
![f1Gup1aiAn](https://user-images.githubusercontent.com/3757771/117545448-1dcaae00-b026-11eb-977a-0f35a5e3f2e0.gif)
Implements `cargo/.config` build target and cfg access by using unstable cargo options:
- `cargo config get` to read the target triple out of the config to pass to `cargo metadata` --filter-platform
- `cargo rustc --print` to read out the `rustc_cfgs`, this causes us to honor `rustflags` and the like.
If those commands fail, due to not having a nightly toolchain present for example, they will fall back to invoking rustc directly as we currently do.
I personally think it should be fine to use these unstable options as they are unlikely to change(even if they did it shouldn't be a problem due to the fallback) and don't burden the user if they do not have a nightly toolchain at hand since we fall back to the previous behaviour.
cc #8741
Closes #6604, Closes #5904, Closes #8430, Closes #8480
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/project_model/src/workspace.rs')
-rw-r--r-- | crates/project_model/src/workspace.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 2fcd0f8fa..84c702fdf 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs | |||
@@ -143,7 +143,8 @@ impl ProjectWorkspace { | |||
143 | } else { | 143 | } else { |
144 | None | 144 | None |
145 | }; | 145 | }; |
146 | let rustc_cfg = rustc_cfg::get(config.target.as_deref()); | 146 | |
147 | let rustc_cfg = rustc_cfg::get(Some(&cargo_toml), config.target.as_deref()); | ||
147 | ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } | 148 | ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } |
148 | } | 149 | } |
149 | }; | 150 | }; |
@@ -159,7 +160,7 @@ impl ProjectWorkspace { | |||
159 | Some(path) => Some(Sysroot::load(path)?), | 160 | Some(path) => Some(Sysroot::load(path)?), |
160 | None => None, | 161 | None => None, |
161 | }; | 162 | }; |
162 | let rustc_cfg = rustc_cfg::get(target); | 163 | let rustc_cfg = rustc_cfg::get(None, target); |
163 | Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg }) | 164 | Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg }) |
164 | } | 165 | } |
165 | 166 | ||
@@ -310,7 +311,7 @@ fn project_json_to_crate_graph( | |||
310 | 311 | ||
311 | let target_cfgs = match krate.target.as_deref() { | 312 | let target_cfgs = match krate.target.as_deref() { |
312 | Some(target) => { | 313 | Some(target) => { |
313 | cfg_cache.entry(target).or_insert_with(|| rustc_cfg::get(Some(target))) | 314 | cfg_cache.entry(target).or_insert_with(|| rustc_cfg::get(None, Some(target))) |
314 | } | 315 | } |
315 | None => &rustc_cfg, | 316 | None => &rustc_cfg, |
316 | }; | 317 | }; |