Skip to content

Commit

Permalink
librustc_back: filter targets for only valid ones
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jcreekmore authored and cardoe committed Jul 27, 2016
1 parent bd194a7 commit 54c61ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/librustc_back/target/mod.rs
Expand Up @@ -71,7 +71,7 @@ macro_rules! supported_targets {
$(mod $module;)*

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

fn load_specific(target: &str) -> TargetResult {
match target {
Expand All @@ -91,6 +91,14 @@ macro_rules! supported_targets {
}
}

pub fn get_targets() -> Box<Iterator<Item=String>> {
Box::new(TARGETS.iter().filter_map(|t| -> Option<String> {
load_specific(t)
.map(|t| t.llvm_target)
.ok()
}))
}

#[cfg(test)]
mod test_json_encode_decode {
use serialize::json::ToJson;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Expand Up @@ -609,7 +609,7 @@ impl RustcDefaultCalls {
for req in &sess.opts.prints {
match *req {
PrintRequest::TargetList => {
let mut targets = rustc_back::target::TARGETS.to_vec();
let mut targets = rustc_back::target::get_targets().collect::<Vec<String>>();
targets.sort();
println!("{}", targets.join("\n"));
},
Expand Down

0 comments on commit 54c61ff

Please sign in to comment.