aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorDaniel McNab <[email protected]>2021-03-08 09:05:19 +0000
committerDaniel McNab <[email protected]>2021-03-08 09:05:19 +0000
commitddce6bb282764692d53b719bff4c37e3512d4556 (patch)
tree0bce7b0c1d7f4b3f870027493bf6e3a2c55efe91 /crates
parent877f745551ff74da987a61f1c8a059d30140fb8a (diff)
Support disabling rustc build scripts
Diffstat (limited to 'crates')
-rw-r--r--crates/project_model/src/workspace.rs14
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs3
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs3
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs8
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs10
-rw-r--r--crates/rust-analyzer/src/cli/ssr.rs18
-rw-r--r--crates/rust-analyzer/src/config.rs5
-rw-r--r--crates/rust-analyzer/src/reload.rs5
8 files changed, 54 insertions, 12 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index ea0c9ff60..d754c8b55 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -56,6 +56,7 @@ impl fmt::Debug for ProjectWorkspace {
56 match self { 56 match self {
57 ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } => f 57 ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } => f
58 .debug_struct("Cargo") 58 .debug_struct("Cargo")
59 .field("root", &cargo.workspace_root())
59 .field("n_packages", &cargo.packages().len()) 60 .field("n_packages", &cargo.packages().len())
60 .field("n_sysroot_crates", &sysroot.crates().len()) 61 .field("n_sysroot_crates", &sysroot.crates().len())
61 .field( 62 .field(
@@ -273,12 +274,19 @@ impl ProjectWorkspace {
273 crate_graph 274 crate_graph
274 } 275 }
275 276
276 pub fn collect_build_data_configs(&self, collector: &mut BuildDataCollector) { 277 pub fn collect_build_data_configs(
278 &self,
279 collector: &mut BuildDataCollector,
280 for_private: bool,
281 ) {
277 match self { 282 match self {
278 ProjectWorkspace::Cargo { cargo, rustc, .. } => { 283 ProjectWorkspace::Cargo { cargo, rustc, .. } => {
279 collector.add_config(&cargo.workspace_root(), cargo.build_data_config().clone()); 284 collector.add_config(&cargo.workspace_root(), cargo.build_data_config().clone());
280 if let Some(rustc) = rustc { 285 if for_private {
281 collector.add_config(rustc.workspace_root(), rustc.build_data_config().clone()); 286 if let Some(rustc) = rustc {
287 collector
288 .add_config(rustc.workspace_root(), rustc.build_data_config().clone());
289 }
282 } 290 }
283 } 291 }
284 _ => {} 292 _ => {}
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 3bd7e678d..104f2e8a2 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -68,6 +68,9 @@ impl BenchCmd {
68 let load_cargo_config = LoadCargoConfig { 68 let load_cargo_config = LoadCargoConfig {
69 load_out_dirs_from_check: self.load_output_dirs, 69 load_out_dirs_from_check: self.load_output_dirs,
70 with_proc_macro: self.with_proc_macro, 70 with_proc_macro: self.with_proc_macro,
71 // This will currently never have rustcSource set, however if in
72 // future it does this will handle that case
73 run_rustc_build_scripts: true,
71 }; 74 };
72 let (mut host, vfs, _proc_macro) = 75 let (mut host, vfs, _proc_macro) =
73 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; 76 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?;
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ad0759bda..5a8432960 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -63,6 +63,9 @@ impl AnalysisStatsCmd {
63 let load_cargo_config = LoadCargoConfig { 63 let load_cargo_config = LoadCargoConfig {
64 load_out_dirs_from_check: self.load_output_dirs, 64 load_out_dirs_from_check: self.load_output_dirs,
65 with_proc_macro: self.with_proc_macro, 65 with_proc_macro: self.with_proc_macro,
66 // This will currently never have rustcSource set, however if in
67 // future it does this will handle that case
68 run_rustc_build_scripts: true,
66 }; 69 };
67 let (host, vfs, _proc_macro) = 70 let (host, vfs, _proc_macro) =
68 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?; 71 load_workspace_at(&self.path, &cargo_config, &load_cargo_config, &|_| {})?;
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 8b985716b..e1966b5a7 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -34,7 +34,13 @@ pub fn diagnostics(
34 with_proc_macro: bool, 34 with_proc_macro: bool,
35) -> Result<()> { 35) -> Result<()> {
36 let cargo_config = Default::default(); 36 let cargo_config = Default::default();
37 let load_cargo_config = LoadCargoConfig { load_out_dirs_from_check, with_proc_macro }; 37 let load_cargo_config = LoadCargoConfig {
38 load_out_dirs_from_check,
39 with_proc_macro,
40 // This will currently never have rustcSource set, however if in
41 // future it does this will handle that case
42 run_rustc_build_scripts: true,
43 };
38 let (host, _vfs, _proc_macro) = 44 let (host, _vfs, _proc_macro) =
39 load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; 45 load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?;
40 let db = host.raw_database(); 46 let db = host.raw_database();
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index 310c36904..3d7b5031a 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -14,6 +14,7 @@ use vfs::{loader::Handle, AbsPath, AbsPathBuf};
14use crate::reload::{ProjectFolders, SourceRootConfig}; 14use crate::reload::{ProjectFolders, SourceRootConfig};
15 15
16pub struct LoadCargoConfig { 16pub struct LoadCargoConfig {
17 pub run_rustc_build_scripts: bool,
17 pub load_out_dirs_from_check: bool, 18 pub load_out_dirs_from_check: bool,
18 pub with_proc_macro: bool, 19 pub with_proc_macro: bool,
19} 20}
@@ -53,7 +54,7 @@ pub fn load_workspace(
53 54
54 let build_data = if config.load_out_dirs_from_check { 55 let build_data = if config.load_out_dirs_from_check {
55 let mut collector = BuildDataCollector::default(); 56 let mut collector = BuildDataCollector::default();
56 ws.collect_build_data_configs(&mut collector); 57 ws.collect_build_data_configs(&mut collector, config.run_rustc_build_scripts);
57 Some(collector.collect(progress)?) 58 Some(collector.collect(progress)?)
58 } else { 59 } else {
59 None 60 None
@@ -136,8 +137,11 @@ mod tests {
136 fn test_loading_rust_analyzer() -> Result<()> { 137 fn test_loading_rust_analyzer() -> Result<()> {
137 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap(); 138 let path = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap().parent().unwrap();
138 let cargo_config = Default::default(); 139 let cargo_config = Default::default();
139 let load_cargo_config = 140 let load_cargo_config = LoadCargoConfig {
140 LoadCargoConfig { load_out_dirs_from_check: false, with_proc_macro: false }; 141 load_out_dirs_from_check: false,
142 with_proc_macro: false,
143 run_rustc_build_scripts: false,
144 };
141 let (host, _vfs, _proc_macro) = 145 let (host, _vfs, _proc_macro) =
142 load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?; 146 load_workspace_at(path, &cargo_config, &load_cargo_config, &|_| {})?;
143 147
diff --git a/crates/rust-analyzer/src/cli/ssr.rs b/crates/rust-analyzer/src/cli/ssr.rs
index 79f426fff..8cc4eefc2 100644
--- a/crates/rust-analyzer/src/cli/ssr.rs
+++ b/crates/rust-analyzer/src/cli/ssr.rs
@@ -9,8 +9,13 @@ use ide_ssr::{MatchFinder, SsrPattern, SsrRule};
9pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> { 9pub fn apply_ssr_rules(rules: Vec<SsrRule>) -> Result<()> {
10 use ide_db::base_db::SourceDatabaseExt; 10 use ide_db::base_db::SourceDatabaseExt;
11 let cargo_config = Default::default(); 11 let cargo_config = Default::default();
12 let load_cargo_config = 12 let load_cargo_config = LoadCargoConfig {
13 LoadCargoConfig { load_out_dirs_from_check: true, with_proc_macro: true }; 13 load_out_dirs_from_check: true,
14 with_proc_macro: true,
15 // This will currently never have rustcSource set, however if in
16 // future it does this will handle that case
17 run_rustc_build_scripts: true,
18 };
14 let (host, vfs, _proc_macro) = 19 let (host, vfs, _proc_macro) =
15 load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?; 20 load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?;
16 let db = host.raw_database(); 21 let db = host.raw_database();
@@ -36,8 +41,13 @@ pub fn search_for_patterns(patterns: Vec<SsrPattern>, debug_snippet: Option<Stri
36 use ide_db::base_db::SourceDatabaseExt; 41 use ide_db::base_db::SourceDatabaseExt;
37 use ide_db::symbol_index::SymbolsDatabase; 42 use ide_db::symbol_index::SymbolsDatabase;
38 let cargo_config = Default::default(); 43 let cargo_config = Default::default();
39 let load_cargo_config = 44 let load_cargo_config = LoadCargoConfig {
40 LoadCargoConfig { load_out_dirs_from_check: true, with_proc_macro: true }; 45 load_out_dirs_from_check: true,
46 with_proc_macro: true,
47 // This will currently never have rustcSource set, however if in
48 // future it does this will handle that case
49 run_rustc_build_scripts: true,
50 };
41 let (host, _vfs, _proc_macro) = 51 let (host, _vfs, _proc_macro) =
42 load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?; 52 load_workspace_at(&std::env::current_dir()?, &cargo_config, &load_cargo_config, &|_| {})?;
43 let db = host.raw_database(); 53 let db = host.raw_database();
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 367136702..cbec8fce2 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -49,6 +49,8 @@ config_data! {
49 /// Run build scripts (`build.rs`) for more precise code analysis. 49 /// Run build scripts (`build.rs`) for more precise code analysis.
50 cargo_runBuildScripts | 50 cargo_runBuildScripts |
51 cargo_loadOutDirsFromCheck: bool = "false", 51 cargo_loadOutDirsFromCheck: bool = "false",
52 /// Disable running build scripts (`build.rs`) for the `rustc_private` crates in `rustcSource`.
53 cargo_disableRustcBuildScripts: bool = "false",
52 /// Do not activate the `default` feature. 54 /// Do not activate the `default` feature.
53 cargo_noDefaultFeatures: bool = "false", 55 cargo_noDefaultFeatures: bool = "false",
54 /// Compilation target (target triple). 56 /// Compilation target (target triple).
@@ -482,6 +484,9 @@ impl Config {
482 pub fn run_build_scripts(&self) -> bool { 484 pub fn run_build_scripts(&self) -> bool {
483 self.data.cargo_runBuildScripts || self.data.procMacro_enable 485 self.data.cargo_runBuildScripts || self.data.procMacro_enable
484 } 486 }
487 pub fn run_rustc_build_scripts(&self) -> bool {
488 self.run_build_scripts() && !self.data.cargo_disableRustcBuildScripts
489 }
485 pub fn cargo(&self) -> CargoConfig { 490 pub fn cargo(&self) -> CargoConfig {
486 let rustc_source = self.data.rustcSource.as_ref().map(|rustc_src| { 491 let rustc_source = self.data.rustcSource.as_ref().map(|rustc_src| {
487 if rustc_src == "discover" { 492 if rustc_src == "discover" {
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index aa8504c3d..da02be2de 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -340,7 +340,10 @@ impl GlobalState {
340 if self.config.run_build_scripts() && workspace_build_data.is_none() { 340 if self.config.run_build_scripts() && workspace_build_data.is_none() {
341 let mut collector = BuildDataCollector::default(); 341 let mut collector = BuildDataCollector::default();
342 for ws in &workspaces { 342 for ws in &workspaces {
343 ws.collect_build_data_configs(&mut collector); 343 ws.collect_build_data_configs(
344 &mut collector,
345 self.config.run_rustc_build_scripts(),
346 );
344 } 347 }
345 self.fetch_build_data_request(collector) 348 self.fetch_build_data_request(collector)
346 } 349 }