2014-12-12 23:39:27 +00:00
|
|
|
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
2014-07-23 18:56:36 +00:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! [Flexible target specification.](https://github.com/rust-lang/rfcs/pull/131)
|
|
|
|
//!
|
|
|
|
//! Rust targets a wide variety of usecases, and in the interest of flexibility,
|
|
|
|
//! allows new target triples to be defined in configuration files. Most users
|
|
|
|
//! will not need to care about these, but this is invaluable when porting Rust
|
|
|
|
//! to a new platform, and allows for an unprecedented level of control over how
|
|
|
|
//! the compiler works.
|
|
|
|
//!
|
|
|
|
//! # Using custom targets
|
|
|
|
//!
|
|
|
|
//! A target triple, as passed via `rustc --target=TRIPLE`, will first be
|
|
|
|
//! compared against the list of built-in targets. This is to ease distributing
|
|
|
|
//! rustc (no need for configuration files) and also to hold these built-in
|
|
|
|
//! targets as immutable and sacred. If `TRIPLE` is not one of the built-in
|
|
|
|
//! targets, rustc will check if a file named `TRIPLE` exists. If it does, it
|
|
|
|
//! will be loaded as the target configuration. If the file does not exist,
|
|
|
|
//! rustc will search each directory in the environment variable
|
|
|
|
//! `RUST_TARGET_PATH` for a file named `TRIPLE.json`. The first one found will
|
|
|
|
//! be loaded. If no file is found in any of those directories, a fatal error
|
|
|
|
//! will be given. `RUST_TARGET_PATH` includes `/etc/rustc` as its last entry,
|
|
|
|
//! to be searched by default.
|
|
|
|
//!
|
|
|
|
//! Projects defining their own targets should use
|
|
|
|
//! `--target=path/to/my-awesome-platform.json` instead of adding to
|
|
|
|
//! `RUST_TARGET_PATH`.
|
|
|
|
//!
|
|
|
|
//! # Defining a new target
|
|
|
|
//!
|
|
|
|
//! Targets are defined using [JSON](http://json.org/). The `Target` struct in
|
|
|
|
//! this module defines the format the JSON file should take, though each
|
|
|
|
//! underscore in the field names should be replaced with a hyphen (`-`) in the
|
|
|
|
//! JSON file. Some fields are required in every target specification, such as
|
2015-02-11 19:53:31 +00:00
|
|
|
//! `data-layout`, `llvm-target`, `target-endian`, `target-pointer-width`, and
|
2014-07-23 18:56:36 +00:00
|
|
|
//! `arch`. In general, options passed to rustc with `-C` override the target's
|
|
|
|
//! settings, though `target-feature` and `link-args` will *add* to the list
|
|
|
|
//! specified by the target, rather than replace.
|
|
|
|
|
|
|
|
use serialize::json::Json;
|
|
|
|
use std::default::Default;
|
2015-02-27 05:00:43 +00:00
|
|
|
use std::io::prelude::*;
|
2015-04-29 17:53:01 +00:00
|
|
|
use syntax::{diagnostic, abi};
|
2014-07-23 18:56:36 +00:00
|
|
|
|
2015-04-29 17:53:01 +00:00
|
|
|
mod android_base;
|
2014-07-23 18:56:36 +00:00
|
|
|
mod apple_base;
|
2015-01-08 08:19:52 +00:00
|
|
|
mod apple_ios_base;
|
2015-01-17 07:51:04 +00:00
|
|
|
mod bitrig_base;
|
2015-04-29 17:53:01 +00:00
|
|
|
mod dragonfly_base;
|
|
|
|
mod freebsd_base;
|
|
|
|
mod linux_base;
|
2015-01-29 07:19:28 +00:00
|
|
|
mod openbsd_base;
|
2015-04-29 17:53:01 +00:00
|
|
|
mod windows_base;
|
2015-05-08 21:44:17 +00:00
|
|
|
mod windows_msvc_base;
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
/// Everything `rustc` knows about how to compile for a specific target.
|
|
|
|
///
|
|
|
|
/// Every field here must be specified, and has no default value.
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2014-07-23 18:56:36 +00:00
|
|
|
pub struct Target {
|
|
|
|
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
|
|
|
|
pub data_layout: String,
|
|
|
|
/// Target triple to pass to LLVM.
|
|
|
|
pub llvm_target: String,
|
|
|
|
/// String to use as the `target_endian` `cfg` variable.
|
|
|
|
pub target_endian: String,
|
2015-01-07 04:26:55 +00:00
|
|
|
/// String to use as the `target_pointer_width` `cfg` variable.
|
|
|
|
pub target_pointer_width: String,
|
2014-07-23 18:56:36 +00:00
|
|
|
/// OS name to use for conditional compilation.
|
|
|
|
pub target_os: String,
|
2015-04-21 22:53:32 +00:00
|
|
|
/// Environment name to use for conditional compilation.
|
|
|
|
pub target_env: String,
|
2014-12-12 23:39:27 +00:00
|
|
|
/// Architecture to use for ABI considerations. Valid options: "x86", "x86_64", "arm",
|
2015-01-10 04:00:29 +00:00
|
|
|
/// "aarch64", "mips", and "powerpc". "mips" includes "mipsel".
|
2014-07-23 18:56:36 +00:00
|
|
|
pub arch: String,
|
|
|
|
/// Optional settings with defaults.
|
|
|
|
pub options: TargetOptions,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Optional aspects of a target specification.
|
|
|
|
///
|
|
|
|
/// This has an implementation of `Default`, see each field for what the default is. In general,
|
|
|
|
/// these try to take "minimal defaults" that don't assume anything about the runtime they run in.
|
2015-01-28 13:34:18 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2014-07-23 18:56:36 +00:00
|
|
|
pub struct TargetOptions {
|
|
|
|
/// Linker to invoke. Defaults to "cc".
|
|
|
|
pub linker: String,
|
2015-05-11 21:41:27 +00:00
|
|
|
/// Archive utility to use when managing archives. Defaults to "ar".
|
|
|
|
pub ar: String,
|
2015-04-22 01:00:16 +00:00
|
|
|
/// Linker arguments that are unconditionally passed *before* any
|
|
|
|
/// user-defined libraries.
|
2014-07-23 18:56:36 +00:00
|
|
|
pub pre_link_args: Vec<String>,
|
2015-04-22 01:00:16 +00:00
|
|
|
/// Linker arguments that are unconditionally passed *after* any
|
|
|
|
/// user-defined libraries.
|
2014-07-23 18:56:36 +00:00
|
|
|
pub post_link_args: Vec<String>,
|
2015-04-22 01:00:16 +00:00
|
|
|
/// Objects to link before and after all others, always found within the
|
|
|
|
/// sysroot folder.
|
|
|
|
pub pre_link_objects: Vec<String>,
|
|
|
|
pub post_link_objects: Vec<String>,
|
|
|
|
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
|
|
|
|
/// to "default".
|
2014-07-23 18:56:36 +00:00
|
|
|
pub cpu: String,
|
2015-04-22 01:00:16 +00:00
|
|
|
/// Default target features to pass to LLVM. These features will *always* be
|
|
|
|
/// passed, and cannot be disabled even via `-C`. Corresponds to `llc
|
|
|
|
/// -mattr=$features`.
|
2014-07-23 18:56:36 +00:00
|
|
|
pub features: String,
|
|
|
|
/// Whether dynamic linking is available on this target. Defaults to false.
|
|
|
|
pub dynamic_linking: bool,
|
|
|
|
/// Whether executables are available on this target. iOS, for example, only allows static
|
|
|
|
/// libraries. Defaults to false.
|
|
|
|
pub executables: bool,
|
|
|
|
/// Whether LLVM's segmented stack prelude is supported by whatever runtime is available.
|
|
|
|
/// Will emit stack checks and calls to __morestack. Defaults to false.
|
|
|
|
pub morestack: bool,
|
|
|
|
/// Relocation model to use in object file. Corresponds to `llc
|
|
|
|
/// -relocation-model=$relocation_model`. Defaults to "pic".
|
|
|
|
pub relocation_model: String,
|
|
|
|
/// Code model to use. Corresponds to `llc -code-model=$code_model`. Defaults to "default".
|
|
|
|
pub code_model: String,
|
|
|
|
/// Do not emit code that uses the "red zone", if the ABI has one. Defaults to false.
|
|
|
|
pub disable_redzone: bool,
|
|
|
|
/// Eliminate frame pointers from stack frames if possible. Defaults to true.
|
|
|
|
pub eliminate_frame_pointer: bool,
|
|
|
|
/// Emit each function in its own section. Defaults to true.
|
|
|
|
pub function_sections: bool,
|
|
|
|
/// String to prepend to the name of every dynamic library. Defaults to "lib".
|
|
|
|
pub dll_prefix: String,
|
|
|
|
/// String to append to the name of every dynamic library. Defaults to ".so".
|
|
|
|
pub dll_suffix: String,
|
|
|
|
/// String to append to the name of every executable.
|
|
|
|
pub exe_suffix: String,
|
|
|
|
/// String to prepend to the name of every static library. Defaults to "lib".
|
|
|
|
pub staticlib_prefix: String,
|
|
|
|
/// String to append to the name of every static library. Defaults to ".a".
|
|
|
|
pub staticlib_suffix: String,
|
|
|
|
/// Whether the target toolchain is like OSX's. Only useful for compiling against iOS/OS X, in
|
|
|
|
/// particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
|
|
|
|
pub is_like_osx: bool,
|
|
|
|
/// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
|
2015-03-28 15:09:51 +00:00
|
|
|
/// only really used for figuring out how to find libraries, since Windows uses its own
|
2014-07-23 18:56:36 +00:00
|
|
|
/// library naming convention. Defaults to false.
|
|
|
|
pub is_like_windows: bool,
|
2015-03-04 22:58:59 +00:00
|
|
|
pub is_like_msvc: bool,
|
2015-02-16 08:48:50 +00:00
|
|
|
/// Whether the target toolchain is like Android's. Only useful for compiling against Android.
|
|
|
|
/// Defaults to false.
|
|
|
|
pub is_like_android: bool,
|
2014-07-23 18:56:36 +00:00
|
|
|
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
|
|
|
|
pub linker_is_gnu: bool,
|
|
|
|
/// Whether the linker support rpaths or not. Defaults to false.
|
|
|
|
pub has_rpath: bool,
|
2015-05-11 21:41:27 +00:00
|
|
|
/// Whether to disable linking to compiler-rt. Defaults to false, as LLVM
|
|
|
|
/// will emit references to the functions that compiler-rt provides.
|
2014-07-23 18:56:36 +00:00
|
|
|
pub no_compiler_rt: bool,
|
2015-05-11 21:41:27 +00:00
|
|
|
/// Dynamically linked executables can be compiled as position independent
|
|
|
|
/// if the default relocation model of position independent code is not
|
|
|
|
/// changed. This is a requirement to take advantage of ASLR, as otherwise
|
|
|
|
/// the functions in the executable are not randomized and can be used
|
|
|
|
/// during an exploit of a vulnerability in any code.
|
2014-11-06 05:17:56 +00:00
|
|
|
pub position_independent_executables: bool,
|
2014-07-23 18:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TargetOptions {
|
2015-05-11 21:41:27 +00:00
|
|
|
/// Create a set of "sane defaults" for any target. This is still
|
|
|
|
/// incomplete, and if used for compilation, will certainly not work.
|
2014-07-23 18:56:36 +00:00
|
|
|
fn default() -> TargetOptions {
|
|
|
|
TargetOptions {
|
|
|
|
linker: "cc".to_string(),
|
2015-05-11 21:41:27 +00:00
|
|
|
ar: "ar".to_string(),
|
2014-07-23 18:56:36 +00:00
|
|
|
pre_link_args: Vec::new(),
|
|
|
|
post_link_args: Vec::new(),
|
|
|
|
cpu: "generic".to_string(),
|
|
|
|
features: "".to_string(),
|
|
|
|
dynamic_linking: false,
|
|
|
|
executables: false,
|
|
|
|
morestack: false,
|
|
|
|
relocation_model: "pic".to_string(),
|
|
|
|
code_model: "default".to_string(),
|
|
|
|
disable_redzone: false,
|
|
|
|
eliminate_frame_pointer: true,
|
|
|
|
function_sections: true,
|
|
|
|
dll_prefix: "lib".to_string(),
|
|
|
|
dll_suffix: ".so".to_string(),
|
|
|
|
exe_suffix: "".to_string(),
|
|
|
|
staticlib_prefix: "lib".to_string(),
|
|
|
|
staticlib_suffix: ".a".to_string(),
|
|
|
|
is_like_osx: false,
|
|
|
|
is_like_windows: false,
|
2015-02-16 08:48:50 +00:00
|
|
|
is_like_android: false,
|
2015-03-04 22:58:59 +00:00
|
|
|
is_like_msvc: false,
|
2014-07-23 18:56:36 +00:00
|
|
|
linker_is_gnu: false,
|
|
|
|
has_rpath: false,
|
|
|
|
no_compiler_rt: false,
|
2014-11-06 05:17:56 +00:00
|
|
|
position_independent_executables: false,
|
2015-04-22 01:00:16 +00:00
|
|
|
pre_link_objects: Vec::new(),
|
|
|
|
post_link_objects: Vec::new(),
|
2014-07-23 18:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Target {
|
|
|
|
/// Given a function ABI, turn "System" into the correct ABI for this target.
|
|
|
|
pub fn adjust_abi(&self, abi: abi::Abi) -> abi::Abi {
|
|
|
|
match abi {
|
|
|
|
abi::System => {
|
2014-11-27 18:57:31 +00:00
|
|
|
if self.options.is_like_windows && self.arch == "x86" {
|
2014-07-23 18:56:36 +00:00
|
|
|
abi::Stdcall
|
|
|
|
} else {
|
|
|
|
abi::C
|
|
|
|
}
|
|
|
|
},
|
|
|
|
abi => abi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Load a target descriptor from a JSON object.
|
|
|
|
pub fn from_json(obj: Json) -> Target {
|
|
|
|
// this is 1. ugly, 2. error prone.
|
|
|
|
|
|
|
|
|
2015-05-13 20:00:17 +00:00
|
|
|
let handler = diagnostic::Handler::new(diagnostic::Auto, None, true);
|
2014-07-23 18:56:36 +00:00
|
|
|
|
2015-02-01 17:44:15 +00:00
|
|
|
let get_req_field = |name: &str| {
|
2014-11-04 10:35:53 +00:00
|
|
|
match obj.find(name)
|
2014-07-23 18:56:36 +00:00
|
|
|
.map(|s| s.as_string())
|
|
|
|
.and_then(|os| os.map(|s| s.to_string())) {
|
|
|
|
Some(val) => val,
|
|
|
|
None =>
|
2015-02-20 19:08:14 +00:00
|
|
|
handler.fatal(&format!("Field {} in target specification is required", name))
|
2014-07-23 18:56:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut base = Target {
|
|
|
|
data_layout: get_req_field("data-layout"),
|
|
|
|
llvm_target: get_req_field("llvm-target"),
|
|
|
|
target_endian: get_req_field("target-endian"),
|
2015-02-11 19:53:31 +00:00
|
|
|
target_pointer_width: get_req_field("target-pointer-width"),
|
2014-07-23 18:56:36 +00:00
|
|
|
arch: get_req_field("arch"),
|
|
|
|
target_os: get_req_field("os"),
|
2015-04-21 22:53:32 +00:00
|
|
|
target_env: obj.find("env").and_then(|s| s.as_string())
|
|
|
|
.map(|s| s.to_string()).unwrap_or(String::new()),
|
2014-07-23 18:56:36 +00:00
|
|
|
options: Default::default(),
|
|
|
|
};
|
|
|
|
|
2015-01-02 22:44:21 +00:00
|
|
|
macro_rules! key {
|
2014-07-23 18:56:36 +00:00
|
|
|
($key_name:ident) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2015-02-18 19:48:57 +00:00
|
|
|
obj.find(&name[..]).map(|o| o.as_string()
|
2014-07-23 18:56:36 +00:00
|
|
|
.map(|s| base.options.$key_name = s.to_string()));
|
|
|
|
} );
|
|
|
|
($key_name:ident, bool) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2015-02-18 19:48:57 +00:00
|
|
|
obj.find(&name[..])
|
2015-01-04 04:43:24 +00:00
|
|
|
.map(|o| o.as_boolean()
|
|
|
|
.map(|s| base.options.$key_name = s));
|
2014-07-23 18:56:36 +00:00
|
|
|
} );
|
|
|
|
($key_name:ident, list) => ( {
|
|
|
|
let name = (stringify!($key_name)).replace("_", "-");
|
2015-02-18 19:48:57 +00:00
|
|
|
obj.find(&name[..]).map(|o| o.as_array()
|
2014-07-23 18:56:36 +00:00
|
|
|
.map(|v| base.options.$key_name = v.iter()
|
|
|
|
.map(|a| a.as_string().unwrap().to_string()).collect()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
2015-01-02 22:44:21 +00:00
|
|
|
}
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
key!(cpu);
|
2015-06-08 13:01:32 +00:00
|
|
|
key!(ar);
|
2014-07-23 18:56:36 +00:00
|
|
|
key!(linker);
|
|
|
|
key!(relocation_model);
|
|
|
|
key!(code_model);
|
|
|
|
key!(dll_prefix);
|
|
|
|
key!(dll_suffix);
|
|
|
|
key!(exe_suffix);
|
|
|
|
key!(staticlib_prefix);
|
|
|
|
key!(staticlib_suffix);
|
|
|
|
key!(features);
|
|
|
|
key!(dynamic_linking, bool);
|
|
|
|
key!(executables, bool);
|
|
|
|
key!(morestack, bool);
|
|
|
|
key!(disable_redzone, bool);
|
|
|
|
key!(eliminate_frame_pointer, bool);
|
|
|
|
key!(function_sections, bool);
|
|
|
|
key!(is_like_osx, bool);
|
|
|
|
key!(is_like_windows, bool);
|
|
|
|
key!(linker_is_gnu, bool);
|
|
|
|
key!(has_rpath, bool);
|
|
|
|
key!(no_compiler_rt, bool);
|
|
|
|
key!(pre_link_args, list);
|
|
|
|
key!(post_link_args, list);
|
|
|
|
|
|
|
|
base
|
|
|
|
}
|
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
/// Search RUST_TARGET_PATH for a JSON file specifying the given target
|
|
|
|
/// triple. Note that it could also just be a bare filename already, so also
|
|
|
|
/// check for that. If one of the hardcoded targets we know about, just
|
|
|
|
/// return it directly.
|
2014-07-23 18:56:36 +00:00
|
|
|
///
|
2015-02-27 05:00:43 +00:00
|
|
|
/// The error string could come from any of the APIs called, including
|
|
|
|
/// filesystem access and JSON decoding.
|
2014-07-23 18:56:36 +00:00
|
|
|
pub fn search(target: &str) -> Result<Target, String> {
|
2015-01-27 20:20:58 +00:00
|
|
|
use std::env;
|
|
|
|
use std::ffi::OsString;
|
2015-02-27 05:00:43 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::path::{Path, PathBuf};
|
2014-07-23 18:56:36 +00:00
|
|
|
use serialize::json;
|
|
|
|
|
|
|
|
fn load_file(path: &Path) -> Result<Target, String> {
|
2015-02-27 05:00:43 +00:00
|
|
|
let mut f = try!(File::open(path).map_err(|e| e.to_string()));
|
|
|
|
let mut contents = Vec::new();
|
|
|
|
try!(f.read_to_end(&mut contents).map_err(|e| e.to_string()));
|
|
|
|
let obj = try!(json::from_reader(&mut &contents[..])
|
|
|
|
.map_err(|e| e.to_string()));
|
2014-07-23 18:56:36 +00:00
|
|
|
Ok(Target::from_json(obj))
|
|
|
|
}
|
|
|
|
|
|
|
|
// this would use a match if stringify! were allowed in pattern position
|
2015-01-02 22:44:21 +00:00
|
|
|
macro_rules! load_specific {
|
2014-07-23 18:56:36 +00:00
|
|
|
( $($name:ident),+ ) => (
|
|
|
|
{
|
2015-04-21 22:59:32 +00:00
|
|
|
$(mod $name;)*
|
2014-07-23 18:56:36 +00:00
|
|
|
let target = target.replace("-", "_");
|
|
|
|
if false { }
|
|
|
|
$(
|
|
|
|
else if target == stringify!($name) {
|
|
|
|
let t = $name::target();
|
2014-12-20 08:09:35 +00:00
|
|
|
debug!("Got builtin target: {:?}", t);
|
2014-07-23 18:56:36 +00:00
|
|
|
return Ok(t);
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
else if target == "x86_64-w64-mingw32" {
|
|
|
|
let t = x86_64_pc_windows_gnu::target();
|
|
|
|
return Ok(t);
|
|
|
|
} else if target == "i686-w64-mingw32" {
|
|
|
|
let t = i686_pc_windows_gnu::target();
|
|
|
|
return Ok(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2015-01-02 22:44:21 +00:00
|
|
|
}
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
load_specific!(
|
|
|
|
x86_64_unknown_linux_gnu,
|
|
|
|
i686_unknown_linux_gnu,
|
|
|
|
mips_unknown_linux_gnu,
|
|
|
|
mipsel_unknown_linux_gnu,
|
2015-01-10 04:00:29 +00:00
|
|
|
powerpc_unknown_linux_gnu,
|
2014-07-23 18:56:36 +00:00
|
|
|
arm_unknown_linux_gnueabi,
|
|
|
|
arm_unknown_linux_gnueabihf,
|
2014-12-12 23:39:27 +00:00
|
|
|
aarch64_unknown_linux_gnu,
|
2015-04-21 22:59:32 +00:00
|
|
|
x86_64_unknown_linux_musl,
|
2014-07-23 18:56:36 +00:00
|
|
|
|
2015-01-22 12:39:06 +00:00
|
|
|
arm_linux_androideabi,
|
|
|
|
aarch64_linux_android,
|
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
x86_64_unknown_freebsd,
|
|
|
|
|
2014-11-05 15:36:09 +00:00
|
|
|
i686_unknown_dragonfly,
|
2014-07-23 18:56:36 +00:00
|
|
|
x86_64_unknown_dragonfly,
|
|
|
|
|
2015-01-17 07:51:04 +00:00
|
|
|
x86_64_unknown_bitrig,
|
2015-01-29 07:19:28 +00:00
|
|
|
x86_64_unknown_openbsd,
|
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
x86_64_apple_darwin,
|
|
|
|
i686_apple_darwin,
|
2015-01-08 08:19:52 +00:00
|
|
|
|
2014-07-23 18:56:36 +00:00
|
|
|
i386_apple_ios,
|
2015-01-09 16:25:01 +00:00
|
|
|
x86_64_apple_ios,
|
|
|
|
aarch64_apple_ios,
|
2015-01-08 08:19:52 +00:00
|
|
|
armv7_apple_ios,
|
|
|
|
armv7s_apple_ios,
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
x86_64_pc_windows_gnu,
|
2015-03-04 22:58:59 +00:00
|
|
|
i686_pc_windows_gnu,
|
|
|
|
|
|
|
|
x86_64_pc_windows_msvc
|
2014-11-14 17:18:10 +00:00
|
|
|
);
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
let path = Path::new(target);
|
|
|
|
|
|
|
|
if path.is_file() {
|
|
|
|
return load_file(&path);
|
|
|
|
}
|
|
|
|
|
|
|
|
let path = {
|
|
|
|
let mut target = target.to_string();
|
|
|
|
target.push_str(".json");
|
2015-03-18 16:14:54 +00:00
|
|
|
PathBuf::from(target)
|
2014-07-23 18:56:36 +00:00
|
|
|
};
|
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
let target_path = env::var_os("RUST_TARGET_PATH")
|
2015-03-18 16:14:54 +00:00
|
|
|
.unwrap_or(OsString::new());
|
2014-07-23 18:56:36 +00:00
|
|
|
|
|
|
|
// FIXME 16351: add a sane default search path?
|
|
|
|
|
2015-02-27 05:00:43 +00:00
|
|
|
for dir in env::split_paths(&target_path) {
|
|
|
|
let p = dir.join(&path);
|
2014-07-23 18:56:36 +00:00
|
|
|
if p.is_file() {
|
|
|
|
return load_file(&p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-20 08:09:35 +00:00
|
|
|
Err(format!("Could not find specification for target {:?}", target))
|
2014-07-23 18:56:36 +00:00
|
|
|
}
|
|
|
|
}
|