Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit cd79447

Browse files
authored
Merge pull request #1167 from alexheretic/dot-cargo-config-target
Use .cargo/config build.target-dir + "/rls"
2 parents cfd8449 + 2187243 commit cd79447

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/build/cargo.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -690,16 +690,28 @@ pub fn make_cargo_config(
690690
.entry("build".to_owned())
691691
.or_insert_with(|| ConfigValue::Table(HashMap::new(), config_path.clone()));
692692

693-
let target_dir = target_dir
694-
.map(|d| d.to_str().unwrap().to_owned())
695-
.unwrap_or_else(|| {
696-
build_dir
697-
.join("target")
698-
.join("rls")
699-
.to_str()
700-
.unwrap()
701-
.to_owned()
702-
});
693+
let target_dir = target_dir
694+
.map(|d| d.to_str().unwrap().to_owned())
695+
.unwrap_or_else(|| {
696+
// Try to use .cargo/config build.target-dir + "/rls"
697+
let cargo_target = build_value
698+
.table("build")
699+
.ok()
700+
.and_then(|(build, _)| build.get("target-dir"))
701+
.and_then(|td| td.string("target-dir").ok())
702+
.map(|(target, _)| {
703+
let t_path = Path::new(target);
704+
if t_path.is_absolute() {
705+
t_path.into()
706+
} else {
707+
build_dir.join(t_path)
708+
}
709+
})
710+
.unwrap_or_else(|| build_dir.join("target"));
711+
712+
cargo_target.join("rls").to_str().unwrap().to_owned()
713+
});
714+
703715
let td_value = ConfigValue::String(target_dir, config_path);
704716
if let ConfigValue::Table(ref mut build_table, _) = *build_value {
705717
build_table.insert("target-dir".to_owned(), td_value);

0 commit comments

Comments
 (0)