forked from meta-rust/meta-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002-Target-add-default-target.json-path-libdir-rust-targ.patch
109 lines (99 loc) · 4.1 KB
/
0002-Target-add-default-target.json-path-libdir-rust-targ.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
From e9d46f8cb10eec1f8ee19ed2aab385d17ec85757 Mon Sep 17 00:00:00 2001
From: Cody P Schafer <[email protected]>
Date: Tue, 18 Nov 2014 01:40:21 -0500
Subject: [PATCH 02/10] Target: add default target.json path:
$libdir/rust/targets
---
src/librustc/session/config.rs | 6 +++---
src/librustc/session/mod.rs | 8 ++++++--
src/librustc_back/target/mod.rs | 14 +++++++++++---
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index c5db7cd..2b9069f 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -38,7 +38,7 @@ use getopts;
use std::collections::HashMap;
use std::env;
use std::fmt;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use llvm;
@@ -655,8 +655,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
v
}
-pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
- let target = match Target::search(&opts.target_triple) {
+pub fn build_target_config(sysroot: &Path, opts: &Options, sp: &SpanHandler) -> Config {
+ let target = match Target::search(sysroot, &opts.target_triple[..]) {
Ok(t) => t,
Err(e) => {
sp.handler().fatal(&format!("Error loading target specification: {}", e));
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 99a58f0..d25e476 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -385,14 +385,18 @@ pub fn build_session_(sopts: config::Options,
local_crate_source_file: Option<PathBuf>,
span_diagnostic: diagnostic::SpanHandler)
-> Session {
- let host = match Target::search(config::host_triple()) {
+ let sysroot = match sopts.maybe_sysroot {
+ Some(ref x) => PathBuf::from(x),
+ None => filesearch::get_or_default_sysroot()
+ };
+ let host = match Target::search(&sysroot, config::host_triple()) {
Ok(t) => t,
Err(e) => {
span_diagnostic.handler()
.fatal(&format!("Error loading host specification: {}", e));
}
};
- let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
+ let target_cfg = config::build_target_config(&sysroot, &sopts, &span_diagnostic);
let p_s = parse::ParseSess::with_span_handler(span_diagnostic);
let default_sysroot = match sopts.maybe_sysroot {
Some(_) => None,
diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs
index ce05a88..1d1ff70 100644
--- a/src/librustc_back/target/mod.rs
+++ b/src/librustc_back/target/mod.rs
@@ -49,6 +49,8 @@ use serialize::json::Json;
use std::default::Default;
use std::io::prelude::*;
use syntax::{diagnostic, abi};
+use std::borrow::ToOwned;
+use std::path::Path;
mod android_base;
mod apple_base;
@@ -320,12 +322,13 @@ impl Target {
///
/// The error string could come from any of the APIs called, including
/// filesystem access and JSON decoding.
- pub fn search(target: &str) -> Result<Target, String> {
+ pub fn search(sysroot: &Path, target: &str) -> Result<Target, String> {
use std::env;
use std::ffi::OsString;
use std::fs::File;
use std::path::{Path, PathBuf};
use serialize::json;
+ use std::iter::IntoIterator;
fn load_file(path: &Path) -> Result<Target, String> {
let mut f = try!(File::open(path).map_err(|e| e.to_string()));
@@ -417,9 +420,14 @@ impl Target {
let target_path = env::var_os("RUST_TARGET_PATH")
.unwrap_or(OsString::new());
- // FIXME 16351: add a sane default search path?
+ let mut default_path = sysroot.to_owned();
+ default_path.push(env!("CFG_LIBDIR_RELATIVE"));
+ default_path.push("rustlib");
- for dir in env::split_paths(&target_path) {
+ let paths = env::split_paths(&target_path)
+ .chain(Some(default_path).into_iter());
+
+ for dir in paths {
let p = dir.join(&path);
if p.is_file() {
return load_file(&p);
--
2.5.1