Skip to content

Commit 7794d62

Browse files
committed
implement "host" target substitution
1 parent a2f54c7 commit 7794d62

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/cargo/core/compiler/compile_kind.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,27 @@ impl CompileKind {
8484
fallback: CompileKindFallback,
8585
) -> CargoResult<Vec<CompileKind>> {
8686
let dedup = |targets: &[String]| {
87-
Ok(targets
87+
let deduplicated_targets = targets
8888
.iter()
89-
.map(|value| Ok(CompileKind::Target(CompileTarget::new(value)?)))
89+
.map(|value| {
90+
// This neatly substitutes the manually-specified `host` target directive
91+
// with the compiling machine's target triple.
92+
93+
if value.as_str() == "host" {
94+
let host_triple = env!("RUST_HOST_TARGET");
95+
Ok(CompileKind::Target(CompileTarget::new(host_triple)?))
96+
} else {
97+
Ok(CompileKind::Target(CompileTarget::new(value.as_str())?))
98+
}
99+
})
90100
// First collect into a set to deduplicate any `--target` passed
91101
// more than once...
92102
.collect::<CargoResult<BTreeSet<_>>>()?
93103
// ... then generate a flat list for everything else to use.
94104
.into_iter()
95-
.collect())
105+
.collect();
106+
107+
Ok(deduplicated_targets)
96108
};
97109

98110
if !targets.is_empty() {

src/cargo/util/command_prelude.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,9 @@ fn get_target_triples() -> Vec<clap_complete::CompletionCandidate> {
12571257
}
12581258
}
12591259

1260+
// Allow tab-completion for `host` as the desired target.
1261+
candidates.push(clap_complete::CompletionCandidate::new("host"));
1262+
12601263
candidates
12611264
}
12621265

0 commit comments

Comments
 (0)