|
1 | 1 | use crate::core::Target;
|
2 |
| -use crate::util::config::BuildTargetConfigValue; |
3 | 2 | use crate::util::errors::CargoResult;
|
4 | 3 | use crate::util::interning::InternedString;
|
5 | 4 | use crate::util::{Config, StableHasher};
|
@@ -53,48 +52,31 @@ impl CompileKind {
|
53 | 52 | config: &Config,
|
54 | 53 | targets: &[String],
|
55 | 54 | ) -> CargoResult<Vec<CompileKind>> {
|
56 |
| - if targets.len() > 1 && !config.cli_unstable().multitarget { |
57 |
| - bail!("specifying multiple `--target` flags requires `-Zmultitarget`") |
58 |
| - } |
59 |
| - if !targets.is_empty() { |
60 |
| - return Ok(targets |
| 55 | + let dedup = |targets: &[String]| { |
| 56 | + Ok(targets |
61 | 57 | .iter()
|
62 | 58 | .map(|value| Ok(CompileKind::Target(CompileTarget::new(value)?)))
|
63 | 59 | // First collect into a set to deduplicate any `--target` passed
|
64 | 60 | // more than once...
|
65 | 61 | .collect::<CargoResult<BTreeSet<_>>>()?
|
66 | 62 | // ... then generate a flat list for everything else to use.
|
67 | 63 | .into_iter()
|
68 |
| - .collect()); |
| 64 | + .collect()) |
| 65 | + }; |
| 66 | + |
| 67 | + if !targets.is_empty() { |
| 68 | + if targets.len() > 1 && !config.cli_unstable().multitarget { |
| 69 | + bail!("specifying multiple `--target` flags requires `-Zmultitarget`") |
| 70 | + } |
| 71 | + return dedup(targets); |
69 | 72 | }
|
70 | 73 |
|
71 | 74 | let kinds = match &config.build_config()?.target {
|
72 |
| - None => vec![CompileKind::Host], |
73 |
| - Some(build_target_config) => { |
74 |
| - let values = build_target_config.values(config); |
75 |
| - if values.len() > 1 && !config.cli_unstable().multitarget { |
76 |
| - bail!("specifying multiple `--target` flags requires `-Zmultitarget`") |
77 |
| - } |
78 |
| - values |
79 |
| - .into_iter() |
80 |
| - .map(|k| { |
81 |
| - use BuildTargetConfigValue::*; |
82 |
| - let value = match &k { |
83 |
| - Path(p) => p.to_str().expect("must be utf-8 in toml"), |
84 |
| - Simple(s) => s, |
85 |
| - }; |
86 |
| - CompileTarget::new(value).map(CompileKind::Target) |
87 |
| - }) |
88 |
| - // First collect into a set to deduplicate any `--target` passed |
89 |
| - // more than once... |
90 |
| - .collect::<CargoResult<BTreeSet<_>>>()? |
91 |
| - // ... then generate a flat list for everything else to use. |
92 |
| - .into_iter() |
93 |
| - .collect() |
94 |
| - } |
| 75 | + None => Ok(vec![CompileKind::Host]), |
| 76 | + Some(build_target_config) => dedup(&build_target_config.values(config)?), |
95 | 77 | };
|
96 | 78 |
|
97 |
| - Ok(kinds) |
| 79 | + kinds |
98 | 80 | }
|
99 | 81 |
|
100 | 82 | /// Hash used for fingerprinting.
|
|
0 commit comments