Skip to content

Commit 6f56670

Browse files
committed
Abstract explicit_kinds from generate_targets
This makes the specific kinds to use for build-std available.
1 parent 1c03475 commit 6f56670

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/cargo/core/package.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ impl Package {
186186
self.targets().iter().any(|t| t.is_custom_build())
187187
}
188188

189+
/// Returns explicit kinds either forced by `forced-target` in `Cargo.toml`,
190+
/// fallback to `default-target`, or specified in cli parameters.
191+
pub fn explicit_kinds(&self, requested_kinds: &[CompileKind], explicit_host_kind: CompileKind) -> Vec<CompileKind> {
192+
if let Some(k) = self.manifest().forced_kind() {
193+
vec![k]
194+
} else {
195+
requested_kinds
196+
.iter()
197+
.map(|kind| match kind {
198+
CompileKind::Host => {
199+
self.manifest().default_kind().unwrap_or(explicit_host_kind)
200+
}
201+
CompileKind::Target(t) => CompileKind::Target(*t),
202+
})
203+
.collect()
204+
}
205+
}
206+
189207
pub fn map_source(self, to_replace: SourceId, replace_with: SourceId) -> Package {
190208
Package {
191209
inner: Rc::new(PackageInner {

src/cargo/ops/cargo_compile.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,7 @@ fn generate_targets(
10651065
// why this is done. However, if the package has its own
10661066
// `package.target` key, then this gets used instead of
10671067
// `$HOST`
1068-
let explicit_kinds = if let Some(k) = pkg.manifest().forced_kind() {
1069-
vec![k]
1070-
} else {
1071-
requested_kinds
1072-
.iter()
1073-
.map(|kind| match kind {
1074-
CompileKind::Host => {
1075-
pkg.manifest().default_kind().unwrap_or(explicit_host_kind)
1076-
}
1077-
CompileKind::Target(t) => CompileKind::Target(*t),
1078-
})
1079-
.collect()
1080-
};
1068+
let explicit_kinds = pkg.explicit_kinds(requested_kinds, explicit_host_kind);
10811069

10821070
for kind in explicit_kinds.iter() {
10831071
let profile = profiles.get_profile(

0 commit comments

Comments
 (0)