Skip to content

Commit b8eae19

Browse files
committed
Set CARGO_TARGET_DIR when using Flycheck custom command
1 parent ef8eae0 commit b8eae19

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

crates/flycheck/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub enum FlycheckConfig {
5858
extra_env: FxHashMap<String, String>,
5959
invocation_strategy: InvocationStrategy,
6060
invocation_location: InvocationLocation,
61+
target_dir: Option<PathBuf>,
6162
},
6263
}
6364

@@ -354,10 +355,15 @@ impl FlycheckActor {
354355
extra_env,
355356
invocation_strategy,
356357
invocation_location,
358+
target_dir,
357359
} => {
358360
let mut cmd = Command::new(command);
359361
cmd.envs(extra_env);
360362

363+
if let Some(target_dir) = target_dir {
364+
cmd.env("CARGO_TARGET_DIR", target_dir);
365+
}
366+
361367
match invocation_location {
362368
InvocationLocation::Workspace => {
363369
match invocation_strategy {

crates/rust-analyzer/src/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ impl Config {
12891289
}
12901290

12911291
pub fn flycheck(&self) -> FlycheckConfig {
1292+
let target_dir = self.target_dir_from_config();
12921293
match &self.data.check_overrideCommand {
12931294
Some(args) if !args.is_empty() => {
12941295
let mut args = args.clone();
@@ -1309,6 +1310,7 @@ impl Config {
13091310
}
13101311
InvocationLocation::Workspace => flycheck::InvocationLocation::Workspace,
13111312
},
1313+
target_dir,
13121314
}
13131315
}
13141316
Some(_) | None => FlycheckConfig::CargoCommand {
@@ -1343,7 +1345,7 @@ impl Config {
13431345
extra_args: self.check_extra_args(),
13441346
extra_env: self.check_extra_env(),
13451347
ansi_color_output: self.color_diagnostic_output(),
1346-
target_dir: self.target_dir_from_config(),
1348+
target_dir,
13471349
},
13481350
}
13491351
}

0 commit comments

Comments
 (0)