Skip to content

Commit 2e2372c

Browse files
committed
auto merge of #20788 : Zoxc/rust/loader, r=huonw
Fixes #19907
2 parents 20bce44 + 9dea210 commit 2e2372c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/librustc/metadata/creader.rs

+3
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ impl<'a> CrateReader<'a> {
409409
crate_name: name,
410410
hash: hash.map(|a| &*a),
411411
filesearch: self.sess.target_filesearch(kind),
412+
target: &self.sess.target.target,
412413
triple: &self.sess.opts.target_triple[],
413414
root: root,
414415
rejected_via_hash: vec!(),
@@ -472,6 +473,7 @@ impl<'a> CrateReader<'a> {
472473
crate_name: &name[],
473474
hash: None,
474475
filesearch: self.sess.host_filesearch(PathKind::Crate),
476+
target: &self.sess.host,
475477
triple: config::host_triple(),
476478
root: &None,
477479
rejected_via_hash: vec!(),
@@ -486,6 +488,7 @@ impl<'a> CrateReader<'a> {
486488
target_only = true;
487489
should_link = info.should_link;
488490

491+
load_ctxt.target = &self.sess.target.target;
489492
load_ctxt.triple = target_triple;
490493
load_ctxt.filesearch = self.sess.target_filesearch(PathKind::Crate);
491494
load_ctxt.load_library_crate()

src/librustc/metadata/loader.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
225225
use syntax::codemap::Span;
226226
use syntax::diagnostic::SpanHandler;
227227
use util::fs;
228+
use rustc_back::target::Target;
228229

229230
use std::ffi::CString;
230231
use std::cmp;
@@ -248,6 +249,8 @@ pub struct Context<'a> {
248249
pub ident: &'a str,
249250
pub crate_name: &'a str,
250251
pub hash: Option<&'a Svh>,
252+
// points to either self.sess.target.target or self.sess.host, must match triple
253+
pub target: &'a Target,
251254
pub triple: &'a str,
252255
pub filesearch: FileSearch<'a>,
253256
pub root: &'a Option<CratePaths>,
@@ -499,7 +502,7 @@ impl<'a> Context<'a> {
499502

500503
for lib in m.into_iter() {
501504
info!("{} reading metadata from: {}", flavor, lib.display());
502-
let metadata = match get_metadata_section(self.sess.target.target.options.is_like_osx,
505+
let metadata = match get_metadata_section(self.target.options.is_like_osx,
503506
&lib) {
504507
Ok(blob) => {
505508
if self.crate_matches(blob.as_slice(), &lib) {
@@ -588,7 +591,7 @@ impl<'a> Context<'a> {
588591
// Returns the corresponding (prefix, suffix) that files need to have for
589592
// dynamic libraries
590593
fn dylibname(&self) -> (String, String) {
591-
let t = &self.sess.target.target;
594+
let t = &self.target;
592595
(t.options.dll_prefix.clone(), t.options.dll_suffix.clone())
593596
}
594597

src/librustc/session/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use syntax::parse::token;
2525
use syntax::parse::ParseSess;
2626
use syntax::{ast, codemap};
2727

28+
use rustc_back::target::Target;
29+
2830
use std::os;
2931
use std::cell::{Cell, RefCell};
3032

@@ -35,6 +37,7 @@ pub mod search_paths;
3537
// session for a single crate.
3638
pub struct Session {
3739
pub target: config::Config,
40+
pub host: Target,
3841
pub opts: config::Options,
3942
pub cstore: CStore,
4043
pub parse_sess: ParseSess,
@@ -243,6 +246,13 @@ pub fn build_session_(sopts: config::Options,
243246
local_crate_source_file: Option<Path>,
244247
span_diagnostic: diagnostic::SpanHandler)
245248
-> Session {
249+
let host = match Target::search(config::host_triple()) {
250+
Ok(t) => t,
251+
Err(e) => {
252+
span_diagnostic.handler()
253+
.fatal((format!("Error loading host specification: {}", e)).as_slice());
254+
}
255+
};
246256
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
247257
let p_s = parse::new_parse_sess_special_handler(span_diagnostic);
248258
let default_sysroot = match sopts.maybe_sysroot {
@@ -268,6 +278,7 @@ pub fn build_session_(sopts: config::Options,
268278

269279
let sess = Session {
270280
target: target_cfg,
281+
host: host,
271282
opts: sopts,
272283
cstore: CStore::new(token::get_ident_interner()),
273284
parse_sess: p_s,

0 commit comments

Comments
 (0)