Skip to content

Commit f1e51af

Browse files
committed
Auto merge of #14328 - lnicola:build-scripts-extra-args, r=Veykril
fix: Pass flycheck extra args when running build scripts Closes #14315 Not sure if we want to do it like this or to add an extra config key, though.
2 parents 70e10de + c3864eb commit f1e51af

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

crates/project-model/src/build_scripts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl WorkspaceBuildScripts {
6767
let mut cmd = Command::new(toolchain::cargo());
6868

6969
cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]);
70+
cmd.args(&config.extra_args);
7071

7172
// --all-targets includes tests, benches and examples in addition to the
7273
// default lib and bins. This is an independent concept from the --target

crates/project-model/src/cargo_workspace.rs

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ pub struct CargoConfig {
105105
pub wrap_rustc_in_build_scripts: bool,
106106
/// The command to run instead of `cargo check` for building build scripts.
107107
pub run_build_script_command: Option<Vec<String>>,
108+
/// Extra args to pass to the cargo command.
109+
pub extra_args: Vec<String>,
108110
/// Extra env vars to set when invoking the cargo command
109111
pub extra_env: FxHashMap<String, String>,
110112
pub invocation_strategy: InvocationStrategy,

crates/rust-analyzer/src/config.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ config_data! {
101101
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
102102
/// avoid checking unnecessary things.
103103
cargo_buildScripts_useRustcWrapper: bool = "true",
104+
/// Extra arguments that are passed to every cargo invocation.
105+
cargo_extraArgs: Vec<String> = "[]",
104106
/// Extra environment variables that will be set when running cargo, rustc
105107
/// or other commands within the workspace. Useful for setting RUSTFLAGS.
106108
cargo_extraEnv: FxHashMap<String, String> = "{}",
@@ -1055,10 +1057,20 @@ impl Config {
10551057
}
10561058
}
10571059

1060+
pub fn extra_args(&self) -> &Vec<String> {
1061+
&self.data.cargo_extraArgs
1062+
}
1063+
10581064
pub fn extra_env(&self) -> &FxHashMap<String, String> {
10591065
&self.data.cargo_extraEnv
10601066
}
10611067

1068+
pub fn check_extra_args(&self) -> Vec<String> {
1069+
let mut extra_args = self.extra_args().clone();
1070+
extra_args.extend_from_slice(&self.data.check_extraArgs);
1071+
extra_args
1072+
}
1073+
10621074
pub fn check_extra_env(&self) -> FxHashMap<String, String> {
10631075
let mut extra_env = self.data.cargo_extraEnv.clone();
10641076
extra_env.extend(self.data.check_extraEnv.clone());
@@ -1157,6 +1169,7 @@ impl Config {
11571169
InvocationLocation::Workspace => project_model::InvocationLocation::Workspace,
11581170
},
11591171
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
1172+
extra_args: self.data.cargo_extraArgs.clone(),
11601173
extra_env: self.data.cargo_extraEnv.clone(),
11611174
}
11621175
}
@@ -1227,7 +1240,7 @@ impl Config {
12271240
CargoFeaturesDef::All => vec![],
12281241
CargoFeaturesDef::Selected(it) => it,
12291242
},
1230-
extra_args: self.data.check_extraArgs.clone(),
1243+
extra_args: self.check_extra_args(),
12311244
extra_env: self.check_extra_env(),
12321245
ansi_color_output: self.color_diagnostic_output(),
12331246
},

docs/user/generated_config.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ cargo check --quiet --workspace --message-format=json --all-targets
7171
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
7272
avoid checking unnecessary things.
7373
--
74+
[[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`)::
75+
+
76+
--
77+
Extra arguments that are passed to every cargo invocation.
78+
--
7479
[[rust-analyzer.cargo.extraEnv]]rust-analyzer.cargo.extraEnv (default: `{}`)::
7580
+
7681
--

editors/code/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@
511511
"default": true,
512512
"type": "boolean"
513513
},
514+
"rust-analyzer.cargo.extraArgs": {
515+
"markdownDescription": "Extra arguments that are passed to every cargo invocation.",
516+
"default": [],
517+
"type": "array",
518+
"items": {
519+
"type": "string"
520+
}
521+
},
514522
"rust-analyzer.cargo.extraEnv": {
515523
"markdownDescription": "Extra environment variables that will be set when running cargo, rustc\nor other commands within the workspace. Useful for setting RUSTFLAGS.",
516524
"default": {},

0 commit comments

Comments
 (0)