Skip to content

Commit c356537

Browse files
authored
Auto merge of #37424 - shiver:issue-37131, r=alexcrichton
Improved error reporting when target sysroot is missing. Attempts to resolve #37131. This is my first pull request on rust, so I would greatly appreciate any feedback you have on this. Thanks!
2 parents 89386d6 + 66de87f commit c356537

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/librustc_metadata/locator.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ use creader::Library;
217217
use schema::{METADATA_HEADER, rustc_version};
218218

219219
use rustc::hir::svh::Svh;
220-
use rustc::session::Session;
220+
use rustc::session::{config, Session};
221221
use rustc::session::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
222222
use rustc::session::search_paths::PathKind;
223223
use rustc::util::common;
@@ -355,6 +355,11 @@ impl<'a> Context<'a> {
355355
"can't find crate for `{}`{}",
356356
self.ident,
357357
add);
358+
359+
if (self.ident == "std" || self.ident == "core")
360+
&& self.triple != config::host_triple() {
361+
err.note(&format!("the `{}` target may not be installed", self.triple));
362+
}
358363
err.span_label(self.span, &format!("can't find crate"));
359364
err
360365
};

src/test/compile-fail/issue-37131.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that compiling for a target which is not installed will result in a helpful
12+
// error message.
13+
14+
// compile-flags: --target=s390x-unknown-linux-gnu
15+
// ignore s390x
16+
17+
// error-pattern:target may not be installed
18+
fn main() { }

src/tools/compiletest/src/runtest.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,18 @@ actual:\n\
13341334
// FIXME (#9639): This needs to handle non-utf8 paths
13351335
let mut args = vec![input_file.to_str().unwrap().to_owned(),
13361336
"-L".to_owned(),
1337-
self.config.build_base.to_str().unwrap().to_owned(),
1338-
format!("--target={}", target)];
1337+
self.config.build_base.to_str().unwrap().to_owned()];
1338+
1339+
// Optionally prevent default --target if specified in test compile-flags.
1340+
let custom_target = self.props.compile_flags
1341+
.iter()
1342+
.fold(false, |acc, ref x| acc || x.starts_with("--target"));
1343+
1344+
if !custom_target {
1345+
args.extend(vec![
1346+
format!("--target={}", target),
1347+
]);
1348+
}
13391349

13401350
if let Some(revision) = self.revision {
13411351
args.extend(vec![

0 commit comments

Comments
 (0)