Skip to content

Commit 54c61ff

Browse files
jcreekmorecardoe
authored andcommitted
librustc_back: filter targets for only valid ones
Since we can know which targets are instantiable on a particular host, it does not make sense to list invalid targets in the target print code. Filter the list of targets to only include the targets that can be instantiated.
1 parent bd194a7 commit 54c61ff

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/librustc_back/target/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ macro_rules! supported_targets {
7171
$(mod $module;)*
7272

7373
/// List of supported targets
74-
pub const TARGETS: &'static [&'static str] = &[$($triple),*];
74+
const TARGETS: &'static [&'static str] = &[$($triple),*];
7575

7676
fn load_specific(target: &str) -> TargetResult {
7777
match target {
@@ -91,6 +91,14 @@ macro_rules! supported_targets {
9191
}
9292
}
9393

94+
pub fn get_targets() -> Box<Iterator<Item=String>> {
95+
Box::new(TARGETS.iter().filter_map(|t| -> Option<String> {
96+
load_specific(t)
97+
.map(|t| t.llvm_target)
98+
.ok()
99+
}))
100+
}
101+
94102
#[cfg(test)]
95103
mod test_json_encode_decode {
96104
use serialize::json::ToJson;

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl RustcDefaultCalls {
609609
for req in &sess.opts.prints {
610610
match *req {
611611
PrintRequest::TargetList => {
612-
let mut targets = rustc_back::target::TARGETS.to_vec();
612+
let mut targets = rustc_back::target::get_targets().collect::<Vec<String>>();
613613
targets.sort();
614614
println!("{}", targets.join("\n"));
615615
},

0 commit comments

Comments
 (0)