a8cd882676
Signed-off-by: Derek Straka <derek@asterius.io>
108 lines
4.0 KiB
Diff
108 lines
4.0 KiB
Diff
From 3237afb78f960c015025186166f1c0998c00c6a6 Mon Sep 17 00:00:00 2001
|
|
From: Cody P Schafer <dev@codyps.com>
|
|
Date: Tue, 18 Nov 2014 01:40:21 -0500
|
|
Subject: [PATCH 2/9] 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 | 13 +++++++++++--
|
|
3 files changed, 20 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
|
|
index c4697eb..4cc059b 100644
|
|
--- a/src/librustc/session/config.rs
|
|
+++ b/src/librustc/session/config.rs
|
|
@@ -35,7 +35,7 @@ use getopts;
|
|
use std::collections::HashMap;
|
|
use std::env;
|
|
use std::fmt;
|
|
-use std::path::PathBuf;
|
|
+use std::path::{Path, PathBuf};
|
|
|
|
use llvm;
|
|
|
|
@@ -711,8 +711,8 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
|
v
|
|
}
|
|
|
|
-pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
|
- let target = match Target::search(&opts.target_triple) {
|
|
+pub fn build_target_config(sysroot: &Path, opts: &Options, sp: &Handler) -> Config {
|
|
+ let target = match Target::search(sysroot, &opts.target_triple[..]) {
|
|
Ok(t) => t,
|
|
Err(e) => {
|
|
panic!(sp.fatal(&format!("Error loading target specification: {}", e)));
|
|
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
|
|
index 2f3af1c..6424cff 100644
|
|
--- a/src/librustc/session/mod.rs
|
|
+++ b/src/librustc/session/mod.rs
|
|
@@ -429,13 +429,17 @@ pub fn build_session_(sopts: config::Options,
|
|
codemap: Rc<codemap::CodeMap>,
|
|
cstore: Rc<for<'a> CrateStore<'a>>)
|
|
-> 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) => {
|
|
panic!(span_diagnostic.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, codemap);
|
|
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 5114910..636a1aa 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::abi;
|
|
+use std::borrow::ToOwned;
|
|
+use std::path::Path;
|
|
|
|
mod android_base;
|
|
mod apple_base;
|
|
@@ -366,12 +368,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()));
|
|
@@ -470,8 +473,14 @@ impl Target {
|
|
.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.4.10
|
|
|