From 7af1ef212c59ee56438fac8fb7cfdd86bd2b04ba Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Wed, 9 Apr 2014 04:36:39 -0500 Subject: [PATCH 01/18] Add std::hash::Hash to std::result::Result. --- src/libstd/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 0b6897ba2dc4f..493ff8c485fe9 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -275,7 +275,7 @@ use option::{None, Option, Some}; /// `Result` is a type that represents either success (`Ok`) or failure (`Err`). /// /// See the [`std::result`](index.html) module documentation for details. -#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show)] +#[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Show, Hash)] #[must_use] pub enum Result { /// Contains the success value From 6d1340526a6465cefe0e435e08f9ae6cf447e97c Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 18:37:09 -0500 Subject: [PATCH 02/18] Added a Triple structure to parse and manage target triples. --- src/librustc/back/triple.rs | 379 ++++++++++++++++++++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 src/librustc/back/triple.rs diff --git a/src/librustc/back/triple.rs b/src/librustc/back/triple.rs new file mode 100644 index 0000000000000..52267fdb6e5da --- /dev/null +++ b/src/librustc/back/triple.rs @@ -0,0 +1,379 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::result::{Result, Ok, Err}; +use std::from_str::FromStr; +use std::{cmp, fmt, default}; +use std::os::consts::{macos, freebsd, linux, android, win32}; +use syntax::abi; + +pub type KnownType = Result; +pub trait Known { + // Unwrap the value, or fails with a message using name. + fn expect_known<'a>(&'a self, name: &str) -> &'a T; +} +impl Known for KnownType { + fn expect_known<'a>(&'a self, name: &str) -> &'a T { + match self { + &Ok(ref v) => v, + &Err(ref v) => { + fail!("Tried to unwrap unknown value `{}`. The unknown string was `{}`.", + name, v); + } + } + } +} +pub trait ParseFromStr { + fn parse_str(s: &str) -> KnownType; +} +impl ParseFromStr for T { + fn parse_str(s: &str) -> KnownType { + let opt: Option = FromStr::from_str(s); + match opt { + Some(v) => Ok(v), + None => Err(s.to_str()), + } + } +} + +#[deriving(Hash, Clone, Eq, TotalEq)] +pub enum GnuType { + GnuDefault, + GnuEAbi, + GnuEAbiHf, + GnuX32, +} +impl FromStr for GnuType { + fn from_str(s: &str) -> Option { + match s { + "gnu" => Some(GnuDefault), + "gnueabi" => Some(GnuEAbi), + "gnueabihf" => Some(GnuEAbiHf), + "gnux32" => Some(GnuX32), + _ => None, + } + } +} + +#[deriving(Hash, Clone, Eq, TotalEq)] +pub enum Env { + GnuEnv(GnuType), + EAbiEnv, + EAbiHfEnv, + AndroidEnv, + AndroidEAbiEnv, + MsvcEnv, + // here for completeness: + ItaniumEnv, +} +impl FromStr for Env { + fn from_str(s: &str) -> Option { + let gnu_opt: Option = FromStr::from_str(s); + match gnu_opt { + Some(gnu) => Some(GnuEnv(gnu)), + None => { + match s { + "eabi" => Some(EAbiEnv), + "eabihf" => Some(EAbiHfEnv), + "android" => Some(AndroidEnv), + "androideabi" => Some(AndroidEAbiEnv), + "msvc" => Some(MsvcEnv), + "itanium" => Some(ItaniumEnv), + _ => None, + } + } + } + } +} +#[deriving(Hash, Clone, Eq, TotalEq)] +pub enum Vendor { + UnknownVendor, + PCVendor, + AppleVendor, +} +impl FromStr for Vendor { + fn from_str(s: &str) -> Option { + match s { + "unknown" => Some(UnknownVendor), + "pc" | "w64" => Some(PCVendor), + "apple" => Some(AppleVendor), + _ => None, + } + } +} + +#[deriving(Hash, Clone, TotalEq)] +pub struct Triple { + pub full: ~str, + + pub arch: abi::Architecture, + pub os: KnownType, + pub vendor: Option>, + pub env: Option>, +} +impl Triple { + pub fn host_triple() -> Triple { + // Get the host triple out of the build environment. This ensures that our + // idea of the host triple is the same as for the set of libraries we've + // actually built. We can't just take LLVM's host triple because they + // normalize all ix86 architectures to i386. + // + // Instead of grabbing the host triple (for the current host), we grab (at + // compile time) the target triple that this rustc is built with and + // calling that (at runtime) the host triple. + FromStr::from_str(env!("CFG_COMPILER_HOST_TRIPLE")).unwrap() + } + pub fn expect_known_os(&self) -> abi::Os { + self.os.expect_known("os").clone() + } + + // Returns the corresponding (prefix, suffix) that files need to have for + // dynamic libraries. Note this expects a known OS, which should all be + // fine except for the session builder (the session builder won't proceed + // if we don't have a known OS). + pub fn dylibname(&self) -> (&'static str, &'static str) { + match self.expect_known_os() { + abi::OsWin32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX), + abi::OsMacos => (macos::DLL_PREFIX, macos::DLL_SUFFIX), + abi::OsLinux => (linux::DLL_PREFIX, linux::DLL_SUFFIX), + abi::OsAndroid => (android::DLL_PREFIX, android::DLL_SUFFIX), + abi::OsFreebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX), + } + } +} + +impl FromStr for Triple { + fn from_str(s: &str) -> Option { + // we require at least an arch. + + let splits: Vec<&str> = s.split_terminator('-').collect(); + if splits.len() < 2 { + None + } else { + let splits = splits.as_slice(); + let arch = match FromStr::from_str(splits[0]) { + Some(arch) => arch, + None => return None, + }; + if splits.len() == 2 { + match splits[1] { + "mingw32msvc" => { + return Some(Triple { + full: s.to_str(), + arch: arch, + os: Ok(abi::OsWin32), + vendor: None, + env: Some(Ok(MsvcEnv)), + }); + } + os => { + return Some(Triple { + full: s.to_str(), + arch: arch, + os: ParseFromStr::parse_str(os), + vendor: None, + env: None, + }) + } + } + } else if splits.len() == 3 { + match (splits[1], splits[2]) { + ("linux", "androideabi") => { + return Some(Triple { + full: s.to_str(), + arch: arch, + os: Ok(abi::OsAndroid), + vendor: None, + env: Some(Ok(AndroidEAbiEnv)), + }) + } + _ => { + return Some(Triple { + full: s.to_str(), + arch: arch, + os: ParseFromStr::parse_str(splits[2]), + vendor: Some(ParseFromStr::parse_str(splits[1])), + env: None, + }); + } + } + } else { + Some(Triple { + full: s.to_str(), + arch: arch, + vendor: Some(ParseFromStr::parse_str(splits[1])), + os: ParseFromStr::parse_str(splits[2]), + env: Some(ParseFromStr::parse_str(splits[3])), + }) + } + } + } +} +impl default::Default for Triple { + fn default() -> Triple { + Triple::host_triple() + } +} +impl fmt::Show for Triple { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.full.fmt(f) + } +} +impl cmp::Eq for Triple { + fn eq(&self, rhs: &Triple) -> bool { + self.arch == rhs.arch && + self.os == rhs.os && + self.env == rhs.env + } +} + +#[cfg(test)] +mod test { + use super::{Triple, Known, + UnknownVendor, + GnuEnv, GnuDefault, + AndroidEAbiEnv, MsvcEnv}; + use syntax::abi; + use std::to_str::ToStr; + use std::from_str::FromStr; + use std::fmt::Show; + + #[test] + fn x86_64_unknown_linux_gnu() { + let original = "x86_64-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86_64); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i386_unknown_linux_gnu() { + let original = "i386-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i486_unknown_linux_gnu() { + let original = "i486-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i586_unknown_linux_gnu() { + let original = "i586-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i686_unknown_linux_gnu() { + let original = "i686-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i786_unknown_linux_gnu() { + let original = "i786-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] #[should_fail] + fn unknownarch_unknown_linux_gnu() { + let original = "unknownarch-unknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + } + #[test] + fn x86_64_ununknown_linux_gnu() { + // unknown vendor + let original = "x86_64-ununknown-linux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86_64); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Err(~"ununknown"))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn x86_64_unknown_notlinux_gnu() { + // unknown os + let original = "x86_64-unknown-notlinux-gnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86_64); + assert!(triple.os == Err(~"notlinux")); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Ok(GnuEnv(GnuDefault)))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn x86_64_unknown_linux_notgnu() { + // unknown os + let original = "x86_64-unknown-linux-notgnu"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86_64); + assert!(triple.os == Ok(abi::OsLinux)); + assert!(triple.vendor == Some(Ok(UnknownVendor))); + assert!(triple.env == Some(Err(~"notgnu"))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn i686_mingw32msvc() { + // Odd one, this is. + let original = "i686-mingw32msvc"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::X86); + assert!(triple.os == Ok(abi::OsWin32)); + assert!(triple.vendor == None); + assert!(triple.env == Some(Ok(MsvcEnv))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] + fn arm_linux_androideabi() { + // Another odd one, this one. Really should be arm-unknown-linux-androideabi or + // maybe arm-android-linux-eabi. + let original = "arm-linux-androideabi"; + let triple: Triple = FromStr::from_str(original).unwrap(); + assert!(triple.arch == abi::Arm); + assert!(triple.os == Ok(abi::OsAndroid)); + assert!(triple.vendor == None); + assert!(triple.env == Some(Ok(AndroidEAbiEnv))); + assert_eq!(triple.to_str(), original.to_str()); + } + #[test] #[should_fail] + fn blank() { + let original = ""; + let triple: Triple = FromStr::from_str(original).unwrap(); + } + #[test] #[should_fail] + fn blank_hyphen() { + let original = "-"; + let triple: Triple = FromStr::from_str(original).unwrap(); + } +} From e79a7809fa9576d3d027ea2f7c63a41ee6ccd325 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 19:01:25 -0500 Subject: [PATCH 03/18] Add implementations of FromStr for Os && Architecture. Additionally added some deriving types to both. --- src/libsyntax/abi.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 17251d31351ab..70657d2234abd 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -9,10 +9,25 @@ // except according to those terms. use std::fmt; +use std::from_str; -#[deriving(Eq)] +#[deriving(Eq, Hash, Clone, TotalEq)] pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, } +impl from_str::FromStr for Os { + fn from_str(s: &str) -> Option { + match s { + "mingw32" => Some(OsWin32), + "win32" => Some(OsWin32), + "darwin" => Some(OsMacos), + "android" => Some(OsAndroid), + "linux" => Some(OsLinux), + "freebsd" => Some(OsFreebsd), + _ => None, + } + } +} + #[deriving(Eq, TotalEq, Hash, Encodable, Decodable, Clone)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. @@ -33,7 +48,7 @@ pub enum Abi { } #[allow(non_camel_case_types)] -#[deriving(Eq)] +#[deriving(Eq, Clone, Hash, TotalEq)] pub enum Architecture { // NB. You cannot change the ordering of these // constants without adjusting IntelBits below. @@ -43,6 +58,18 @@ pub enum Architecture { Arm, Mips } +impl from_str::FromStr for Architecture { + fn from_str(s: &str) -> Option { + match s { + "i386" | "i486" | "i586" | "i686" | "i786" => Some(X86), + "x86_64" => Some(X86_64), + "arm" | "xscale" | "thumb" => Some(Arm), + "mips" => Some(Mips), + _ => None, + } + } +} + static IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); static ArmBits: u32 = (1 << (Arm as uint)); From ac79c44c55dfbe1e928c01e9c29afad4c6e7188a Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 19:27:19 -0500 Subject: [PATCH 04/18] Store the parse target triple in Config. Added convience functions to access the OS, arch, && the full triple. --- src/librustc/back/archive.rs | 2 +- src/librustc/back/link.rs | 39 ++++++-------- src/librustc/back/rpath.rs | 4 +- src/librustc/driver/driver.rs | 72 +++++++------------------- src/librustc/driver/session.rs | 22 ++++++-- src/librustc/lib.rs | 1 + src/librustc/metadata/creader.rs | 6 +-- src/librustc/metadata/filesearch.rs | 29 ++++++----- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/base.rs | 8 +-- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/cabi_x86.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 2 +- src/librustc/middle/trans/foreign.rs | 4 +- src/librustc/middle/trans/type_.rs | 2 +- 15 files changed, 87 insertions(+), 110 deletions(-) diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 9b795e6957cf3..b953473fa1f34 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -175,7 +175,7 @@ impl<'a> Archive<'a> { } fn find_library(&self, name: &str) -> Path { - let (osprefix, osext) = match self.sess.targ_cfg.os { + let (osprefix, osext) = match self.sess.target_os() { abi::OsWin32 => ("", "lib"), _ => ("lib", "a"), }; // On Windows, static libraries sometimes show up as libfoo.a and other diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 9ac99b267169e..d1a8bbc8f00d8 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -9,7 +9,7 @@ // except according to those terms. use back::archive::{Archive, METADATA_FILENAME}; -use back::rpath; +use back::{rpath, triple}; use back::svh::Svh; use driver::driver::{CrateTranslation, OutputFilenames}; use driver::session::{NoDebugInfo, Session}; @@ -30,7 +30,6 @@ use std::c_str::{ToCStr, CString}; use std::char; use std::io::{fs, TempDir, Process}; use std::io; -use std::os::consts::{macos, freebsd, linux, android, win32}; use std::ptr; use std::str; use std::strbuf::StrBuf; @@ -112,7 +111,7 @@ pub mod write { // cases, so if any sort of target feature is specified we don't append v7 // to the feature list. fn target_feature<'a>(sess: &'a Session) -> &'a str { - match sess.targ_cfg.os { + match sess.target_os() { abi::OsAndroid => { if "" == sess.opts.cg.target_feature { "+v7" @@ -150,8 +149,8 @@ pub mod write { // FIXME: #11906: Omitting frame pointers breaks retrieving the value of a parameter. // FIXME: #11954: mac64 unwinding may not work with fp elim let no_fp_elim = (sess.opts.debuginfo != NoDebugInfo) || - (sess.targ_cfg.os == abi::OsMacos && - sess.targ_cfg.arch == abi::X86_64); + (sess.target_os() == abi::OsMacos && + sess.target_arch() == abi::X86_64); let reloc_model = match sess.opts.cg.relocation_model.as_slice() { "pic" => lib::llvm::RelocPIC, @@ -737,7 +736,7 @@ pub fn get_cc_prog(sess: &Session) -> ~str { // It would be flexible to use cc (system's default C compiler) // instead of hard-coded gcc. // For win32, there is no cc command, so we add a condition to make it use gcc. - match sess.targ_cfg.os { + match sess.target_os() { abi::OsWin32 => return ~"gcc", _ => {}, } @@ -755,7 +754,7 @@ pub fn get_ar_prog(sess: &Session) -> ~str { } fn get_system_tool(sess: &Session, tool: &str) -> ~str { - match sess.targ_cfg.os { + match sess.target_os() { abi::OsAndroid => match sess.opts.cg.android_cross_path { Some(ref path) => { let tool_str = match tool { @@ -821,13 +820,7 @@ pub fn filename_for_input(sess: &Session, crate_type: session::CrateType, out_filename.with_filename(format!("lib{}.rlib", libname)) } session::CrateTypeDylib => { - let (prefix, suffix) = match sess.targ_cfg.os { - abi::OsWin32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX), - abi::OsMacos => (macos::DLL_PREFIX, macos::DLL_SUFFIX), - abi::OsLinux => (linux::DLL_PREFIX, linux::DLL_SUFFIX), - abi::OsAndroid => (android::DLL_PREFIX, android::DLL_SUFFIX), - abi::OsFreebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX), - }; + let (prefix, suffix) = sess.target_triple().dylibname(); out_filename.with_filename(format!("{}{}{}", prefix, libname, suffix)) } session::CrateTypeStaticlib => { @@ -973,7 +966,7 @@ fn link_rlib<'a>(sess: &'a Session, // After adding all files to the archive, we need to update the // symbol table of the archive. This currently dies on OSX (see // #11162), and isn't necessary there anyway - match sess.targ_cfg.os { + match sess.target_os() { abi::OsMacos => {} _ => { a.update_symbols(); } } @@ -1066,7 +1059,7 @@ fn link_natively(sess: &Session, dylib: bool, obj_filename: &Path, // On OSX, debuggers need this utility to get run to do some munging of // the symbols - if sess.targ_cfg.os == abi::OsMacos && (sess.opts.debuginfo != NoDebugInfo) { + if sess.target_os() == abi::OsMacos && (sess.opts.debuginfo != NoDebugInfo) { // FIXME (#9639): This needs to handle non-utf8 paths match Process::status("dsymutil", [out_filename.as_str().unwrap().to_owned()]) { @@ -1130,11 +1123,11 @@ fn link_args(sess: &Session, // subset we wanted. // // FIXME(#11937) we should invoke the system linker directly - if sess.targ_cfg.os != abi::OsWin32 { + if sess.target_os() != abi::OsWin32 { args.push(~"-nodefaultlibs"); } - if sess.targ_cfg.os == abi::OsLinux { + if sess.target_os() == abi::OsLinux { // GNU-style linkers will use this to omit linking to libraries which // don't actually fulfill any relocations, but only for libraries which // follow this flag. Thus, use it before specifying libraries to link to. @@ -1150,7 +1143,7 @@ fn link_args(sess: &Session, } } - if sess.targ_cfg.os == abi::OsWin32 { + if sess.target_os() == abi::OsWin32 { // Make sure that we link to the dynamic libgcc, otherwise cross-module // DWARF stack unwinding will not work. // This behavior may be overridden by --link-args "-static-libgcc" @@ -1184,7 +1177,7 @@ fn link_args(sess: &Session, args.push(~"-Wl,--enable-long-section-names"); } - if sess.targ_cfg.os == abi::OsAndroid { + if sess.target_os() == abi::OsAndroid { // Many of the symbols defined in compiler-rt are also defined in libgcc. // Android linker doesn't like that by default. args.push(~"-Wl,--allow-multiple-definition"); @@ -1231,7 +1224,7 @@ fn link_args(sess: &Session, if dylib { // On mac we need to tell the linker to let this library be rpathed - if sess.targ_cfg.os == abi::OsMacos { + if sess.target_os() == abi::OsMacos { args.push(~"-dynamiclib"); args.push(~"-Wl,-dylib"); // FIXME (#9639): This needs to handle non-utf8 paths @@ -1244,7 +1237,7 @@ fn link_args(sess: &Session, } } - if sess.targ_cfg.os == abi::OsFreebsd { + if sess.target_os() == abi::OsFreebsd { args.push_all([~"-L/usr/local/lib", ~"-L/usr/local/lib/gcc46", ~"-L/usr/local/lib/gcc44"]); @@ -1388,7 +1381,7 @@ fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session, // Converts a library file-stem into a cc -l argument fn unlib(config: &session::Config, stem: &str) -> ~str { - if stem.starts_with("lib") && config.os != abi::OsWin32 { + if stem.starts_with("lib") && config.os() != abi::OsWin32 { stem.slice(3, stem.len()).to_owned() } else { stem.to_owned() diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index e455c4ad23ce0..7229c27fd64b5 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -23,7 +23,7 @@ fn not_win32(os: abi::Os) -> bool { } pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> { - let os = sess.targ_cfg.os; + let os = sess.target_os(); // No rpath on windows if os == abi::OsWin32 { @@ -32,7 +32,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> { let mut flags = Vec::new(); - if sess.targ_cfg.os == abi::OsFreebsd { + if sess.target_os() == abi::OsFreebsd { flags.push_all([~"-Wl,-rpath,/usr/local/lib/gcc46", ~"-Wl,-rpath,/usr/local/lib/gcc44", ~"-Wl,-z,origin"]); diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 4fc7239e63b18..26fa87bf15f5a 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::link; +use back::{link, triple}; use back::{arm, x86, x86_64, mips}; use driver::session::{Aggressive, CrateTypeExecutable, CrateType, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; @@ -80,7 +80,7 @@ pub fn source_name(input: &Input) -> ~str { pub fn default_configuration(sess: &Session) -> ast::CrateConfig { - let tos = match sess.targ_cfg.os { + let tos = match sess.target_os() { abi::OsWin32 => InternedString::new("win32"), abi::OsMacos => InternedString::new("macos"), abi::OsLinux => InternedString::new("linux"), @@ -90,14 +90,14 @@ pub fn default_configuration(sess: &Session) -> // ARM is bi-endian, however using NDK seems to default // to little-endian unless a flag is provided. - let (end,arch,wordsz) = match sess.targ_cfg.arch { + let (end,arch,wordsz) = match sess.target_arch() { abi::X86 => ("little", "x86", "32"), abi::X86_64 => ("little", "x86_64", "64"), abi::Arm => ("little", "arm", "32"), abi::Mips => ("big", "mips", "32") }; - let fam = match sess.targ_cfg.os { + let fam = match sess.target_os() { abi::OsWin32 => InternedString::new("windows"), _ => InternedString::new("unix") }; @@ -284,9 +284,7 @@ pub fn phase_3_run_analysis_passes(sess: Session, let time_passes = sess.time_passes(); time(time_passes, "external crate/lib resolution", (), |_| - creader::read_crates(&sess, krate, - session::sess_os_to_meta_os(sess.targ_cfg.os), - token::get_ident_interner())); + creader::read_crates(&sess, krate, token::get_ident_interner())); let lang_items = time(time_passes, "language item collection", (), |_| middle::lang_items::collect_language_items(krate, &sess)); @@ -734,66 +732,32 @@ pub fn pretty_print_input(sess: Session, } -pub fn get_os(triple: &str) -> Option { - for &(name, os) in os_names.iter() { - if triple.contains(name) { return Some(os) } - } - None -} -static os_names : &'static [(&'static str, abi::Os)] = &'static [ - ("mingw32", abi::OsWin32), - ("win32", abi::OsWin32), - ("darwin", abi::OsMacos), - ("android", abi::OsAndroid), - ("linux", abi::OsLinux), - ("freebsd", abi::OsFreebsd)]; - -pub fn get_arch(triple: &str) -> Option { - for &(arch, abi) in architecture_abis.iter() { - if triple.contains(arch) { return Some(abi) } - } - None -} -static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'static [ - ("i386", abi::X86), - ("i486", abi::X86), - ("i586", abi::X86), - ("i686", abi::X86), - ("i786", abi::X86), - - ("x86_64", abi::X86_64), - - ("arm", abi::Arm), - ("xscale", abi::Arm), - ("thumb", abi::Arm), - - ("mips", abi::Mips)]; - pub fn build_target_config(sopts: &session::Options) -> session::Config { - let os = match get_os(sopts.target_triple) { - Some(os) => os, - None => early_error("unknown operating system") - }; - let arch = match get_arch(sopts.target_triple) { - Some(arch) => arch, - None => early_error("unknown architecture: " + sopts.target_triple) + let triple: triple::Triple = + match FromStr::from_str(sopts.target_triple) { + Some(triple) => triple, + None => early_error(format!("unknown architecture or missing operating system: `{}`", + sopts.target_triple)), + }; + let os = match triple.os { + Ok(ref os) => os.clone(), + Err(ref os_str) => early_error("unknown operating system: " + *os_str), }; - let (int_type, uint_type) = match arch { + let (int_type, uint_type) = match triple.arch { abi::X86 => (ast::TyI32, ast::TyU32), abi::X86_64 => (ast::TyI64, ast::TyU64), abi::Arm => (ast::TyI32, ast::TyU32), abi::Mips => (ast::TyI32, ast::TyU32) }; let target_triple = sopts.target_triple.clone(); - let target_strs = match arch { + let target_strs = match triple.arch { abi::X86 => x86::get_target_strs(target_triple, os), abi::X86_64 => x86_64::get_target_strs(target_triple, os), abi::Arm => arm::get_target_strs(target_triple, os), abi::Mips => mips::get_target_strs(target_triple, os) }; session::Config { - os: os, - arch: arch, + target: triple, target_strs: target_strs, int_type: int_type, uint_type: uint_type, @@ -1223,7 +1187,7 @@ pub fn early_error(msg: &str) -> ! { pub fn list_metadata(sess: &Session, path: &Path, out: &mut io::Writer) -> io::IoResult<()> { metadata::loader::list_file_metadata( - session::sess_os_to_meta_os(sess.targ_cfg.os), path, out) + session::sess_os_to_meta_os(sess.target_os()), path, out) } #[cfg(test)] diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 0cd0ac557787d..7d014f77faafa 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::target_strs; +use back::{target_strs, triple}; use back; use driver::driver::host_triple; use front; @@ -31,12 +31,19 @@ use std::cell::{Cell, RefCell}; use collections::HashSet; pub struct Config { - pub os: abi::Os, - pub arch: abi::Architecture, + pub target: triple::Triple, pub target_strs: target_strs::t, pub int_type: IntTy, pub uint_type: UintTy, } +impl Config { + pub fn os(&self) -> abi::Os { + self.target.expect_known_os() + } + pub fn arch(&self) -> abi::Architecture { + self.target.arch.clone() + } +} macro_rules! debugging_opts( ([ $opt:ident ] $cnt:expr ) => ( @@ -328,6 +335,15 @@ impl Session { self.opts.target_triple, &self.opts.addl_lib_search_paths) } + pub fn target_os(&self) -> abi::Os { + self.targ_cfg.os() + } + pub fn target_arch(&self) -> abi::Architecture { + self.targ_cfg.arch() + } + pub fn target_triple<'a>(&'a self) -> &'a triple::Triple { + &self.targ_cfg.target + } } /// Some reasonable defaults diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b9acd41321520..3c1cfbcb8b2c4 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -114,6 +114,7 @@ pub mod back { pub mod rpath; pub mod svh; pub mod target_strs; + pub mod triple; pub mod x86; pub mod x86_64; } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index e6b7049f4f8fa..8dcc20d2918f0 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -215,7 +215,7 @@ fn visit_item(e: &Env, i: &ast::Item) { Some(k) => { if k.equiv(&("static")) { cstore::NativeStatic - } else if e.sess.targ_cfg.os == abi::OsMacos && + } else if e.sess.target_os() == abi::OsMacos && k.equiv(&("framework")) { cstore::NativeFramework } else if k.equiv(&("framework")) { @@ -380,12 +380,10 @@ pub struct Loader<'a> { impl<'a> Loader<'a> { pub fn new(sess: &'a Session) -> Loader<'a> { - let os = driver::get_os(driver::host_triple()).unwrap(); - let os = session::sess_os_to_meta_os(os); Loader { env: Env { sess: sess, - os: os, + os: sess.target_os(), next_crate_num: sess.cstore.next_crate_num(), intr: token::get_ident_interner(), } diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index f4ea386a2ecad..7624bd304a0ea 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -11,9 +11,10 @@ #![allow(non_camel_case_types)] use std::cell::RefCell; -use std::os; +use std::{os, clone}; use std::io::fs; use collections::HashSet; +use back::triple::Triple; use myfs = util::fs; @@ -30,7 +31,7 @@ pub type pick<'a> = |path: &Path|: 'a -> FileMatch; pub struct FileSearch<'a> { pub sysroot: &'a Path, pub addl_lib_search_paths: &'a RefCell>, - pub target_triple: &'a str + pub target_triple: Triple, } impl<'a> FileSearch<'a> { @@ -50,7 +51,7 @@ impl<'a> FileSearch<'a> { debug!("filesearch: searching target lib path"); let tlib_path = make_target_lib_path(self.sysroot, - self.target_triple); + &self.target_triple); if !visited_dirs.contains_equiv(&tlib_path.as_vec()) { match f(&tlib_path) { FileMatches => found = true, @@ -63,7 +64,7 @@ impl<'a> FileSearch<'a> { let rustpath = rust_path(); for path in rustpath.iter() { let tlib_path = make_rustpkg_target_lib_path( - self.sysroot, path, self.target_triple); + self.sysroot, path, &self.target_triple); debug!("is {} in visited_dirs? {:?}", tlib_path.display(), visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned())); @@ -83,7 +84,7 @@ impl<'a> FileSearch<'a> { } pub fn get_target_lib_path(&self) -> Path { - make_target_lib_path(self.sysroot, self.target_triple) + make_target_lib_path(self.sysroot, &self.target_triple) } pub fn search(&self, pick: pick) { @@ -122,7 +123,7 @@ impl<'a> FileSearch<'a> { } pub fn new(sysroot: &'a Path, - target_triple: &'a str, + target_triple: Triple, addl_lib_search_paths: &'a RefCell>) -> FileSearch<'a> { debug!("using sysroot = {}", sysroot.display()); FileSearch { @@ -133,25 +134,29 @@ impl<'a> FileSearch<'a> { } } -pub fn relative_target_lib_path(sysroot: &Path, target_triple: &str) -> Path { +pub fn get_host_lib_path(sysroot: &Path) -> Path { + sysroot.join(find_libdir(sysroot)) +} + +pub fn relative_target_lib_path(sysroot: &Path, target_triple: &Triple) -> Path { let mut p = Path::new(find_libdir(sysroot)); assert!(p.is_relative()); p.push(rustlibdir()); - p.push(target_triple); + p.push(target_triple.to_str()); p.push("lib"); p } -fn make_target_lib_path(sysroot: &Path, - target_triple: &str) -> Path { +pub fn make_target_lib_path(sysroot: &Path, + target_triple: &Triple) -> Path { sysroot.join(&relative_target_lib_path(sysroot, target_triple)) } fn make_rustpkg_target_lib_path(sysroot: &Path, dir: &Path, - target_triple: &str) -> Path { + target_triple: &Triple) -> Path { let mut p = dir.join(find_libdir(sysroot)); - p.push(target_triple); + p.push(target_triple.to_str()); p } diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index da78b650852e8..405559f84beb8 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -326,7 +326,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp return ity; } attr::ReprExtern => { - attempts = match cx.sess().targ_cfg.arch { + attempts = match cx.sess().target_arch() { X86 | X86_64 => at_least_32, // WARNING: the ARM EABI has two variants; the one corresponding to `at_least_32` // appears to be used on Linux and NetBSD, but some systems may use the variant diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 5f063bb31ca5a..7669d8f7f691e 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -808,8 +808,8 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val let name = csearch::get_symbol(&ccx.sess().cstore, did); match ty::get(t).sty { ty::ty_bare_fn(ref fn_ty) => { - match fn_ty.abi.for_target(ccx.sess().targ_cfg.os, - ccx.sess().targ_cfg.arch) { + match fn_ty.abi.for_target(ccx.sess().target_os(), + ccx.sess().target_arch()) { Some(Rust) | Some(RustIntrinsic) => { get_extern_rust_fn(ccx, fn_ty.sig.inputs.as_slice(), @@ -973,7 +973,7 @@ pub fn with_cond<'a>( pub fn call_memcpy(cx: &Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) { let _icx = push_ctxt("call_memcpy"); let ccx = cx.ccx(); - let key = match ccx.sess().targ_cfg.arch { + let key = match ccx.sess().target_arch() { X86 | Arm | Mips => "llvm.memcpy.p0i8.p0i8.i32", X86_64 => "llvm.memcpy.p0i8.p0i8.i64" }; @@ -1017,7 +1017,7 @@ fn memzero(b: &Builder, llptr: ValueRef, ty: Type) { let _icx = push_ctxt("memzero"); let ccx = b.ccx; - let intrinsic_key = match ccx.sess().targ_cfg.arch { + let intrinsic_key = match ccx.sess().target_arch() { X86 | Arm | Mips => "llvm.memset.p0i8.i32", X86_64 => "llvm.memset.p0i8.i64" }; diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 2c9be587eaa9e..3ae184995cdc4 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -105,7 +105,7 @@ pub fn compute_abi_info(ccx: &CrateContext, atys: &[Type], rty: Type, ret_def: bool) -> FnType { - match ccx.sess().targ_cfg.arch { + match ccx.sess().target_arch() { X86 => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def), X86_64 => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def), Arm => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def), diff --git a/src/librustc/middle/trans/cabi_x86.rs b/src/librustc/middle/trans/cabi_x86.rs index 93b6fdd8988c5..8f9cc94cbbe0c 100644 --- a/src/librustc/middle/trans/cabi_x86.rs +++ b/src/librustc/middle/trans/cabi_x86.rs @@ -35,7 +35,7 @@ pub fn compute_abi_info(ccx: &CrateContext, // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp enum Strategy { RetValue(Type), RetPointer } - let strategy = match ccx.sess().targ_cfg.os { + let strategy = match ccx.sess().target_os() { OsWin32 | OsMacos => { match llsize_of_alloc(ccx, rty) { 1 => RetValue(Type::i8(ccx)), diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 0514642c58390..ca3a38d5adb24 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -276,7 +276,7 @@ pub fn finalize(cx: &CrateContext) { // instruct LLVM to emit an older version of dwarf, however, // for OS X to understand. For more info see #11352 // This can be overridden using --llvm-opts -dwarf-version,N. - if cx.sess().targ_cfg.os == abi::OsMacos { + if cx.sess().target_os() == abi::OsMacos { "Dwarf Version".with_c_str( |s| llvm::LLVMRustAddModuleFlag(cx.llmod, s, 2)); } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 0a2bf60bf04e2..14119cd2062d8 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -74,8 +74,8 @@ struct LlvmSignature { pub fn llvm_calling_convention(ccx: &CrateContext, abi: Abi) -> Option { - let os = ccx.sess().targ_cfg.os; - let arch = ccx.sess().targ_cfg.arch; + let os = ccx.sess().target_os(); + let arch = ccx.sess().target_arch(); abi.for_target(os, arch).map(|abi| { match abi { RustIntrinsic => { diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 6f91ec53419e0..4e609f7fdae23 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -101,7 +101,7 @@ impl Type { } pub fn int(ccx: &CrateContext) -> Type { - match ccx.tcx.sess.targ_cfg.arch { + match ccx.tcx.sess.target_arch() { X86 | Arm | Mips => Type::i32(ccx), X86_64 => Type::i64(ccx) } From 592b2a32ee220cfda7c3a98835c15dcd8b836da4 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 19:38:53 -0500 Subject: [PATCH 05/18] Removed a duplication of ```syntax::abi::Os```. --- src/librustc/back/arm.rs | 3 +-- src/librustc/back/mips.rs | 3 +-- src/librustc/back/x86.rs | 3 +-- src/librustc/back/x86_64.rs | 3 +-- src/librustc/driver/driver.rs | 3 +-- src/librustc/driver/session.rs | 12 ------------ src/librustc/metadata/creader.rs | 6 ++---- src/librustc/metadata/loader.rs | 28 ++++------------------------ 8 files changed, 11 insertions(+), 50 deletions(-) diff --git a/src/librustc/back/arm.rs b/src/librustc/back/arm.rs index f86c87af72674..722be437e09f7 100644 --- a/src/librustc/back/arm.rs +++ b/src/librustc/back/arm.rs @@ -9,7 +9,6 @@ // except according to those terms. use back::target_strs; -use driver::session::sess_os_to_meta_os; use metadata::loader::meta_section_name; use syntax::abi; @@ -22,7 +21,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs:: return target_strs::t { module_asm: ~"", - meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(), + meta_sect_name: meta_section_name(target_os).to_owned(), data_layout: match target_os { abi::OsMacos => { diff --git a/src/librustc/back/mips.rs b/src/librustc/back/mips.rs index 9667d7b84e9c0..aec8b71e4a27b 100644 --- a/src/librustc/back/mips.rs +++ b/src/librustc/back/mips.rs @@ -9,7 +9,6 @@ // except according to those terms. use back::target_strs; -use driver::session::sess_os_to_meta_os; use metadata::loader::meta_section_name; use syntax::abi; @@ -17,7 +16,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs:: return target_strs::t { module_asm: ~"", - meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(), + meta_sect_name: meta_section_name(target_os).to_owned(), data_layout: match target_os { abi::OsMacos => { diff --git a/src/librustc/back/x86.rs b/src/librustc/back/x86.rs index 9b22c82e91776..ae8dccf04c724 100644 --- a/src/librustc/back/x86.rs +++ b/src/librustc/back/x86.rs @@ -10,7 +10,6 @@ use back::target_strs; -use driver::session::sess_os_to_meta_os; use metadata::loader::meta_section_name; use syntax::abi; @@ -18,7 +17,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs:: return target_strs::t { module_asm: ~"", - meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(), + meta_sect_name: meta_section_name(target_os).to_owned(), data_layout: match target_os { abi::OsMacos => { diff --git a/src/librustc/back/x86_64.rs b/src/librustc/back/x86_64.rs index 524ae5e552484..84420609ca65b 100644 --- a/src/librustc/back/x86_64.rs +++ b/src/librustc/back/x86_64.rs @@ -10,7 +10,6 @@ use back::target_strs; -use driver::session::sess_os_to_meta_os; use metadata::loader::meta_section_name; use syntax::abi; @@ -18,7 +17,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs:: return target_strs::t { module_asm: ~"", - meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(), + meta_sect_name: meta_section_name(target_os).to_owned(), data_layout: match target_os { abi::OsMacos => { diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 26fa87bf15f5a..ba96ae57ac2be 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -1186,8 +1186,7 @@ pub fn early_error(msg: &str) -> ! { pub fn list_metadata(sess: &Session, path: &Path, out: &mut io::Writer) -> io::IoResult<()> { - metadata::loader::list_file_metadata( - session::sess_os_to_meta_os(sess.target_os()), path, out) + metadata::loader::list_file_metadata(sess.target_os(), path, out) } #[cfg(test)] diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 7d014f77faafa..0503cbe705568 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -560,15 +560,3 @@ pub fn collect_crate_types(session: &Session, return base; } } - -pub fn sess_os_to_meta_os(os: abi::Os) -> metadata::loader::Os { - use metadata::loader; - - match os { - abi::OsWin32 => loader::OsWin32, - abi::OsLinux => loader::OsLinux, - abi::OsAndroid => loader::OsAndroid, - abi::OsMacos => loader::OsMacos, - abi::OsFreebsd => loader::OsFreebsd - } -} diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 8dcc20d2918f0..9a9272a882382 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -14,13 +14,11 @@ use back::link; use back::svh::Svh; -use driver::{driver, session}; use driver::session::Session; use metadata::cstore; use metadata::cstore::CStore; use metadata::decoder; use metadata::loader; -use metadata::loader::Os; use metadata::loader::CratePaths; use std::cell::RefCell; @@ -40,7 +38,7 @@ use syntax::visit; struct Env<'a> { sess: &'a Session, - os: loader::Os, + os: abi::Os, next_crate_num: ast::CrateNum, intr: Rc } @@ -49,7 +47,7 @@ struct Env<'a> { // libraries necessary for later resolving, typechecking, linking, etc. pub fn read_crates(sess: &Session, krate: &ast::Crate, - os: loader::Os, + os: abi::Os, intr: Rc) { let mut e = Env { sess: sess, diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 5a342e39d701a..dd462cce20c2b 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -23,12 +23,12 @@ use syntax::diagnostic::SpanHandler; use syntax::parse::token::IdentInterner; use syntax::crateid::CrateId; use syntax::attr::AttrMetaMethods; +use syntax::abi::{Os, OsLinux, OsMacos, OsWin32, OsAndroid, OsFreebsd}; use std::c_str::ToCStr; use std::cast; use std::cmp; use std::io; -use std::os::consts::{macos, freebsd, linux, android, win32}; use std::ptr; use std::rc::Rc; use std::slice; @@ -38,14 +38,6 @@ use collections::{HashMap, HashSet}; use flate; use time; -pub enum Os { - OsMacos, - OsWin32, - OsLinux, - OsAndroid, - OsFreebsd -} - pub struct HashMismatch { path: Path, } @@ -57,7 +49,6 @@ pub struct Context<'a> { pub crate_id: &'a CrateId, pub id_hash: &'a str, pub hash: Option<&'a Svh>, - pub os: Os, pub intr: Rc, pub rejected_via_hash: Vec } @@ -150,7 +141,7 @@ impl<'a> Context<'a> { fn find_library_crate(&mut self) -> Option { let filesearch = self.sess.filesearch(); - let (dyprefix, dysuffix) = self.dylibname(); + let (dyprefix, dysuffix) = self.sess.target_triple().dylibname(); // want: crate_name.dir_part() + prefix + crate_name.file_part + "-" let dylib_prefix = format!("{}{}-", dyprefix, self.crate_id.name); @@ -334,9 +325,10 @@ impl<'a> Context<'a> { } } + let os = self.sess.target_os(); for lib in m.move_iter() { info!("{} reading metadata from: {}", flavor, lib.display()); - let metadata = match get_metadata_section(self.os, &lib) { + let metadata = match get_metadata_section(os, &lib) { Ok(blob) => { if self.crate_matches(blob.as_slice(), &lib) { blob @@ -393,18 +385,6 @@ impl<'a> Context<'a> { } } } - - // Returns the corresponding (prefix, suffix) that files need to have for - // dynamic libraries - fn dylibname(&self) -> (&'static str, &'static str) { - match self.os { - OsWin32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX), - OsMacos => (macos::DLL_PREFIX, macos::DLL_SUFFIX), - OsLinux => (linux::DLL_PREFIX, linux::DLL_SUFFIX), - OsAndroid => (android::DLL_PREFIX, android::DLL_SUFFIX), - OsFreebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX), - } - } } pub fn note_crateid_attr(diag: &SpanHandler, crateid: &CrateId) { From 4e7b2bbfb66242c1e6db0a754d09a82d9b537ca5 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 19:50:39 -0500 Subject: [PATCH 06/18] Refactor retrieving the target && host library paths in the sysroot. --- src/librustc/back/archive.rs | 2 +- src/librustc/back/link.rs | 2 +- src/librustc/back/rpath.rs | 2 +- src/librustc/driver/session.rs | 16 ++++++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index b953473fa1f34..30702b9ee51a2 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -184,7 +184,7 @@ impl<'a> Archive<'a> { let unixlibname = format!("lib{}.a", name); let mut rustpath = filesearch::rust_path(); - rustpath.push(self.sess.filesearch().get_target_lib_path()); + rustpath.push(self.sess.target_lib_path()); let search = self.sess.opts.addl_lib_search_paths.borrow(); for path in search.iter().chain(rustpath.iter()) { debug!("looking for {} inside {}", name, path.display()); diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index d1a8bbc8f00d8..c5483f0c3a005 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -1081,7 +1081,7 @@ fn link_args(sess: &Session, // The default library location, we need this to find the runtime. // The location of crates will be determined as needed. // FIXME (#9639): This needs to handle non-utf8 paths - let lib_path = sess.filesearch().get_target_lib_path(); + let lib_path = sess.target_lib_path(); let stage: ~str = ~"-L" + lib_path.as_str().unwrap(); let mut args = vec!(stage); diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 7229c27fd64b5..93a70357cea60 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> { debug!("preparing the RPATH!"); - let sysroot = sess.filesearch().sysroot; + let sysroot = sess.sysroot(); let output = out_filename; let libs = sess.cstore.get_used_crates(cstore::RequireDynamic); let libs = libs.move_iter().filter_map(|(_, l)| { diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 0503cbe705568..8b4987f981bea 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -324,14 +324,22 @@ impl Session { pub fn show_span(&self) -> bool { self.debugging_opt(SHOW_SPAN) } - pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { - let sysroot = match self.opts.maybe_sysroot { + pub fn sysroot<'a>(&'a self) -> &'a Path { + match self.opts.maybe_sysroot { Some(ref sysroot) => sysroot, None => self.default_sysroot.as_ref() .expect("missing sysroot and default_sysroot in Session") - }; + } + } + pub fn target_lib_path(&self) -> Path { + filesearch::make_target_lib_path(self.sysroot(), self.target_triple()) + } + pub fn host_lib_path(&self) -> Path { + filesearch::get_host_lib_path(self.sysroot()) + } + pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { filesearch::FileSearch::new( - sysroot, + self.sysroot(), self.opts.target_triple, &self.opts.addl_lib_search_paths) } From 120d66e724f60c2f8c51ad237c1a62d2a35f3aec Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 19:54:38 -0500 Subject: [PATCH 07/18] Impl ```std::clone::Clone``` for FileSearch. --- src/librustc/metadata/filesearch.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 7624bd304a0ea..2eb2c0e69adcc 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -33,6 +33,15 @@ pub struct FileSearch<'a> { pub addl_lib_search_paths: &'a RefCell>, pub target_triple: Triple, } +impl<'a> clone::Clone for FileSearch<'a> { + fn clone(&self) -> FileSearch<'a> { + FileSearch { + sysroot: self.sysroot, + addl_lib_search_paths: self.addl_lib_search_paths, + target_triple: self.target_triple.clone(), + } + } +} impl<'a> FileSearch<'a> { pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) { From ff1d130e0ba2ed64bfee183bea129eb7f8c777aa Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 20:03:27 -0500 Subject: [PATCH 08/18] New target triple crate metadata. Filter crates based on the crate's target triple, if present. If cross compiling, use rustc's set of crates while resolving syntax extension imports. --- src/librustc/back/link.rs | 5 ++- src/librustc/driver/driver.rs | 26 ++++++++++++++-- src/librustc/driver/session.rs | 52 +++++++++++++++++++++++++++---- src/librustc/front/test.rs | 10 +++--- src/librustc/metadata/common.rs | 3 ++ src/librustc/metadata/creader.rs | 14 ++++----- src/librustc/metadata/decoder.rs | 13 ++++++++ src/librustc/metadata/encoder.rs | 8 +++++ src/librustc/metadata/loader.rs | 20 +++++++++--- src/librustc/middle/trans/base.rs | 4 ++- src/librustdoc/core.rs | 7 +++-- src/librustdoc/test.rs | 7 +++-- 12 files changed, 138 insertions(+), 31 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index c5483f0c3a005..1f1b3c8db8964 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -529,10 +529,13 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str { truncated_hash_result(&mut s).slice_to(8).to_owned() } -pub fn build_link_meta(krate: &ast::Crate, out_filestem: &str) -> LinkMeta { +pub fn build_link_meta(krate: &ast::Crate, + out_filestem: &str, + target: triple::Triple) -> LinkMeta { let r = LinkMeta { crateid: find_crate_id(krate.attrs.as_slice(), out_filestem), crate_hash: Svh::calculate(krate), + target: target }; info!("{}", r); return r; diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index ba96ae57ac2be..9f4a3df30f90e 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -37,6 +37,7 @@ use std::io::fs; use std::io::MemReader; use std::mem::drop; use std::os; +use std::from_str::FromStr; use getopts::{optopt, optmulti, optflag, optflagopt}; use getopts; use syntax::ast; @@ -247,7 +248,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, front::config::strip_unconfigured_items(krate)); krate = time(time_passes, "maybe building test harness", krate, |krate| - front::test::modify_for_testing(sess, krate)); + front::test::modify_for_testing(sess, krate, loader)); krate = time(time_passes, "prelude injection", krate, |krate| front::std_inject::maybe_inject_prelude(sess, krate)); @@ -566,11 +567,29 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input, output, krate.attrs.as_slice(), &sess); - let loader = &mut Loader::new(&sess); + // Keep this here for the lifetime. + let syntax_search = sess.host_filesearch(); + let loader = &mut Loader::new(&sess, + // If we aren't cross compiling, + // don't load anything from rustc's + // set of crates. This will save us + // later during the link phase + // for crates like std. + if sess.cross_compiling() { + syntax_search.filesearch() + } else { + sess.target_filesearch() + }); let id = link::find_crate_id(krate.attrs.as_slice(), outputs.out_filestem); let (expanded_crate, ast_map) = phase_2_configure_and_expand(&sess, loader, krate, &id); + // While cross compiling, always reset cstore. Otherwise we'll transfer + // some host crate dependencies which may or may not (Bad) be available + // on the cross' platform. + if sess.cross_compiling() { + sess.cstore.reset(); + } (outputs, expanded_crate, ast_map) }; write_out_deps(&sess, input, &outputs, &expanded_crate).unwrap(); @@ -669,7 +688,8 @@ pub fn pretty_print_input(sess: Session, let (krate, ast_map, is_expanded) = match ppm { PpmExpanded | PpmExpandedIdentified | PpmTyped => { - let loader = &mut Loader::new(&sess); + let syntax_search = sess.host_filesearch(); + let loader = &mut Loader::new(&sess, syntax_search.filesearch()); let (krate, ast_map) = phase_2_configure_and_expand(&sess, loader, krate, &id); (krate, Some(ast_map), true) diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 8b4987f981bea..f6cc0fbc1446d 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -28,6 +28,7 @@ use syntax::{abi, ast, codemap}; use syntax; use std::cell::{Cell, RefCell}; +use std::default::Default; use collections::HashSet; pub struct Config { @@ -179,6 +180,39 @@ pub enum CrateType { CrateTypeRlib, CrateTypeStaticlib, } +// Serves mostly as a lifetime/storage boat. +pub struct HostFileSearch { + sysroot: Path, + search_paths: RefCell>, +} +impl HostFileSearch { + // Create a loader solely for the host. This is used for + // syntax phase crates referenced by our crate. We do this in order to + // prevent errors from having multiple crates in -L paths later on + // (particularly problematic when targeting non-host targets). + // We accomplish this with this minor hack. More specifically, + // we use a bogus sysroot and add the path for rustc's set of libs + // (ie /usr/local/lib/ on Unix) to addl_lib_search_paths. + fn new(sess: &Session) -> HostFileSearch { + HostFileSearch { + search_paths: RefCell::new + ({ + let mut set = (*sess.opts.addl_lib_search_paths.borrow()).clone(); + set.insert(sess.host_lib_path()); + set + }), + // ensure we don't silently (and possibly maliciously) load crates from + // our fake sysroot: + sysroot: Path::new("/dev/null"), + } + } + // Create a filesearch object for passing to metadata subsystems. + pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { + filesearch::FileSearch::new(&self.sysroot, + triple::Triple::host_triple(), + &self.search_paths) + } +} pub struct Session { pub targ_cfg: Config, @@ -331,18 +365,21 @@ impl Session { .expect("missing sysroot and default_sysroot in Session") } } + pub fn target_filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { + filesearch::FileSearch::new( + self.sysroot(), + self.target_triple().clone(), + &self.opts.addl_lib_search_paths) + } + pub fn host_filesearch(&self) -> HostFileSearch { + HostFileSearch::new(self) + } pub fn target_lib_path(&self) -> Path { filesearch::make_target_lib_path(self.sysroot(), self.target_triple()) } pub fn host_lib_path(&self) -> Path { filesearch::get_host_lib_path(self.sysroot()) } - pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { - filesearch::FileSearch::new( - self.sysroot(), - self.opts.target_triple, - &self.opts.addl_lib_search_paths) - } pub fn target_os(&self) -> abi::Os { self.targ_cfg.os() } @@ -352,6 +389,9 @@ impl Session { pub fn target_triple<'a>(&'a self) -> &'a triple::Triple { &self.targ_cfg.target } + pub fn cross_compiling(&self) -> bool { + *self.target_triple() != Default::default() + } } /// Some reasonable defaults diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index e36893f40e5ca..21b570c729999 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -58,14 +58,15 @@ struct TestCtxt<'a> { // Traverse the crate, collecting all the test functions, eliding any // existing main functions, and synthesizing a main test harness pub fn modify_for_testing(sess: &Session, - krate: ast::Crate) -> ast::Crate { + krate: ast::Crate, + loader: &mut Loader) -> ast::Crate { // We generate the test harness when building in the 'test' // configuration, either with the '--test' or '--cfg test' // command line options. let should_test = attr::contains_name(krate.config.as_slice(), "test"); if should_test { - generate_test_harness(sess, krate) + generate_test_harness(sess, krate, loader) } else { strip_test_functions(krate) } @@ -151,9 +152,10 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { } } -fn generate_test_harness(sess: &Session, krate: ast::Crate) +fn generate_test_harness(sess: &Session, + krate: ast::Crate, + loader: &mut Loader) -> ast::Crate { - let loader = &mut Loader::new(sess); let mut cx: TestCtxt = TestCtxt { sess: sess, ext_cx: ExtCtxt::new(&sess.parse_sess, sess.opts.cfg.clone(), diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 264829b18a309..5cafd8a5e2030 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -13,6 +13,7 @@ use std::cast; use syntax::crateid::CrateId; use back::svh::Svh; +use back::triple; // EBML enum definitions and utils shared by the encoder and decoder @@ -198,9 +199,11 @@ pub static tag_native_libraries_kind: uint = 0x62; pub static tag_macro_registrar_fn: uint = 0x63; pub static tag_exported_macros: uint = 0x64; pub static tag_macro_def: uint = 0x65; +pub static tag_crate_target: uint = 0x66; #[deriving(Clone, Show)] pub struct LinkMeta { pub crateid: CrateId, pub crate_hash: Svh, + pub target: triple::Triple, } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 9a9272a882382..450beadf0c488 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -18,7 +18,7 @@ use driver::session::Session; use metadata::cstore; use metadata::cstore::CStore; use metadata::decoder; -use metadata::loader; +use metadata::{loader, filesearch}; use metadata::loader::CratePaths; use std::cell::RefCell; @@ -38,7 +38,7 @@ use syntax::visit; struct Env<'a> { sess: &'a Session, - os: abi::Os, + search: filesearch::FileSearch<'a>, next_crate_num: ast::CrateNum, intr: Rc } @@ -47,11 +47,10 @@ struct Env<'a> { // libraries necessary for later resolving, typechecking, linking, etc. pub fn read_crates(sess: &Session, krate: &ast::Crate, - os: abi::Os, intr: Rc) { let mut e = Env { sess: sess, - os: os, + search: sess.target_filesearch(), next_crate_num: sess.cstore.next_crate_num(), intr: intr }; @@ -285,12 +284,12 @@ fn resolve_crate<'a>(e: &mut Env, let id_hash = link::crate_id_hash(crate_id); let mut load_ctxt = loader::Context { sess: e.sess, + search: e.search.clone(), span: span, ident: ident, crate_id: crate_id, id_hash: id_hash, hash: hash.map(|a| &*a), - os: e.os, intr: e.intr.clone(), rejected_via_hash: vec!(), }; @@ -377,11 +376,12 @@ pub struct Loader<'a> { } impl<'a> Loader<'a> { - pub fn new(sess: &'a Session) -> Loader<'a> { + pub fn new(sess: &'a Session, + search: filesearch::FileSearch<'a>) -> Loader<'a> { Loader { env: Env { sess: sess, - os: sess.target_os(), + search: search, next_crate_num: sess.cstore.next_crate_num(), intr: token::get_ident_interner(), } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index ee7ce817a3f20..cb5c17c3bf48a 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -13,6 +13,7 @@ #![allow(non_camel_case_types)] use back::svh::Svh; +use back::triple; use metadata::cstore::crate_metadata; use metadata::common::*; use metadata::csearch::StaticMethodInfo; @@ -1132,6 +1133,18 @@ pub fn get_crate_id(data: &[u8]) -> CrateId { from_str(hashdoc.as_str_slice()).unwrap() } +pub fn maybe_get_crate_target(data: &[u8]) -> Option { + let cratedoc = reader::Doc(data); + reader::maybe_get_doc(cratedoc, tag_crate_target).and_then(|doc| { + from_str(doc.as_str_slice()) + }) +} +pub fn get_crate_target(data: &[u8]) -> triple::Triple { + let cratedoc = reader::Doc(data); + let doc = reader::get_doc(cratedoc, tag_crate_target); + from_str(doc.as_str_slice()).unwrap() +} + pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> { let hash = get_crate_hash(bytes); let md = reader::Doc(bytes); diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 085a96ea7be2f..43f1719d851f9 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -14,6 +14,7 @@ #![allow(non_camel_case_types)] use back::svh::Svh; +use back::triple; use metadata::common::*; use metadata::cstore; use metadata::decoder; @@ -1707,6 +1708,12 @@ fn encode_crate_id(ebml_w: &mut Encoder, crate_id: &CrateId) { ebml_w.end_tag(); } +fn encode_crate_target(ebml_w: &mut Encoder, triple: &triple::Triple) { + ebml_w.start_tag(tag_crate_target); + ebml_w.writer.write(triple.full.as_bytes()); + ebml_w.end_tag(); +} + // NB: Increment this as you change the metadata encoding version. pub static metadata_encoding_version : &'static [u8] = &[0x72, //'r' as u8, @@ -1767,6 +1774,7 @@ fn encode_metadata_inner(wr: &mut MemWriter, parms: EncodeParams, krate: &Crate) encode_crate_id(&mut ebml_w, &ecx.link_meta.crateid); encode_hash(&mut ebml_w, &ecx.link_meta.crate_hash); + encode_crate_target(&mut ebml_w, &ecx.link_meta.target); let mut i = ebml_w.writer.tell().unwrap(); let crate_attrs = synthesize_crate_attrs(&ecx, krate); diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index dd462cce20c2b..702601bcef218 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -17,7 +17,7 @@ use lib::llvm::{False, llvm, ObjectFile, mk_section_iter}; use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive}; use metadata::decoder; use metadata::encoder; -use metadata::filesearch::{FileMatches, FileDoesntMatch}; +use metadata::filesearch::{FileMatches, FileDoesntMatch, FileSearch}; use syntax::codemap::Span; use syntax::diagnostic::SpanHandler; use syntax::parse::token::IdentInterner; @@ -44,6 +44,12 @@ pub struct HashMismatch { pub struct Context<'a> { pub sess: &'a Session, + + // The locations searched by this context. During syntax extension expansion + // we use rustc's set of libs (ie /usr/local/lib/ on Unix) plus the paths specified + // with -L. Whereas during the link phase we search as usual in the target lib plus + // cli paths. + pub search: FileSearch<'a>, pub span: Span, pub ident: &'a str, pub crate_id: &'a CrateId, @@ -140,8 +146,7 @@ impl<'a> Context<'a> { } fn find_library_crate(&mut self) -> Option { - let filesearch = self.sess.filesearch(); - let (dyprefix, dysuffix) = self.sess.target_triple().dylibname(); + let (dyprefix, dysuffix) = self.search.target_triple.dylibname(); // want: crate_name.dir_part() + prefix + crate_name.file_part + "-" let dylib_prefix = format!("{}{}-", dyprefix, self.crate_id.name); @@ -162,7 +167,7 @@ impl<'a> Context<'a> { // of the crate id (path/name/id). // // The goal of this step is to look at as little metadata as possible. - filesearch.search(|path| { + self.search.search(|path| { let file = match path.filename_str() { None => return FileDoesntMatch, Some(file) => file, @@ -325,7 +330,7 @@ impl<'a> Context<'a> { } } - let os = self.sess.target_os(); + let os = self.search.target_triple.expect_known_os(); for lib in m.move_iter() { info!("{} reading metadata from: {}", flavor, lib.display()); let metadata = match get_metadata_section(os, &lib) { @@ -370,6 +375,11 @@ impl<'a> Context<'a> { Some(ref id) if self.crate_id.matches(id) => {} _ => return false } + match decoder::maybe_get_crate_target(crate_data) { + Some(ref triple) if *triple != self.search.target_triple => return false, + // note: don't fail this check if the crate lacks target triple metadata. + _ => {}, + } let hash = match decoder::maybe_get_crate_hash(crate_data) { Some(hash) => hash, None => return false }; diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 7669d8f7f691e..3e1e735974b88 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2119,7 +2119,9 @@ pub fn trans_crate(krate: ast::Crate, } } - let link_meta = link::build_link_meta(&krate, output.out_filestem); + let link_meta = link::build_link_meta(&krate, + output.out_filestem, + tcx.sess.target_triple().clone()); // Append ".rs" to crate name as LLVM module identifier. // diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 027d14babafd2..115094b744584 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -85,8 +85,11 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec<~str>) } let krate = phase_1_parse_input(&sess, cfg, &input); - let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), - krate, &from_str("rustdoc").unwrap()); + let (krate, ast_map) = phase_2_configure_and_expand + (&sess, + &mut Loader::new(&sess, sess.target_filesearch()), + krate, + &from_str("rustdoc").unwrap()); let driver::driver::CrateAnalysis { exported_items, public_items, ty_cx, .. } = phase_3_run_analysis_passes(sess, &krate, ast_map); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index ad49f41f64afc..8af6203f16851 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -64,8 +64,11 @@ pub fn run(input: &str, cfgs: Vec<~str>, @dummy_spanned(ast::MetaWord(cfg_)) })); let krate = driver::phase_1_parse_input(&sess, cfg, &input); - let (krate, _) = driver::phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), krate, - &from_str("rustdoc-test").unwrap()); + let (krate, _) = driver::phase_2_configure_and_expand + (&sess, + &mut Loader::new(&sess, sess.target_filesearch()), + krate, + &from_str("rustdoc-test").unwrap()); let ctx = @core::DocContext { krate: krate, From 9d704a1dcabf12975618134284e38b3c4bb4b24a Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 20:11:54 -0500 Subject: [PATCH 09/18] Refactor ```rustc::back::rpath``` to use Triple. --- src/librustc/back/rpath.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 93a70357cea60..4873bb03098be 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -12,6 +12,7 @@ use driver::session::Session; use metadata::cstore; use metadata::filesearch; +use back::triple; use util::fs; use collections::HashSet; @@ -48,7 +49,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> { }).collect::<~[_]>(); let rpaths = get_rpaths(os, sysroot, output, libs, - sess.opts.target_triple); + sess.target_triple()); flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice()); flags } @@ -65,7 +66,7 @@ fn get_rpaths(os: abi::Os, sysroot: &Path, output: &Path, libs: &[Path], - target_triple: &str) -> Vec<~str> { + target_triple: &triple::Triple) -> Vec<~str> { debug!("sysroot: {}", sysroot.display()); debug!("output: {}", output.display()); debug!("libs:"); @@ -132,7 +133,7 @@ pub fn get_rpath_relative_to_output(os: abi::Os, prefix+"/"+relative.as_str().expect("non-utf8 component in path") } -pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &str) -> ~str { +pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &triple::Triple) -> ~str { let install_prefix = env!("CFG_PREFIX"); let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); @@ -157,12 +158,18 @@ pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> { #[cfg(unix, test)] mod test { use std::os; + use std::from_str::FromStr; use back::rpath::get_install_prefix_rpath; use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output}; + use back::triple::Triple; use syntax::abi; use metadata::filesearch; + fn triple() -> Triple { + FromStr::from_str("x86_64-unknown-linux-gnu").unwrap() + } + #[test] fn test_rpaths_to_flags() { let flags = rpaths_to_flags([~"path1", ~"path2"]); @@ -172,11 +179,12 @@ mod test { #[test] fn test_prefix_rpath() { let sysroot = filesearch::get_or_default_sysroot(); - let res = get_install_prefix_rpath(&sysroot, "triple"); + let triple = triple(); + let res = get_install_prefix_rpath(&sysroot, &triple); let mut d = Path::new(env!("CFG_PREFIX")); d.push("lib"); d.push(filesearch::rustlibdir()); - d.push("triple/lib"); + d.push("x86_64-unknown-linux-gnu/lib"); debug!("test_prefix_path: {} vs. {}", res, d.display()); @@ -186,7 +194,7 @@ mod test { #[test] fn test_prefix_rpath_abs() { let sysroot = filesearch::get_or_default_sysroot(); - let res = get_install_prefix_rpath(&sysroot, "triple"); + let res = get_install_prefix_rpath(&sysroot, &triple()); assert!(Path::new(res).is_absolute()); } From a4e2e4b4d7ff1e8215662327d94703038fc3c48c Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 20:40:00 -0500 Subject: [PATCH 10/18] Fix type mismatch. Oops. --- src/librustc/front/test.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 21b570c729999..e480c2a1a1e7a 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -28,6 +28,7 @@ use syntax::attr; use syntax::codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute}; use syntax::codemap; use syntax::ext::base::ExtCtxt; +use syntax::ext::base::CrateLoader; use syntax::ext::expand::ExpansionConfig; use syntax::fold::Folder; use syntax::fold; @@ -59,7 +60,7 @@ struct TestCtxt<'a> { // existing main functions, and synthesizing a main test harness pub fn modify_for_testing(sess: &Session, krate: ast::Crate, - loader: &mut Loader) -> ast::Crate { + loader: &mut CrateLoader) -> ast::Crate { // We generate the test harness when building in the 'test' // configuration, either with the '--test' or '--cfg test' // command line options. @@ -154,7 +155,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { fn generate_test_harness(sess: &Session, krate: ast::Crate, - loader: &mut Loader) + loader: &mut CrateLoader) -> ast::Crate { let mut cx: TestCtxt = TestCtxt { sess: sess, From 3682a4c9b0eed800d010c23137adea96036bdc95 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 22:13:20 -0500 Subject: [PATCH 11/18] Move rustc's Triple structure into its own crate so compiletest doesn't need to import all of librustc. --- mk/crates.mk | 7 ++++--- src/{librustc/back/triple.rs => libmach_triple/lib.rs} | 10 ++++++++++ src/librustc/back/link.rs | 5 +++-- src/librustc/back/rpath.rs | 8 ++++---- src/librustc/driver/driver.rs | 5 +++-- src/librustc/driver/session.rs | 10 ++++++---- src/librustc/lib.rs | 2 +- src/librustc/metadata/common.rs | 4 ++-- src/librustc/metadata/decoder.rs | 6 +++--- src/librustc/metadata/encoder.rs | 4 ++-- src/librustc/metadata/filesearch.rs | 2 +- 11 files changed, 39 insertions(+), 24 deletions(-) rename src/{librustc/back/triple.rs => libmach_triple/lib.rs} (97%) diff --git a/mk/crates.mk b/mk/crates.mk index 28330010dc2ac..16519cf5389bd 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -52,7 +52,7 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \ uuid serialize sync getopts collections num test time rand \ workcache url log -HOST_CRATES := syntax rustc rustdoc fourcc hexfloat +HOST_CRATES := syntax rustc rustdoc fourcc hexfloat mach_triple CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -62,7 +62,7 @@ DEPS_rustuv := std native:uv native:uv_support DEPS_native := std DEPS_syntax := std term serialize collections log DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \ - collections time log + collections time log mach_triple DEPS_rustdoc := rustc native:sundown serialize sync getopts collections \ test time DEPS_flate := std native:miniz @@ -84,8 +84,9 @@ DEPS_rand := std DEPS_url := std collections DEPS_workcache := std serialize collections log DEPS_log := std sync +DEPS_mach_triple := std syntax -TOOL_DEPS_compiletest := test green rustuv getopts +TOOL_DEPS_compiletest := test green rustuv getopts mach_triple TOOL_DEPS_rustdoc := rustdoc native TOOL_DEPS_rustc := rustc native TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs diff --git a/src/librustc/back/triple.rs b/src/libmach_triple/lib.rs similarity index 97% rename from src/librustc/back/triple.rs rename to src/libmach_triple/lib.rs index 52267fdb6e5da..5d5c41a571b88 100644 --- a/src/librustc/back/triple.rs +++ b/src/libmach_triple/lib.rs @@ -8,6 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![crate_id = "mach_triple#0.11-pre"] +#![license = "MIT/ASL2"] +#![crate_type = "rlib"] +#![crate_type = "dylib"] +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "http://www.rust-lang.org/favicon.ico", + html_root_url = "http://static.rust-lang.org/doc/master")] + +extern crate syntax; + use std::result::{Result, Ok, Err}; use std::from_str::FromStr; use std::{cmp, fmt, default}; diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 1f1b3c8db8964..aebe620c7b6ce 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -9,7 +9,7 @@ // except according to those terms. use back::archive::{Archive, METADATA_FILENAME}; -use back::{rpath, triple}; +use back::rpath; use back::svh::Svh; use driver::driver::{CrateTranslation, OutputFilenames}; use driver::session::{NoDebugInfo, Session}; @@ -25,6 +25,7 @@ use middle::ty; use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; +use mach_triple; use std::c_str::{ToCStr, CString}; use std::char; @@ -531,7 +532,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str { pub fn build_link_meta(krate: &ast::Crate, out_filestem: &str, - target: triple::Triple) -> LinkMeta { + target: mach_triple::Triple) -> LinkMeta { let r = LinkMeta { crateid: find_crate_id(krate.attrs.as_slice(), out_filestem), crate_hash: Svh::calculate(krate), diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 4873bb03098be..0213442bf6fe4 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -12,7 +12,7 @@ use driver::session::Session; use metadata::cstore; use metadata::filesearch; -use back::triple; +use mach_triple; use util::fs; use collections::HashSet; @@ -66,7 +66,7 @@ fn get_rpaths(os: abi::Os, sysroot: &Path, output: &Path, libs: &[Path], - target_triple: &triple::Triple) -> Vec<~str> { + target_triple: &mach_triple::Triple) -> Vec<~str> { debug!("sysroot: {}", sysroot.display()); debug!("output: {}", output.display()); debug!("libs:"); @@ -133,7 +133,7 @@ pub fn get_rpath_relative_to_output(os: abi::Os, prefix+"/"+relative.as_str().expect("non-utf8 component in path") } -pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &triple::Triple) -> ~str { +pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &mach_triple::Triple) -> ~str { let install_prefix = env!("CFG_PREFIX"); let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); @@ -162,7 +162,7 @@ mod test { use back::rpath::get_install_prefix_rpath; use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output}; - use back::triple::Triple; + use mach_triple::Triple; use syntax::abi; use metadata::filesearch; diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 9f4a3df30f90e..c5196f73d5b3b 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::{link, triple}; +use back::link; use back::{arm, x86, x86_64, mips}; use driver::session::{Aggressive, CrateTypeExecutable, CrateType, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; @@ -28,6 +28,7 @@ use middle; use util::common::time; use util::ppaux; use util::nodemap::{NodeMap, NodeSet}; +use mach_triple; use serialize::{json, Encodable}; @@ -753,7 +754,7 @@ pub fn pretty_print_input(sess: Session, } pub fn build_target_config(sopts: &session::Options) -> session::Config { - let triple: triple::Triple = + let triple: mach_triple::Triple = match FromStr::from_str(sopts.target_triple) { Some(triple) => triple, None => early_error(format!("unknown architecture or missing operating system: `{}`", diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index f6cc0fbc1446d..ea51dda6038cf 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -9,7 +9,7 @@ // except according to those terms. -use back::{target_strs, triple}; +use back::target_strs; use back; use driver::driver::host_triple; use front; @@ -27,12 +27,14 @@ use syntax::parse::ParseSess; use syntax::{abi, ast, codemap}; use syntax; +use mach_triple::Triple; + use std::cell::{Cell, RefCell}; use std::default::Default; use collections::HashSet; pub struct Config { - pub target: triple::Triple, + pub target: Triple, pub target_strs: target_strs::t, pub int_type: IntTy, pub uint_type: UintTy, @@ -209,7 +211,7 @@ impl HostFileSearch { // Create a filesearch object for passing to metadata subsystems. pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> { filesearch::FileSearch::new(&self.sysroot, - triple::Triple::host_triple(), + Default::default(), &self.search_paths) } } @@ -386,7 +388,7 @@ impl Session { pub fn target_arch(&self) -> abi::Architecture { self.targ_cfg.arch() } - pub fn target_triple<'a>(&'a self) -> &'a triple::Triple { + pub fn target_triple<'a>(&'a self) -> &'a Triple { &self.targ_cfg.target } pub fn cross_compiling(&self) -> bool { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 3c1cfbcb8b2c4..740e304bf8e02 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -40,6 +40,7 @@ extern crate getopts; extern crate collections; extern crate time; extern crate libc; +extern crate mach_triple; #[phase(syntax, link)] extern crate log; @@ -114,7 +115,6 @@ pub mod back { pub mod rpath; pub mod svh; pub mod target_strs; - pub mod triple; pub mod x86; pub mod x86_64; } diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 5cafd8a5e2030..0d4b6895f55a8 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -13,7 +13,7 @@ use std::cast; use syntax::crateid::CrateId; use back::svh::Svh; -use back::triple; +use mach_triple; // EBML enum definitions and utils shared by the encoder and decoder @@ -205,5 +205,5 @@ pub static tag_crate_target: uint = 0x66; pub struct LinkMeta { pub crateid: CrateId, pub crate_hash: Svh, - pub target: triple::Triple, + pub target: mach_triple::Triple, } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index cb5c17c3bf48a..e9247a0681e72 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -13,7 +13,6 @@ #![allow(non_camel_case_types)] use back::svh::Svh; -use back::triple; use metadata::cstore::crate_metadata; use metadata::common::*; use metadata::csearch::StaticMethodInfo; @@ -26,6 +25,7 @@ use middle::ty::{ImplContainer, TraitContainer}; use middle::ty; use middle::typeck; use middle::astencode::vtable_decoder_helpers; +use mach_triple; use std::u64; use std::hash; @@ -1133,13 +1133,13 @@ pub fn get_crate_id(data: &[u8]) -> CrateId { from_str(hashdoc.as_str_slice()).unwrap() } -pub fn maybe_get_crate_target(data: &[u8]) -> Option { +pub fn maybe_get_crate_target(data: &[u8]) -> Option { let cratedoc = reader::Doc(data); reader::maybe_get_doc(cratedoc, tag_crate_target).and_then(|doc| { from_str(doc.as_str_slice()) }) } -pub fn get_crate_target(data: &[u8]) -> triple::Triple { +pub fn get_crate_target(data: &[u8]) -> mach_triple::Triple { let cratedoc = reader::Doc(data); let doc = reader::get_doc(cratedoc, tag_crate_target); from_str(doc.as_str_slice()).unwrap() diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 43f1719d851f9..0574a1a86dddf 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -14,7 +14,6 @@ #![allow(non_camel_case_types)] use back::svh::Svh; -use back::triple; use metadata::common::*; use metadata::cstore; use metadata::decoder; @@ -25,6 +24,7 @@ use middle::ty; use middle::typeck; use middle; use util::nodemap::{NodeMap, NodeSet}; +use mach_triple; use serialize::Encodable; use std::cast; @@ -1708,7 +1708,7 @@ fn encode_crate_id(ebml_w: &mut Encoder, crate_id: &CrateId) { ebml_w.end_tag(); } -fn encode_crate_target(ebml_w: &mut Encoder, triple: &triple::Triple) { +fn encode_crate_target(ebml_w: &mut Encoder, triple: &mach_triple::Triple) { ebml_w.start_tag(tag_crate_target); ebml_w.writer.write(triple.full.as_bytes()); ebml_w.end_tag(); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 2eb2c0e69adcc..4524b43a15849 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::{os, clone}; use std::io::fs; use collections::HashSet; -use back::triple::Triple; +use mach_triple::Triple; use myfs = util::fs; From 8feaef1926d157f30f24775bf82111edf9ab7922 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 10 Apr 2014 22:59:28 -0500 Subject: [PATCH 12/18] fmt::Show for Os in libsyntax. --- src/libsyntax/abi.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 70657d2234abd..4bbf8ca23c12c 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -28,6 +28,18 @@ impl from_str::FromStr for Os { } } +impl fmt::Show for Os { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &OsWin32 => "win32".fmt(f), + &OsMacos => "darwin".fmt(f), + &OsLinux => "linux".fmt(f), + &OsAndroid => "android".fmt(f), + &OsFreebsd => "freebsd".fmt(f), + } + } +} + #[deriving(Eq, TotalEq, Hash, Encodable, Decodable, Clone)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. From 5891ba52a7b59b248faa591bba4db65e3da6816f Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Fri, 11 Apr 2014 02:15:48 -0500 Subject: [PATCH 13/18] Renamed libmach_triple to libmachine. Moved about half of libsyntax/abi to libmachine. Added convenience checks for Android triples (I apologize, I trapped myself on my own work-flow). --- mk/crates.mk | 10 +- src/libmachine/abi.rs | 74 ++++++++++++++ src/libmachine/lib.rs | 20 ++++ .../lib.rs => libmachine/triple.rs} | 28 +++--- src/librustc/back/archive.rs | 2 +- src/librustc/back/arm.rs | 2 +- src/librustc/back/link.rs | 9 +- src/librustc/back/mips.rs | 2 +- src/librustc/back/rpath.rs | 12 +-- src/librustc/back/x86.rs | 2 +- src/librustc/back/x86_64.rs | 2 +- src/librustc/driver/driver.rs | 7 +- src/librustc/driver/session.rs | 2 +- src/librustc/lib.rs | 2 +- src/librustc/metadata/common.rs | 4 +- src/librustc/metadata/creader.rs | 3 +- src/librustc/metadata/decoder.rs | 6 +- src/librustc/metadata/encoder.rs | 4 +- src/librustc/metadata/filesearch.rs | 2 +- src/librustc/metadata/loader.rs | 2 +- src/librustc/middle/trans/adt.rs | 2 +- src/librustc/middle/trans/base.rs | 3 +- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/cabi_x86.rs | 2 +- src/librustc/middle/trans/debuginfo.rs | 3 +- src/librustc/middle/trans/type_.rs | 2 +- src/libsyntax/abi.rs | 96 +++++-------------- src/libsyntax/lib.rs | 1 + 28 files changed, 183 insertions(+), 123 deletions(-) create mode 100644 src/libmachine/abi.rs create mode 100644 src/libmachine/lib.rs rename src/{libmach_triple/lib.rs => libmachine/triple.rs} (97%) diff --git a/mk/crates.mk b/mk/crates.mk index 16519cf5389bd..3cbd6e8ba95ad 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -52,7 +52,7 @@ TARGET_CRATES := libc std green rustuv native flate arena glob term semver \ uuid serialize sync getopts collections num test time rand \ workcache url log -HOST_CRATES := syntax rustc rustdoc fourcc hexfloat mach_triple +HOST_CRATES := syntax rustc rustdoc fourcc hexfloat machine CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -60,9 +60,9 @@ DEPS_std := libc native:rustrt native:compiler-rt native:backtrace DEPS_green := std rand native:context_switch DEPS_rustuv := std native:uv native:uv_support DEPS_native := std -DEPS_syntax := std term serialize collections log +DEPS_syntax := std term serialize collections log machine DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \ - collections time log mach_triple + collections time log machine DEPS_rustdoc := rustc native:sundown serialize sync getopts collections \ test time DEPS_flate := std native:miniz @@ -84,9 +84,9 @@ DEPS_rand := std DEPS_url := std collections DEPS_workcache := std serialize collections log DEPS_log := std sync -DEPS_mach_triple := std syntax +DEPS_machine := std -TOOL_DEPS_compiletest := test green rustuv getopts mach_triple +TOOL_DEPS_compiletest := test green rustuv getopts machine TOOL_DEPS_rustdoc := rustdoc native TOOL_DEPS_rustc := rustc native TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs diff --git a/src/libmachine/abi.rs b/src/libmachine/abi.rs new file mode 100644 index 0000000000000..e1267a60c71d6 --- /dev/null +++ b/src/libmachine/abi.rs @@ -0,0 +1,74 @@ +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::fmt; +use std::from_str; + +#[deriving(Eq, Hash, Clone, TotalEq)] +pub enum Os { + OsWin32, + OsMacos, + OsLinux, + OsAndroid, + OsFreebsd, +} + +impl from_str::FromStr for Os { + fn from_str(s: &str) -> Option { + match s { + "mingw32" => Some(OsWin32), + "win32" => Some(OsWin32), + "darwin" => Some(OsMacos), + "android" => Some(OsAndroid), + "linux" => Some(OsLinux), + "freebsd" => Some(OsFreebsd), + _ => None, + } + } +} + +impl fmt::Show for Os { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &OsWin32 => "win32".fmt(f), + &OsMacos => "darwin".fmt(f), + &OsLinux => "linux".fmt(f), + &OsAndroid => "android".fmt(f), + &OsFreebsd => "freebsd".fmt(f), + } + } +} + +#[allow(non_camel_case_types)] +#[deriving(Eq, Clone, Hash, TotalEq)] +pub enum Architecture { + // NB. You cannot change the ordering of these + // constants without adjusting IntelBits below. + // (This is ensured by the test indices_are_correct().) + X86, + X86_64, + Arm, + Mips +} +impl from_str::FromStr for Architecture { + fn from_str(s: &str) -> Option { + match s { + "i386" | "i486" | "i586" | "i686" | "i786" => Some(X86), + "x86_64" => Some(X86_64), + "arm" | "xscale" | "thumb" => Some(Arm), + "mips" => Some(Mips), + _ => None, + } + } +} + +pub static IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); +pub static ArmBits: u32 = (1 << (Arm as uint)); + diff --git a/src/libmachine/lib.rs b/src/libmachine/lib.rs new file mode 100644 index 0000000000000..735e37f3765e5 --- /dev/null +++ b/src/libmachine/lib.rs @@ -0,0 +1,20 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_id = "machine#0.11-pre"] +#![license = "MIT/ASL2"] +#![crate_type = "rlib"] +#![crate_type = "dylib"] +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", + html_favicon_url = "http://www.rust-lang.org/favicon.ico", + html_root_url = "http://static.rust-lang.org/doc/master")] + +pub mod abi; +pub mod triple; diff --git a/src/libmach_triple/lib.rs b/src/libmachine/triple.rs similarity index 97% rename from src/libmach_triple/lib.rs rename to src/libmachine/triple.rs index 5d5c41a571b88..3795ae457fb88 100644 --- a/src/libmach_triple/lib.rs +++ b/src/libmachine/triple.rs @@ -8,21 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_id = "mach_triple#0.11-pre"] -#![license = "MIT/ASL2"] -#![crate_type = "rlib"] -#![crate_type = "dylib"] -#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", - html_favicon_url = "http://www.rust-lang.org/favicon.ico", - html_root_url = "http://static.rust-lang.org/doc/master")] - -extern crate syntax; - use std::result::{Result, Ok, Err}; use std::from_str::FromStr; use std::{cmp, fmt, default}; use std::os::consts::{macos, freebsd, linux, android, win32}; -use syntax::abi; +use abi; pub type KnownType = Result; pub trait Known { @@ -157,6 +147,20 @@ impl Triple { abi::OsFreebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX), } } + + // Are we targeting Android? + pub fn is_android(&self) -> bool { + use abi::OsAndroid; + + self.os == Ok(OsAndroid) && + self.env == Some(Ok(AndroidEAbiEnv)) + } + // Are we targeting Android and Arm? + pub fn is_android_on_arm(&self) -> bool { + use abi::Arm; + + self.arch == Arm && self.is_android() + } } impl FromStr for Triple { @@ -250,7 +254,7 @@ mod test { UnknownVendor, GnuEnv, GnuDefault, AndroidEAbiEnv, MsvcEnv}; - use syntax::abi; + use abi; use std::to_str::ToStr; use std::from_str::FromStr; use std::fmt::Show; diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 30702b9ee51a2..a40b7fc3c5dc0 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -23,7 +23,7 @@ use std::os; use std::io::process::{ProcessConfig, Process, ProcessOutput}; use std::str; use std::raw; -use syntax::abi; +use machine::abi; pub static METADATA_FILENAME: &'static str = "rust.metadata.bin"; diff --git a/src/librustc/back/arm.rs b/src/librustc/back/arm.rs index 722be437e09f7..cdd29601d6f46 100644 --- a/src/librustc/back/arm.rs +++ b/src/librustc/back/arm.rs @@ -10,7 +10,7 @@ use back::target_strs; use metadata::loader::meta_section_name; -use syntax::abi; +use machine::abi; pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t { let cc_args = if target_triple.contains("thumb") { diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index aebe620c7b6ce..a460425ba9bbd 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -25,7 +25,7 @@ use middle::ty; use util::common::time; use util::ppaux; use util::sha2::{Digest, Sha256}; -use mach_triple; +use machine::triple; use std::c_str::{ToCStr, CString}; use std::char; @@ -36,7 +36,7 @@ use std::str; use std::strbuf::StrBuf; use flate; use serialize::hex::ToHex; -use syntax::abi; +use machine::abi; use syntax::ast; use syntax::ast_map::{PathElem, PathElems, PathName}; use syntax::ast_map; @@ -99,7 +99,6 @@ pub mod write { use lib::llvm::{ModuleRef, TargetMachineRef, PassManagerRef}; use lib; use util::common::time; - use syntax::abi; use std::c_str::ToCStr; use std::io::Process; @@ -112,6 +111,7 @@ pub mod write { // cases, so if any sort of target feature is specified we don't append v7 // to the feature list. fn target_feature<'a>(sess: &'a Session) -> &'a str { + use machine::abi; match sess.target_os() { abi::OsAndroid => { if "" == sess.opts.cg.target_feature { @@ -128,6 +128,7 @@ pub mod write { trans: &CrateTranslation, output_types: &[OutputType], output: &OutputFilenames) { + use machine::abi; let llmod = trans.module; let llcx = trans.context; unsafe { @@ -532,7 +533,7 @@ pub fn crate_id_hash(crate_id: &CrateId) -> ~str { pub fn build_link_meta(krate: &ast::Crate, out_filestem: &str, - target: mach_triple::Triple) -> LinkMeta { + target: triple::Triple) -> LinkMeta { let r = LinkMeta { crateid: find_crate_id(krate.attrs.as_slice(), out_filestem), crate_hash: Svh::calculate(krate), diff --git a/src/librustc/back/mips.rs b/src/librustc/back/mips.rs index aec8b71e4a27b..d6b7d506f992f 100644 --- a/src/librustc/back/mips.rs +++ b/src/librustc/back/mips.rs @@ -10,7 +10,7 @@ use back::target_strs; use metadata::loader::meta_section_name; -use syntax::abi; +use machine::abi; pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t { return target_strs::t { diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 0213442bf6fe4..57a8fbddb129b 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -12,12 +12,12 @@ use driver::session::Session; use metadata::cstore; use metadata::filesearch; -use mach_triple; +use machine::triple; use util::fs; use collections::HashSet; use std::os; -use syntax::abi; +use machine::abi; fn not_win32(os: abi::Os) -> bool { os != abi::OsWin32 @@ -66,7 +66,7 @@ fn get_rpaths(os: abi::Os, sysroot: &Path, output: &Path, libs: &[Path], - target_triple: &mach_triple::Triple) -> Vec<~str> { + target_triple: &triple::Triple) -> Vec<~str> { debug!("sysroot: {}", sysroot.display()); debug!("output: {}", output.display()); debug!("libs:"); @@ -133,7 +133,7 @@ pub fn get_rpath_relative_to_output(os: abi::Os, prefix+"/"+relative.as_str().expect("non-utf8 component in path") } -pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &mach_triple::Triple) -> ~str { +pub fn get_install_prefix_rpath(sysroot: &Path, target_triple: &triple::Triple) -> ~str { let install_prefix = env!("CFG_PREFIX"); let tlib = filesearch::relative_target_lib_path(sysroot, target_triple); @@ -162,8 +162,8 @@ mod test { use back::rpath::get_install_prefix_rpath; use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output}; - use mach_triple::Triple; - use syntax::abi; + use machine::triple::Triple; + use machine::abi; use metadata::filesearch; fn triple() -> Triple { diff --git a/src/librustc/back/x86.rs b/src/librustc/back/x86.rs index ae8dccf04c724..c831758182a5e 100644 --- a/src/librustc/back/x86.rs +++ b/src/librustc/back/x86.rs @@ -11,7 +11,7 @@ use back::target_strs; use metadata::loader::meta_section_name; -use syntax::abi; +use machine::abi; pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t { return target_strs::t { diff --git a/src/librustc/back/x86_64.rs b/src/librustc/back/x86_64.rs index 84420609ca65b..a4433c3a9ff3a 100644 --- a/src/librustc/back/x86_64.rs +++ b/src/librustc/back/x86_64.rs @@ -11,7 +11,7 @@ use back::target_strs; use metadata::loader::meta_section_name; -use syntax::abi; +use machine::abi; pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t { return target_strs::t { diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index c5196f73d5b3b..eb12e9e822e75 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -28,7 +28,7 @@ use middle; use util::common::time; use util::ppaux; use util::nodemap::{NodeMap, NodeSet}; -use mach_triple; +use machine::triple; use serialize::{json, Encodable}; @@ -42,7 +42,6 @@ use std::from_str::FromStr; use getopts::{optopt, optmulti, optflag, optflagopt}; use getopts; use syntax::ast; -use syntax::abi; use syntax::attr; use syntax::attr::{AttrMetaMethods}; use syntax::codemap; @@ -82,6 +81,7 @@ pub fn source_name(input: &Input) -> ~str { pub fn default_configuration(sess: &Session) -> ast::CrateConfig { + use machine::abi; let tos = match sess.target_os() { abi::OsWin32 => InternedString::new("win32"), abi::OsMacos => InternedString::new("macos"), @@ -754,7 +754,8 @@ pub fn pretty_print_input(sess: Session, } pub fn build_target_config(sopts: &session::Options) -> session::Config { - let triple: mach_triple::Triple = + use machine::abi; + let triple: triple::Triple = match FromStr::from_str(sopts.target_triple) { Some(triple) => triple, None => early_error(format!("unknown architecture or missing operating system: `{}`", diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index ea51dda6038cf..a78cf273e6ac7 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -27,7 +27,7 @@ use syntax::parse::ParseSess; use syntax::{abi, ast, codemap}; use syntax; -use mach_triple::Triple; +use machine::triple::Triple; use std::cell::{Cell, RefCell}; use std::default::Default; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 740e304bf8e02..43dc4a4a3a2c4 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -40,7 +40,7 @@ extern crate getopts; extern crate collections; extern crate time; extern crate libc; -extern crate mach_triple; +extern crate machine; #[phase(syntax, link)] extern crate log; diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index 0d4b6895f55a8..3b3c93530da26 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -13,7 +13,7 @@ use std::cast; use syntax::crateid::CrateId; use back::svh::Svh; -use mach_triple; +use machine; // EBML enum definitions and utils shared by the encoder and decoder @@ -205,5 +205,5 @@ pub static tag_crate_target: uint = 0x66; pub struct LinkMeta { pub crateid: CrateId, pub crate_hash: Svh, - pub target: mach_triple::Triple, + pub target: machine::triple::Triple, } diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 450beadf0c488..43a453f4abbeb 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -35,6 +35,7 @@ use syntax::parse::token::{IdentInterner, InternedString}; use syntax::parse::token; use syntax::crateid::CrateId; use syntax::visit; +use machine; struct Env<'a> { sess: &'a Session, @@ -212,7 +213,7 @@ fn visit_item(e: &Env, i: &ast::Item) { Some(k) => { if k.equiv(&("static")) { cstore::NativeStatic - } else if e.sess.target_os() == abi::OsMacos && + } else if e.sess.target_os() == machine::abi::OsMacos && k.equiv(&("framework")) { cstore::NativeFramework } else if k.equiv(&("framework")) { diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index e9247a0681e72..a41e11febc9b3 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -25,7 +25,7 @@ use middle::ty::{ImplContainer, TraitContainer}; use middle::ty; use middle::typeck; use middle::astencode::vtable_decoder_helpers; -use mach_triple; +use machine::triple; use std::u64; use std::hash; @@ -1133,13 +1133,13 @@ pub fn get_crate_id(data: &[u8]) -> CrateId { from_str(hashdoc.as_str_slice()).unwrap() } -pub fn maybe_get_crate_target(data: &[u8]) -> Option { +pub fn maybe_get_crate_target(data: &[u8]) -> Option { let cratedoc = reader::Doc(data); reader::maybe_get_doc(cratedoc, tag_crate_target).and_then(|doc| { from_str(doc.as_str_slice()) }) } -pub fn get_crate_target(data: &[u8]) -> mach_triple::Triple { +pub fn get_crate_target(data: &[u8]) -> triple::Triple { let cratedoc = reader::Doc(data); let doc = reader::get_doc(cratedoc, tag_crate_target); from_str(doc.as_str_slice()).unwrap() diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 0574a1a86dddf..8bca82cda28ea 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -24,7 +24,7 @@ use middle::ty; use middle::typeck; use middle; use util::nodemap::{NodeMap, NodeSet}; -use mach_triple; +use machine::triple; use serialize::Encodable; use std::cast; @@ -1708,7 +1708,7 @@ fn encode_crate_id(ebml_w: &mut Encoder, crate_id: &CrateId) { ebml_w.end_tag(); } -fn encode_crate_target(ebml_w: &mut Encoder, triple: &mach_triple::Triple) { +fn encode_crate_target(ebml_w: &mut Encoder, triple: &triple::Triple) { ebml_w.start_tag(tag_crate_target); ebml_w.writer.write(triple.full.as_bytes()); ebml_w.end_tag(); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 4524b43a15849..7b2a35059cc9a 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::{os, clone}; use std::io::fs; use collections::HashSet; -use mach_triple::Triple; +use machine::triple::Triple; use myfs = util::fs; diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 702601bcef218..b12642d3b331c 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -23,7 +23,7 @@ use syntax::diagnostic::SpanHandler; use syntax::parse::token::IdentInterner; use syntax::crateid::CrateId; use syntax::attr::AttrMetaMethods; -use syntax::abi::{Os, OsLinux, OsMacos, OsWin32, OsAndroid, OsFreebsd}; +use machine::abi::{Os, OsLinux, OsMacos, OsWin32, OsAndroid, OsFreebsd}; use std::c_str::ToCStr; use std::cast; diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 405559f84beb8..fd53e621da69d 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -57,7 +57,7 @@ use middle::trans::type_::Type; use middle::trans::type_of; use middle::ty; use middle::ty::Disr; -use syntax::abi::{X86, X86_64, Arm, Mips}; +use machine::abi::{X86, X86_64, Arm, Mips}; use syntax::ast; use syntax::attr; use syntax::attr::IntType; diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 3e1e735974b88..4e89b0b1cdf74 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -75,7 +75,8 @@ use libc::c_uint; use std::c_str::ToCStr; use std::cell::{Cell, RefCell}; use std::local_data; -use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic}; +use machine::abi::{X86, X86_64, Arm, Mips}; +use syntax::abi::{Rust, RustIntrinsic}; use syntax::ast_util::{local_def, is_local}; use syntax::attr::AttrMetaMethods; use syntax::attr; diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 3ae184995cdc4..c98be044f6332 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -16,7 +16,7 @@ use middle::trans::cabi_x86_64; use middle::trans::cabi_arm; use middle::trans::cabi_mips; use middle::trans::type_::Type; -use syntax::abi::{X86, X86_64, Arm, Mips}; +use machine::abi::{X86, X86_64, Arm, Mips}; #[deriving(Clone, Eq)] pub enum ArgKind { diff --git a/src/librustc/middle/trans/cabi_x86.rs b/src/librustc/middle/trans/cabi_x86.rs index 8f9cc94cbbe0c..4b97931667032 100644 --- a/src/librustc/middle/trans/cabi_x86.rs +++ b/src/librustc/middle/trans/cabi_x86.rs @@ -9,7 +9,7 @@ // except according to those terms. -use syntax::abi::{OsWin32, OsMacos}; +use machine::abi::{OsWin32, OsMacos}; use lib::llvm::*; use super::cabi::*; use super::common::*; diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index ca3a38d5adb24..8ea2dba7ec776 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -151,8 +151,9 @@ use std::ptr; use std::slice; use std::strbuf::StrBuf; use std::sync::atomics; +use machine::abi; use syntax::codemap::{Span, Pos}; -use syntax::{abi, ast, codemap, ast_util, ast_map}; +use syntax::{ast, codemap, ast_util, ast_map}; use syntax::owned_slice::OwnedSlice; use syntax::parse::token; use syntax::parse::token::special_idents; diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index 4e609f7fdae23..4b830ea77e8a9 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -16,7 +16,7 @@ use lib::llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; use middle::trans::context::CrateContext; use syntax::ast; -use syntax::abi::{X86, X86_64, Arm, Mips}; +use machine::abi::{X86, X86_64, Arm, Mips}; use std::c_str::ToCStr; use std::cast; diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 4bbf8ca23c12c..b086183adb931 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -8,37 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::fmt; -use std::from_str; - -#[deriving(Eq, Hash, Clone, TotalEq)] -pub enum Os { OsWin32, OsMacos, OsLinux, OsAndroid, OsFreebsd, } - -impl from_str::FromStr for Os { - fn from_str(s: &str) -> Option { - match s { - "mingw32" => Some(OsWin32), - "win32" => Some(OsWin32), - "darwin" => Some(OsMacos), - "android" => Some(OsAndroid), - "linux" => Some(OsLinux), - "freebsd" => Some(OsFreebsd), - _ => None, - } - } -} +// It is my opinion that all of this should have been moved to libmachine, +// however rustc would barf when a type used Abi (from libmachine) while also +// #[deriving(Hash)] when I tried to do that. So, I've left Abi here. -impl fmt::Show for Os { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &OsWin32 => "win32".fmt(f), - &OsMacos => "darwin".fmt(f), - &OsLinux => "linux".fmt(f), - &OsAndroid => "android".fmt(f), - &OsFreebsd => "freebsd".fmt(f), - } - } -} +use std::fmt; +use machine::abi; +pub use machine::abi::Os; +pub use machine::abi::Architecture; #[deriving(Eq, TotalEq, Hash, Encodable, Decodable, Clone)] pub enum Abi { @@ -59,33 +36,6 @@ pub enum Abi { RustIntrinsic, } -#[allow(non_camel_case_types)] -#[deriving(Eq, Clone, Hash, TotalEq)] -pub enum Architecture { - // NB. You cannot change the ordering of these - // constants without adjusting IntelBits below. - // (This is ensured by the test indices_are_correct().) - X86, - X86_64, - Arm, - Mips -} -impl from_str::FromStr for Architecture { - fn from_str(s: &str) -> Option { - match s { - "i386" | "i486" | "i586" | "i686" | "i786" => Some(X86), - "x86_64" => Some(X86_64), - "arm" | "xscale" | "thumb" => Some(Arm), - "mips" => Some(Mips), - _ => None, - } - } -} - - -static IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); -static ArmBits: u32 = (1 << (Arm as uint)); - pub struct AbiData { abi: Abi, @@ -105,12 +55,12 @@ pub enum AbiArchitecture { static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs - AbiData {abi: Cdecl, name: "cdecl", abi_arch: Archs(IntelBits)}, - AbiData {abi: Stdcall, name: "stdcall", abi_arch: Archs(IntelBits)}, - AbiData {abi: Fastcall, name:"fastcall", abi_arch: Archs(IntelBits)}, - AbiData {abi: Aapcs, name: "aapcs", abi_arch: Archs(ArmBits)}, + AbiData {abi: Cdecl, name: "cdecl", abi_arch: Archs(abi::IntelBits)}, + AbiData {abi: Stdcall, name: "stdcall", abi_arch: Archs(abi::IntelBits)}, + AbiData {abi: Fastcall, name:"fastcall", abi_arch: Archs(abi::IntelBits)}, + AbiData {abi: Aapcs, name: "aapcs", abi_arch: Archs(abi::ArmBits)}, AbiData {abi: Win64, name: "win64", - abi_arch: Archs(1 << (X86_64 as uint))}, + abi_arch: Archs(1 << (abi::X86_64 as uint))}, // Cross-platform ABIs // @@ -169,7 +119,7 @@ impl Abi { self.data().name } - pub fn for_target(&self, os: Os, arch: Architecture) -> Option { + pub fn for_target(&self, os: abi::Os, arch: abi::Architecture) -> Option { // If this ABI isn't actually for the specified architecture, then we // short circuit early match self.data().abi_arch { @@ -179,14 +129,18 @@ impl Abi { // Transform this ABI as appropriate for the requested os/arch // combination. Some(match (*self, os, arch) { - (System, OsWin32, X86) => Stdcall, + (System, abi::OsWin32, abi::X86) => Stdcall, (System, _, _) => C, (me, _, _) => me, }) } } -impl Architecture { +trait ArchBit { + fn bit(&self) -> u32; +} + +impl ArchBit for Architecture { fn bit(&self) -> u32 { 1 << (*self as u32) } @@ -222,16 +176,18 @@ fn indices_are_correct() { assert_eq!(i, abi_data.abi.index()); } - let bits = 1 << (X86 as u32); - let bits = bits | 1 << (X86_64 as u32); - assert_eq!(IntelBits, bits); + let bits = 1 << (abi::X86 as u32); + let bits = bits | 1 << (abi::X86_64 as u32); + assert_eq!(abi::IntelBits, bits); - let bits = 1 << (Arm as u32); - assert_eq!(ArmBits, bits); + let bits = 1 << (abi::Arm as u32); + assert_eq!(abi::ArmBits, bits); } #[test] fn pick_uniplatform() { + use machine::abi::{OsLinux, OsWin32, + X86, X86_64, Arm}; assert_eq!(Stdcall.for_target(OsLinux, X86), Some(Stdcall)); assert_eq!(Stdcall.for_target(OsLinux, Arm), None); assert_eq!(System.for_target(OsLinux, X86), Some(C)); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 012bc50ecabc8..2e1b272decc05 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -35,6 +35,7 @@ extern crate term; extern crate collections; #[phase(syntax, link)] extern crate log; +extern crate machine; pub mod util { pub mod interner; From bb6e441a51503ef1c579f95d90bf346b2c2e69d8 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Fri, 11 Apr 2014 10:18:18 -0500 Subject: [PATCH 14/18] Use libmachine/triple in compiletest. --- src/compiletest/common.rs | 17 +- src/compiletest/compiletest.rs | 19 +- src/compiletest/header.rs | 33 ++-- src/compiletest/runtest.rs | 306 ++++++++++++++++++--------------- 4 files changed, 217 insertions(+), 158 deletions(-) diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index ea6e98fafa7cd..65754c52b0a44 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use machine::triple::Triple; + #[deriving(Clone, Eq)] pub enum mode { mode_compile_fail, @@ -87,10 +89,10 @@ pub struct config { pub jit: bool, // Target system to be tested - pub target: ~str, + pub target: Triple, // Host triple for the compiler being invoked - pub host: ~str, + pub host: Triple, // Extra parameter to run adb on arm-linux-androideabi pub adb_path: ~str, @@ -105,3 +107,14 @@ pub struct config { pub verbose: bool } + +impl config { + pub fn is_cross_compile(&self) -> bool { + self.target != self.host + } + + pub fn is_target_android(&self) -> bool { + self.target.is_android() + } +} + diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index d2499ea33bdd6..98b57e32e3282 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -23,6 +23,7 @@ extern crate getopts; extern crate log; extern crate green; extern crate rustuv; +extern crate machine; use std::os; use std::io; @@ -58,6 +59,8 @@ pub fn main() { } pub fn parse_config(args: Vec<~str> ) -> config { + use std::from_str::FromStr; + use std::default::Default; let groups : Vec = vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"), @@ -145,8 +148,18 @@ pub fn parse_config(args: Vec<~str> ) -> config { host_rustcflags: matches.opt_str("host-rustcflags"), target_rustcflags: matches.opt_str("target-rustcflags"), jit: matches.opt_present("jit"), - target: opt_str2(matches.opt_str("target")).to_str(), - host: opt_str2(matches.opt_str("host")).to_str(), + target: matches + .opt_str("target") + .and_then(|triple| { + FromStr::from_str(triple) + }) + .unwrap_or_else(|| Default::default() ), + host: matches + .opt_str("host") + .and_then(|triple| { + FromStr::from_str(triple) + }) + .unwrap_or_else(|| Default::default() ), adb_path: opt_str2(matches.opt_str("adb-path")).to_str(), adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")).to_str(), @@ -226,7 +239,7 @@ pub fn mode_str(mode: mode) -> ~str { } pub fn run_tests(config: &config) { - if config.target == ~"arm-linux-androideabi" { + if config.is_target_android() { match config.mode{ mode_debug_info => { println!("arm-linux-androideabi debug-info \ diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index b45a68518a3ec..5f1145708264c 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -10,7 +10,6 @@ use common::config; use common; -use util; pub struct TestProps { // Lines that should be expected, in order, on standard out @@ -28,8 +27,13 @@ pub struct TestProps { pub debugger_cmds: Vec<~str> , // Lines to check if they appear in the expected debugger output pub check_lines: Vec<~str> , - // Flag to force a crate to be built with the host architecture - pub force_host: bool, + // Flag to additionally build a crate for the host architecture + // Used for some aux crates that export syntax extensions. + pub needs_host: bool, + // Flag for syntax extensions aux' that use libsyntax (a host crate, + // so therefore can't, for the time being, target the target). + // Ignored on non-aux crates && implies needs-host. + pub only_host: bool, // Check stdout for error-pattern output as well as stderr pub check_stdout: bool, // Don't force a --crate-type=dylib flag on the command line @@ -45,7 +49,8 @@ pub fn load_props(testfile: &Path) -> TestProps { let mut pp_exact = None; let mut debugger_cmds = Vec::new(); let mut check_lines = Vec::new(); - let mut force_host = false; + let mut needs_host = false; + let mut only_host = false; let mut check_stdout = false; let mut no_prefer_dynamic = false; iter_header(testfile, |ln| { @@ -62,8 +67,11 @@ pub fn load_props(testfile: &Path) -> TestProps { pp_exact = parse_pp_exact(ln, testfile); } - if !force_host { - force_host = parse_force_host(ln); + if !needs_host { + needs_host = parse_needs_host(ln); + } + if !only_host { + only_host = parse_only_host(ln); } if !check_stdout { @@ -104,7 +112,8 @@ pub fn load_props(testfile: &Path) -> TestProps { exec_env: exec_env, debugger_cmds: debugger_cmds, check_lines: check_lines, - force_host: force_host, + needs_host: needs_host, + only_host: only_host, check_stdout: check_stdout, no_prefer_dynamic: no_prefer_dynamic, }; @@ -112,7 +121,7 @@ pub fn load_props(testfile: &Path) -> TestProps { pub fn is_test_ignored(config: &config, testfile: &Path) -> bool { fn ignore_target(config: &config) -> ~str { - ~"ignore-" + util::get_os(config.target) + ~"ignore-" + config.target.expect_known_os().to_str() } fn ignore_stage(config: &config) -> ~str { ~"ignore-" + config.stage_id.split('-').next().unwrap() @@ -168,8 +177,12 @@ fn parse_check_line(line: &str) -> Option<~str> { parse_name_value_directive(line, ~"check") } -fn parse_force_host(line: &str) -> bool { - parse_name_directive(line, "force-host") +fn parse_needs_host(line: &str) -> bool { + parse_name_directive(line, "needs-host") +} + +fn parse_only_host(line: &str) -> bool { + parse_name_directive(line, "only-host") } fn parse_check_stdout(line: &str) -> bool { diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 1885f20bd8853..4d6bada286e0f 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -38,15 +38,10 @@ use test::MetricMap; pub fn run(config: config, testfile: ~str) { - match config.target.as_slice() { - - "arm-linux-androideabi" => { - if !config.adb_device_status { - fail!("android device not available"); - } + if config.is_target_android() { + if !config.adb_device_status { + fail!("android device not available"); } - - _=> { } } let mut _mm = MetricMap::new(); @@ -209,7 +204,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { fn make_pp_args(config: &config, _testfile: &Path) -> ProcArgs { let args = vec!(~"-", ~"--pretty", ~"normal", - ~"--target=" + config.target); + ~"--target=" + config.target.full); // FIXME (#9639): This needs to handle non-utf8 paths return ProcArgs {prog: config.rustc_path.as_str().unwrap().to_owned(), args: args}; } @@ -240,11 +235,8 @@ actual:\n\ fn make_typecheck_args(config: &config, props: &TestProps, testfile: &Path) -> ProcArgs { let aux_dir = aux_output_dir_name(config, testfile); - let target = if props.force_host { - config.host.as_slice() - } else { - config.target.as_slice() - }; + // Trans isn't run, so technically target flags are irrelevant. I think... + let target = config.target.full.as_slice(); // FIXME (#9639): This needs to handle non-utf8 paths let mut args = vec!(~"-", ~"--no-trans", ~"--crate-type=lib", @@ -279,119 +271,114 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { let exe_file = make_exe_name(config, testfile); let mut proc_args; - match config.target.as_slice() { - "arm-linux-androideabi" => { - - cmds = cmds.replace("run","continue"); - - // write debugger script - let script_str = [~"set charset UTF-8", - format!("file {}",exe_file.as_str().unwrap().to_owned()), - ~"target remote :5039", - cmds, - ~"quit"].connect("\n"); - debug!("script_str = {}", script_str); - dump_output_file(config, testfile, script_str, "debugger.script"); - - - procsrv::run("", config.adb_path, - [~"push", exe_file.as_str().unwrap().to_owned(), - config.adb_test_dir.clone()], - vec!((~"",~"")), Some(~"")) - .expect(format!("failed to exec `{}`", config.adb_path)); - - procsrv::run("", config.adb_path, - [~"forward", ~"tcp:5039", ~"tcp:5039"], - vec!((~"",~"")), Some(~"")) - .expect(format!("failed to exec `{}`", config.adb_path)); - - let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}", - config.adb_test_dir.clone(), config.adb_test_dir.clone(), - str::from_utf8(exe_file.filename().unwrap()).unwrap()); - - let mut process = procsrv::run_background("", config.adb_path, - [~"shell",adb_arg.clone()], - vec!((~"",~"")), Some(~"")) - .expect(format!("failed to exec `{}`", config.adb_path)); - loop { - //waiting 1 second for gdbserver start - timer::sleep(1000); - let result = task::try(proc() { - tcp::TcpStream::connect(SocketAddr { - ip: Ipv4Addr(127, 0, 0, 1), - port: 5039, - }).unwrap(); - }); - if result.is_err() { - continue; - } - break; - } + if config.is_target_android() { + cmds = cmds.replace("run","continue"); + + // write debugger script + let script_str = [~"set charset UTF-8", + format!("file {}", exe_file.as_str().unwrap().to_owned()), + ~"target remote :5039", + cmds, + ~"quit"].connect("\n"); + debug!("script_str = {}", script_str); + dump_output_file(config, testfile, script_str, "debugger.script"); + + + procsrv::run("", config.adb_path, + [~"push", exe_file.as_str().unwrap().to_owned(), + config.adb_test_dir.clone()], + vec!((~"",~"")), Some(~"")) + .expect(format!("failed to exec `{}`", config.adb_path)); - let args = split_maybe_args(&config.target_rustcflags); - let mut tool_path = StrBuf::new(); - for arg in args.iter() { - if arg.contains("android-cross-path=") { - tool_path = StrBuf::from_str(arg.replace("android-cross-path=", "")); - break; - } + procsrv::run("", config.adb_path, + [~"forward", ~"tcp:5039", ~"tcp:5039"], + vec!((~"",~"")), Some(~"")) + .expect(format!("failed to exec `{}`", config.adb_path)); + + let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}", + config.adb_test_dir.clone(), config.adb_test_dir.clone(), + str::from_utf8(exe_file.filename().unwrap()).unwrap()); + + let mut process = procsrv::run_background("", config.adb_path, + [~"shell", adb_arg.clone()], + vec!((~"",~"")), Some(~"")) + .expect(format!("failed to exec `{}`", config.adb_path)); + loop { + //waiting 1 second for gdbserver start + timer::sleep(1000); + let result = task::try(proc() { + tcp::TcpStream::connect(SocketAddr { + ip: Ipv4Addr(127, 0, 0, 1), + port: 5039, + }).unwrap(); + }); + if result.is_err() { + continue; } + break; + } - if tool_path.is_empty() { - fatal(~"cannot found android cross path"); + let args = split_maybe_args(&config.target_rustcflags); + let mut tool_path = StrBuf::new(); + for arg in args.iter() { + if arg.contains("android-cross-path=") { + tool_path = StrBuf::from_str(arg.replace("android-cross-path=", "")); + break; } + } - let debugger_script = make_out_name(config, testfile, "debugger.script"); - // FIXME (#9639): This needs to handle non-utf8 paths - let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", - "-command=" + debugger_script.as_str().unwrap().to_owned()); - - let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb"); - let procsrv::Result{ out, err, status }= - procsrv::run("", - gdb_path.as_slice(), - debugger_opts.as_slice(), - vec!((~"",~"")), - None) - .expect(format!("failed to exec `{}`", gdb_path)); - let cmdline = { - let cmdline = make_cmdline("", - "arm-linux-androideabi-gdb", - debugger_opts.as_slice()); - logv(config, format!("executing {}", cmdline)); - cmdline - }; - - proc_res = ProcRes {status: status, - stdout: out, - stderr: err, - cmdline: cmdline}; - process.signal_kill().unwrap(); + if tool_path.is_empty() { + fatal(~"cannot found android cross path"); } - _=> { - // write debugger script - let script_str = [~"set charset UTF-8", - cmds, - ~"quit\n"].connect("\n"); - debug!("script_str = {}", script_str); - dump_output_file(config, testfile, script_str, "debugger.script"); + let debugger_script = make_out_name(config, testfile, "debugger.script"); + // FIXME (#9639): This needs to handle non-utf8 paths + let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", + "-command=" + debugger_script.as_str().unwrap().to_owned()); + + let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb"); + let procsrv::Result { out, err, status } = + procsrv::run("", + gdb_path.as_slice(), + debugger_opts.as_slice(), + vec!((~"",~"")), + None) + .expect(format!("failed to exec `{}`", gdb_path)); + let cmdline = { + let cmdline = make_cmdline("", + "arm-linux-androideabi-gdb", + debugger_opts.as_slice()); + logv(config, format!("executing {}", cmdline)); + cmdline + }; - // run debugger script with gdb - #[cfg(windows)] - fn debugger() -> ~str { ~"gdb.exe" } - #[cfg(unix)] - fn debugger() -> ~str { ~"gdb" } + proc_res = ProcRes {status: status, + stdout: out, + stderr: err, + cmdline: cmdline}; + process.signal_kill().unwrap(); + } else { + // write debugger script + let script_str = [~"set charset UTF-8", + cmds, + ~"quit\n"].connect("\n"); + debug!("script_str = {}", script_str); + dump_output_file(config, testfile, script_str, "debugger.script"); - let debugger_script = make_out_name(config, testfile, "debugger.script"); + // run debugger script with gdb + #[cfg(windows)] + fn debugger() -> ~str { ~"gdb.exe" } + #[cfg(unix)] + fn debugger() -> ~str { ~"gdb" } - // FIXME (#9639): This needs to handle non-utf8 paths - let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", - "-command=" + debugger_script.as_str().unwrap().to_owned(), - exe_file.as_str().unwrap().to_owned()); - proc_args = ProcArgs {prog: debugger(), args: debugger_opts}; - proc_res = compose_and_run(config, testfile, proc_args, Vec::new(), "", None); - } + let debugger_script = make_out_name(config, testfile, "debugger.script"); + + // FIXME (#9639): This needs to handle non-utf8 paths + let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", + "-command=" + debugger_script.as_str().unwrap().to_owned(), + exe_file.as_str().unwrap().to_owned()); + proc_args = ProcArgs {prog: debugger(), args: debugger_opts}; + proc_res = compose_and_run(config, testfile, proc_args, Vec::new(), "", None); } if !proc_res.status.success() { @@ -693,18 +680,13 @@ fn exec_compiled_test(config: &config, props: &TestProps, let env = props.exec_env.clone(); - match config.target.as_slice() { - - "arm-linux-androideabi" => { - _arm_exec_compiled_test(config, props, testfile, env) - } - - _=> { - compose_and_run(config, testfile, - make_run_args(config, props, testfile), - env, - config.run_lib_path, None) - } + if config.is_target_android() { + _arm_exec_compiled_test(config, props, testfile, env) + } else { + compose_and_run(config, testfile, + make_run_args(config, props, testfile), + env, + config.run_lib_path, None) } } @@ -712,7 +694,7 @@ fn compose_and_run_compiler( config: &config, props: &TestProps, testfile: &Path, - args: ProcArgs, + mut args: ProcArgs, input: Option<~str>) -> ProcRes { if !props.aux_builds.is_empty() { @@ -726,36 +708,74 @@ fn compose_and_run_compiler( for rel_ab in props.aux_builds.iter() { let abs_ab = config.aux_base.join(rel_ab.as_slice()); let aux_props = load_props(&abs_ab); - let crate_type = if aux_props.no_prefer_dynamic { + if !aux_props.only_host { + let crate_type = if aux_props.no_prefer_dynamic { + Vec::new() + } else { + vec!(~"--crate-type=dylib") + }; + let aux_args = + make_compile_args(config, + TargetBuild, + &aux_props, + crate_type.append(extra_link_args.as_slice()), + |a,b| { + let f = make_lib_name(a, b, testfile); + ThisDirectory(f.dir_path()) + }, &abs_ab); + let auxres = compose_and_run(config, &abs_ab, aux_args, Vec::new(), + config.compile_lib_path, None); + if !auxres.status.success() { + fatal_ProcRes( + format!("auxiliary build of {} failed to compile (target): ", + abs_ab.display()), + &auxres); + } + + if config.is_target_android() { + _arm_push_aux_shared_library(config, testfile); + } + // now, if the aux has flagged that it additionally needs to be + // built for the host, do so now, else continue the loop. + if !aux_props.needs_host || !config.is_cross_compile() { + continue; + } + } + + let outdir_suffix = "host"; + let mut aux_args = if aux_props.no_prefer_dynamic { Vec::new() } else { vec!(~"--crate-type=dylib") }; + aux_args.push(~"-L"); + aux_args.push(config.compile_lib_path.to_str()); + aux_args.push(~"--sysroot=."); let aux_args = make_compile_args(config, + HostBuild, &aux_props, - crate_type.append(extra_link_args.as_slice()), + aux_args.append(extra_link_args.as_slice()), |a,b| { let f = make_lib_name(a, b, testfile); - ThisDirectory(f.dir_path()) + let f = f.dir_path().with_extension(outdir_suffix); + ensure_dir(&f); + ThisDirectory(f) }, &abs_ab); let auxres = compose_and_run(config, &abs_ab, aux_args, Vec::new(), config.compile_lib_path, None); if !auxres.status.success() { fatal_ProcRes( - format!("auxiliary build of {} failed to compile: ", + format!("auxiliary build of {} failed to compile (target): ", abs_ab.display()), &auxres); } - - match config.target.as_slice() { - - "arm-linux-androideabi" => { - _arm_push_aux_shared_library(config, testfile); - } - - _=> { } - } + // now add the host crate's output dir to the tests arguments: + let outdir = make_lib_name(config, testfile, testfile) + .dir_path() + .with_extension(outdir_suffix); + args.args.push(~"-L"); + args.args.push(outdir.display().to_str()); } compose_and_run(config, testfile, args, Vec::new(), From f26cd3c4f4d5351d57e7c3f3acb5a9d25d0d6862 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Fri, 11 Apr 2014 10:19:00 -0500 Subject: [PATCH 15/18] Fixed passing wrong rustcflags to compiletest. --- mk/tests.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/tests.mk b/mk/tests.mk index c134e71986f40..b14b5a5152776 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -568,7 +568,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --host $(3) \ --adb-path=$(CFG_ADB) \ --adb-test-dir=$(CFG_ADB_TEST_DIR) \ - --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ + --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \ --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ $$(CTEST_TESTARGS) From 56f02f66b34f9ac5fbc5cdc5f50c3b88a23fd37e Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Sat, 12 Apr 2014 06:43:22 -0500 Subject: [PATCH 16/18] Fix test warnings. --- src/libmachine/triple.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libmachine/triple.rs b/src/libmachine/triple.rs index 3795ae457fb88..afbcd3243a067 100644 --- a/src/libmachine/triple.rs +++ b/src/libmachine/triple.rs @@ -250,14 +250,13 @@ impl cmp::Eq for Triple { #[cfg(test)] mod test { - use super::{Triple, Known, + use super::{Triple, UnknownVendor, GnuEnv, GnuDefault, AndroidEAbiEnv, MsvcEnv}; use abi; use std::to_str::ToStr; use std::from_str::FromStr; - use std::fmt::Show; #[test] fn x86_64_unknown_linux_gnu() { @@ -322,7 +321,7 @@ mod test { #[test] #[should_fail] fn unknownarch_unknown_linux_gnu() { let original = "unknownarch-unknown-linux-gnu"; - let triple: Triple = FromStr::from_str(original).unwrap(); + let _: Triple = FromStr::from_str(original).unwrap(); } #[test] fn x86_64_ununknown_linux_gnu() { @@ -383,11 +382,11 @@ mod test { #[test] #[should_fail] fn blank() { let original = ""; - let triple: Triple = FromStr::from_str(original).unwrap(); + let _: Triple = FromStr::from_str(original).unwrap(); } #[test] #[should_fail] fn blank_hyphen() { let original = "-"; - let triple: Triple = FromStr::from_str(original).unwrap(); + let _: Triple = FromStr::from_str(original).unwrap(); } } From 00445602c67116afa6981be40e1710a9b59f1046 Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Sat, 12 Apr 2014 06:50:27 -0500 Subject: [PATCH 17/18] Compiletest: if flagged, build for both target & host. --- src/compiletest/common.rs | 5 +++++ src/compiletest/runtest.rs | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index 65754c52b0a44..7ea38c28bf751 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -118,3 +118,8 @@ impl config { } } +#[deriving(Clone, Eq, Hash, TotalEq)] +pub enum BuildFor { + TargetBuild, + HostBuild, +} diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 4d6bada286e0f..8fed22fac13f4 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -13,6 +13,7 @@ use common::mode_compile_fail; use common::mode_pretty; use common::mode_run_fail; use common::mode_run_pass; +use common::{BuildFor, TargetBuild, HostBuild}; use errors; use header::TestProps; use header::load_props; @@ -669,6 +670,7 @@ fn compile_test_(config: &config, props: &TestProps, // FIXME (#9639): This needs to handle non-utf8 paths let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned()); let args = make_compile_args(config, + TargetBuild, props, link_args.append(extra_args), |a, b| ThisFile(make_exe_name(a, b)), testfile); @@ -766,7 +768,7 @@ fn compose_and_run_compiler( config.compile_lib_path, None); if !auxres.status.success() { fatal_ProcRes( - format!("auxiliary build of {} failed to compile (target): ", + format!("auxiliary build of {} failed to compile (host): ", abs_ab.display()), &auxres); } @@ -802,16 +804,16 @@ enum TargetLocation { } fn make_compile_args(config: &config, + build_for: BuildFor, props: &TestProps, extras: Vec<~str> , xform: |&config, &Path| -> TargetLocation, testfile: &Path) -> ProcArgs { let xform_file = xform(config, testfile); - let target = if props.force_host { - config.host.as_slice() - } else { - config.target.as_slice() + let target = match build_for { + TargetBuild => config.target.full.as_slice(), + HostBuild => config.host.full.as_slice(), }; // FIXME (#9639): This needs to handle non-utf8 paths let mut args = vec!(testfile.as_str().unwrap().to_owned(), @@ -827,11 +829,10 @@ fn make_compile_args(config: &config, ThisDirectory(path) => { args.push(~"--out-dir"); path } }; args.push(path.as_str().unwrap().to_owned()); - if props.force_host { - args.push_all_move(split_maybe_args(&config.host_rustcflags)); - } else { - args.push_all_move(split_maybe_args(&config.target_rustcflags)); - } + match build_for { + HostBuild => args.push_all_move(split_maybe_args(&config.host_rustcflags)), + TargetBuild => args.push_all_move(split_maybe_args(&config.target_rustcflags)), + }; args.push_all_move(split_maybe_args(&props.compile_flags)); return ProcArgs {prog: config.rustc_path.as_str().unwrap().to_owned(), args: args}; } @@ -1126,6 +1127,7 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps, let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned()); let llvm_args = vec!(~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps"); let args = make_compile_args(config, + TargetBuild, props, link_args.append(llvm_args.as_slice()), |a, b| ThisFile(make_o_name(a, b)), testfile); From 6688d0323ae5d52a0cf5e0cc591e0d34e7d8f67f Mon Sep 17 00:00:00 2001 From: Richard Diamond Date: Thu, 17 Apr 2014 07:18:43 -0500 Subject: [PATCH 18/18] Update tests. --- src/test/auxiliary/macro_crate_def_only.rs | 1 + .../auxiliary/macro_crate_outlive_expansion_phase.rs | 2 +- src/test/auxiliary/macro_crate_test.rs | 2 +- src/test/auxiliary/macro_export_inner_module.rs | 1 + .../compile-fail/macro-crate-unexported-macro.rs | 2 -- src/test/compile-fail/phase-syntax-doesnt-resolve.rs | 2 -- .../compile-fail/syntax-extension-fourcc-bad-len.rs | 1 - .../syntax-extension-fourcc-invalid-endian.rs | 1 - .../syntax-extension-fourcc-non-ascii-str.rs | 1 - .../syntax-extension-fourcc-non-literal.rs | 1 - .../syntax-extension-fourcc-unsupported-literal.rs | 1 - .../syntax-extension-hexfloat-bad-lits.rs | 1 - .../syntax-extension-hexfloat-bad-types.rs | 1 - .../macro-crate-outlive-expansion-phase.rs | 2 -- src/test/run-pass-fulldeps/macro-crate.rs | 1 - .../phase-syntax-link-does-resolve.rs | 12 +----------- .../run-pass-fulldeps/quote-unused-sp-no-warning.rs | 3 ++- .../run-pass-fulldeps/syntax-extension-fourcc.rs | 1 - .../run-pass-fulldeps/syntax-extension-hexfloat.rs | 1 - 19 files changed, 7 insertions(+), 30 deletions(-) diff --git a/src/test/auxiliary/macro_crate_def_only.rs b/src/test/auxiliary/macro_crate_def_only.rs index 56053a0cd7520..1e0c6617edcd6 100644 --- a/src/test/auxiliary/macro_crate_def_only.rs +++ b/src/test/auxiliary/macro_crate_def_only.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// needs-host #![feature(macro_rules)] #[macro_export] diff --git a/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs b/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs index 4e933be509256..c6d0f9b0ec8e3 100644 --- a/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs +++ b/src/test/auxiliary/macro_crate_outlive_expansion_phase.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// force-host +// only-host #![feature(macro_registrar)] diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index 070bb6dfcb793..440e72c7344fc 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// force-host +// only-host #![feature(globs, macro_registrar, macro_rules, quote, managed_boxes)] diff --git a/src/test/auxiliary/macro_export_inner_module.rs b/src/test/auxiliary/macro_export_inner_module.rs index 1e8c15f6b44cb..4171dd13f5e94 100644 --- a/src/test/auxiliary/macro_export_inner_module.rs +++ b/src/test/auxiliary/macro_export_inner_module.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// needs-host #![feature(macro_rules)] pub mod inner { diff --git a/src/test/compile-fail/macro-crate-unexported-macro.rs b/src/test/compile-fail/macro-crate-unexported-macro.rs index 6f4c450940e0f..f4ceca9d35ec5 100644 --- a/src/test/compile-fail/macro-crate-unexported-macro.rs +++ b/src/test/compile-fail/macro-crate-unexported-macro.rs @@ -10,8 +10,6 @@ // aux-build:macro_crate_test.rs // ignore-stage1 -// ignore-android -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/phase-syntax-doesnt-resolve.rs b/src/test/compile-fail/phase-syntax-doesnt-resolve.rs index 9bfc7fc34bb5b..385f9dcf92370 100644 --- a/src/test/compile-fail/phase-syntax-doesnt-resolve.rs +++ b/src/test/compile-fail/phase-syntax-doesnt-resolve.rs @@ -10,8 +10,6 @@ // aux-build:macro_crate_test.rs // ignore-stage1 -// ignore-android -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-fourcc-bad-len.rs b/src/test/compile-fail/syntax-extension-fourcc-bad-len.rs index 865ab7e6e84b6..fbcdf55f1acbf 100644 --- a/src/test/compile-fail/syntax-extension-fourcc-bad-len.rs +++ b/src/test/compile-fail/syntax-extension-fourcc-bad-len.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-fourcc-invalid-endian.rs b/src/test/compile-fail/syntax-extension-fourcc-invalid-endian.rs index c127035bf1e45..569b54b93fb09 100644 --- a/src/test/compile-fail/syntax-extension-fourcc-invalid-endian.rs +++ b/src/test/compile-fail/syntax-extension-fourcc-invalid-endian.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-fourcc-non-ascii-str.rs b/src/test/compile-fail/syntax-extension-fourcc-non-ascii-str.rs index 28b146635f145..c0e2304354cc4 100644 --- a/src/test/compile-fail/syntax-extension-fourcc-non-ascii-str.rs +++ b/src/test/compile-fail/syntax-extension-fourcc-non-ascii-str.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-fourcc-non-literal.rs b/src/test/compile-fail/syntax-extension-fourcc-non-literal.rs index 1f1a7ab80f966..536594f306311 100644 --- a/src/test/compile-fail/syntax-extension-fourcc-non-literal.rs +++ b/src/test/compile-fail/syntax-extension-fourcc-non-literal.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-fourcc-unsupported-literal.rs b/src/test/compile-fail/syntax-extension-fourcc-unsupported-literal.rs index a745c227fb14d..8a0b0856d24de 100644 --- a/src/test/compile-fail/syntax-extension-fourcc-unsupported-literal.rs +++ b/src/test/compile-fail/syntax-extension-fourcc-unsupported-literal.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-hexfloat-bad-lits.rs b/src/test/compile-fail/syntax-extension-hexfloat-bad-lits.rs index 04b34c85b78f7..1cd4f654d2e37 100644 --- a/src/test/compile-fail/syntax-extension-hexfloat-bad-lits.rs +++ b/src/test/compile-fail/syntax-extension-hexfloat-bad-lits.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/compile-fail/syntax-extension-hexfloat-bad-types.rs b/src/test/compile-fail/syntax-extension-hexfloat-bad-types.rs index 6b2f8067ccc44..4a6475cea9672 100644 --- a/src/test/compile-fail/syntax-extension-hexfloat-bad-types.rs +++ b/src/test/compile-fail/syntax-extension-hexfloat-bad-types.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs b/src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs index f61cddace825d..58663bb44c744 100644 --- a/src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs +++ b/src/test/run-pass-fulldeps/macro-crate-outlive-expansion-phase.rs @@ -10,8 +10,6 @@ // aux-build:macro_crate_outlive_expansion_phase.rs // ignore-stage1 -// ignore-android -// ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/run-pass-fulldeps/macro-crate.rs b/src/test/run-pass-fulldeps/macro-crate.rs index 24d416a416c1e..39c7efea9351e 100644 --- a/src/test/run-pass-fulldeps/macro-crate.rs +++ b/src/test/run-pass-fulldeps/macro-crate.rs @@ -10,7 +10,6 @@ // aux-build:macro_crate_test.rs // ignore-stage1 -// ignore-android // ignore-cross-compile #12102 #![feature(phase)] diff --git a/src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs b/src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs index 1700ceaec4ffe..ac93cfdad10a1 100644 --- a/src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs +++ b/src/test/run-pass-fulldeps/phase-syntax-link-does-resolve.rs @@ -10,17 +10,7 @@ // aux-build:macro_crate_test.rs // ignore-stage1 -// ignore-android -// force-host - -// You'll note that there's lots of directives above. This is a very particular -// test in which we're both linking to a macro crate and loading macros from it. -// This implies that both versions are the host architecture, meaning this test -// must also be compiled with the host arch. -// -// because this doesn't work with that test runner, ignore-android because it -// can't run host binaries, and force-host to make this test build as the host -// arch. +// ignore-cross-compile #![feature(phase)] diff --git a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs index 5025cc12b4a64..e383a19b6805e 100644 --- a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs +++ b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-android +// ignore-cross-compile + #![feature(quote)] #![deny(unused_variable)] diff --git a/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs b/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs index 53ea4fbe0c35d..0681ec63b9ed0 100644 --- a/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs +++ b/src/test/run-pass-fulldeps/syntax-extension-fourcc.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #![feature(phase)] diff --git a/src/test/run-pass-fulldeps/syntax-extension-hexfloat.rs b/src/test/run-pass-fulldeps/syntax-extension-hexfloat.rs index 5eb6a30c01562..3601b61011598 100644 --- a/src/test/run-pass-fulldeps/syntax-extension-hexfloat.rs +++ b/src/test/run-pass-fulldeps/syntax-extension-hexfloat.rs @@ -10,7 +10,6 @@ // ignore-stage1 // ignore-pretty -// ignore-cross-compile #12102 #![feature(phase)] #[phase(syntax)]