about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2017-08-26 17:31:32 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2017-09-23 12:55:32 +0200
commitd44a256157f1773f146465107de1f211401ebf93 (patch)
tree287830a6718fda5bf9995616c53a674e547a6c7a
parentcba53f0be575196083fe52ecd2ec8f1c015664ce (diff)
downloadrust-d44a256157f1773f146465107de1f211401ebf93.tar.gz
rust-d44a256157f1773f146465107de1f211401ebf93.zip
Allow building stage 2 compiler libraries
-rw-r--r--src/bootstrap/bin/rustc.rs4
-rw-r--r--src/bootstrap/builder.rs2
-rw-r--r--src/bootstrap/compile.rs7
-rw-r--r--src/librustc_driver/driver.rs37
-rw-r--r--src/librustc_metadata/locator.rs18
-rw-r--r--src/librustc_trans/back/link.rs42
-rw-r--r--src/librustc_trans/base.rs2
-rw-r--r--src/librustc_trans/lib.rs1
-rw-r--r--src/librustc_trans_utils/link.rs35
9 files changed, 90 insertions, 58 deletions
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 848b10d312c..df9c55ce0be 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -159,6 +159,10 @@ fn main() {
             cmd.arg("-C").arg("panic=abort");
         }
 
+        if cfg!(not(feature="llvm")) && stage != "0" {
+            cmd.arg("-Zno-trans");
+        }
+
         // Set various options from config.toml to configure how we're building
         // code.
         if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 8a6c998c932..de6dd10938e 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -531,7 +531,7 @@ impl<'a> Builder<'a> {
         // For other crates, however, we know that we've already got a standard
         // library up and running, so we can use the normal compiler to compile
         // build scripts in that situation.
-        if mode == Mode::Libstd {
+        if mode == Mode::Libstd || !self.build.config.llvm_enabled {
             cargo.env("RUSTC_SNAPSHOT", &self.initial_rustc)
                  .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
         } else {
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 2e368ddf43f..335e1690a2e 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -104,11 +104,7 @@ impl Step for Std {
 
         let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
         build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
-        let mut cargo = if compiler.stage == 0 {
-            builder.cargo(compiler, Mode::Libstd, target, "build")
-        }else{
-            builder.cargo(compiler, Mode::Libstd, target, "check")
-        };
+        let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
         std_cargo(build, &compiler, target, &mut cargo);
         run_cargo(build,
                 &mut cargo,
@@ -165,7 +161,6 @@ pub fn std_cargo(build: &Build,
         // missing
         // We also only build the runtimes when --enable-sanitizers (or its
         // config.toml equivalent) is used
-        //cargo.env("RUST_FLAGS", "-Zno-trans");
         cargo.env("LLVM_CONFIG", build.llvm_config(target));
     }
 
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index 1520fc7def8..1b1282eacc0 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -69,7 +69,7 @@ use derive_registrar;
 
 use profile;
 
-pub fn compile_input(sess: &Session,
+pub fn compile_input(sess: &mut Session,
                      cstore: &CStore,
                      input: &Input,
                      outdir: &Option<PathBuf>,
@@ -100,17 +100,32 @@ pub fn compile_input(sess: &Session,
             sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
         }
 
-        if sess.opts.crate_types.iter().all(|&t|{
-            t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
-        }) && !sess.opts.crate_types.is_empty() {
-            sess.err(
-                "LLVM is not supported by this rustc, so non rlib libraries are not supported"
-            );
+        for cty in sess.opts.crate_types.iter_mut() {
+            match *cty {
+                CrateType::CrateTypeRlib | CrateType::CrateTypeExecutable => {},
+                CrateType::CrateTypeDylib | CrateType::CrateTypeCdylib |
+                CrateType::CrateTypeStaticlib => {
+                    sess.parse_sess.span_diagnostic.warn(
+                        &format!("LLVM unsupported, so non rlib output type {} \
+                                  will be treated like rlib lib", cty)
+                    );
+                    *cty = CrateType::CrateTypeRlib;
+                },
+                CrateType::CrateTypeProcMacro => {
+                    sess.parse_sess.span_diagnostic.err(
+                        "No LLVM support, so cant compile proc macros"
+                    );
+                }
+            }
         }
 
         sess.abort_if_errors();
     }
 
+    // Make sure nobody changes sess after crate types
+    // have optionally been adjusted for no llvm builds
+    let sess = &*sess;
+
     if sess.profile_queries() {
         profile::begin();
     }
@@ -267,6 +282,10 @@ pub fn compile_input(sess: &Session,
 
     if cfg!(not(feature="llvm")) {
         let (_, _) = (outputs, trans);
+
+        if sess.opts.crate_types.contains(&CrateType::CrateTypeRlib) {
+            return Ok(())
+        }
         sess.fatal("LLVM is not supported by this rustc");
     }
 
@@ -300,9 +319,9 @@ pub fn compile_input(sess: &Session,
             CompileState::state_when_compilation_done(input, sess, outdir, output),
             Ok(())
         );
-
-        Ok(())
     }
+
+    Ok(())
 }
 
 fn keep_hygiene_data(sess: &Session) -> bool {
diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs
index 19f7cb0ee23..c762844ab35 100644
--- a/src/librustc_metadata/locator.rs
+++ b/src/librustc_metadata/locator.rs
@@ -457,6 +457,14 @@ impl<'a> Context<'a> {
         //
         // The goal of this step is to look at as little metadata as possible.
         self.filesearch.search(|path, kind| {
+            let mut path = path.to_owned();
+            if cfg!(not(feature="llvm")) {
+                // This is a hack to make crates both defined as dylib
+                // and rlib to be findable without LLVM
+                path.set_extension("rlib");
+            }
+            let path = &path;
+
             let file = match path.file_name().and_then(|s| s.to_str()) {
                 None => return FileDoesntMatch,
                 Some(file) => file,
@@ -745,7 +753,15 @@ impl<'a> Context<'a> {
         let mut rmetas = FxHashMap();
         let mut dylibs = FxHashMap();
         {
-            let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
+            let locs = locs.map(|l| PathBuf::from(l))
+                .map(|mut l| {
+                    if cfg!(not(feature="llvm")) {
+                        // This is a hack to make crates both defined as dylib
+                        // and rlib to be findable without LLVM
+                        l.set_extension("rlib");
+                    }
+                    l
+                }).filter(|loc| {
                 if !loc.exists() {
                     sess.err(&format!("extern location for {} does not exist: {}",
                                       self.crate_name,
diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs
index e6ab46fa931..796e203bd04 100644
--- a/src/librustc_trans/back/link.rs
+++ b/src/librustc_trans/back/link.rs
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-extern crate rustc_trans_utils;
-
 use super::archive::{ArchiveBuilder, ArchiveConfig};
 use super::linker::Linker;
 use super::command::Command;
@@ -27,7 +25,6 @@ use {CrateTranslation, CrateInfo};
 use rustc::util::common::time;
 use rustc::util::fs::fix_windows_verbatim_for_gcc;
 use rustc::hir::def_id::CrateNum;
-use rustc::hir::svh::Svh;
 use rustc_back::tempdir::TempDir;
 use rustc_back::{PanicStrategy, RelroLevel};
 use context::get_reloc_model;
@@ -88,9 +85,9 @@ pub const RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET: usize =
 pub const RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET: usize =
     RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET + 8;
 
-pub use self::rustc_trans_utils::link::{find_crate_name, filename_for_input,
-                                        default_output_for_target, invalid_output_for_target,
-                                        build_link_meta};
+pub use rustc_trans_utils::link::{find_crate_name, filename_for_input, default_output_for_target,
+                                  invalid_output_for_target, build_link_meta, out_filename,
+                                  check_file_is_writeable};
 
 // The third parameter is for env vars, used on windows to set up the
 // path for MSVC to find its DLLs, and gcc to find its bundled
@@ -218,13 +215,6 @@ pub fn link_binary(sess: &Session,
     out_filenames
 }
 
-fn is_writeable(p: &Path) -> bool {
-    match p.metadata() {
-        Err(..) => true,
-        Ok(m) => !m.permissions().readonly()
-    }
-}
-
 fn filename_for_metadata(sess: &Session, crate_name: &str, outputs: &OutputFilenames) -> PathBuf {
     let out_filename = outputs.single_output_file.clone()
         .unwrap_or(outputs
@@ -288,32 +278,6 @@ pub fn ignored_for_lto(info: &CrateInfo, cnum: CrateNum) -> bool {
     info.is_no_builtins.contains(&cnum) || info.compiler_builtins == Some(cnum)
 }
 
-fn out_filename(sess: &Session,
-                crate_type: config::CrateType,
-                outputs: &OutputFilenames,
-                crate_name: &str)
-                -> PathBuf {
-    let default_filename = filename_for_input(sess, crate_type, crate_name, outputs);
-    let out_filename = outputs.outputs.get(&OutputType::Exe)
-                              .and_then(|s| s.to_owned())
-                              .or_else(|| outputs.single_output_file.clone())
-                              .unwrap_or(default_filename);
-
-    check_file_is_writeable(&out_filename, sess);
-
-    out_filename
-}
-
-// Make sure files are writeable.  Mac, FreeBSD, and Windows system linkers
-// check this already -- however, the Linux linker will happily overwrite a
-// read-only file.  We should be consistent.
-fn check_file_is_writeable(file: &Path, sess: &Session) {
-    if !is_writeable(file) {
-        sess.fatal(&format!("output file {} is not writeable -- check its \
-                            permissions", file.display()));
-    }
-}
-
 fn link_binary_output(sess: &Session,
                       trans: &CrateTranslation,
                       crate_type: config::CrateType,
diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs
index 91852630fa4..7d69db12bd0 100644
--- a/src/librustc_trans/base.rs
+++ b/src/librustc_trans/base.rs
@@ -938,7 +938,7 @@ pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
 pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                              rx: mpsc::Receiver<Box<Any + Send>>)
                              -> OngoingCrateTranslation {
-    use back::link::rustc_trans_utils::find_exported_symbols;
+    use rustc_trans_utils::find_exported_symbols;
 
     check_for_rustc_errors_attr(tcx);
 
diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs
index 57e9f1d091b..f45a011e94d 100644
--- a/src/librustc_trans/lib.rs
+++ b/src/librustc_trans/lib.rs
@@ -50,6 +50,7 @@ extern crate rustc_incremental;
 extern crate rustc_llvm as llvm;
 extern crate rustc_platform_intrinsics as intrinsics;
 extern crate rustc_const_math;
+extern crate rustc_trans_utils;
 extern crate rustc_demangle;
 extern crate jobserver;
 extern crate num_cpus;
diff --git a/src/librustc_trans_utils/link.rs b/src/librustc_trans_utils/link.rs
index 36c3ddc178b..ccd5739efe0 100644
--- a/src/librustc_trans_utils/link.rs
+++ b/src/librustc_trans_utils/link.rs
@@ -14,10 +14,43 @@ use rustc::middle::cstore::{self, LinkMeta};
 use rustc::dep_graph::{DepKind, DepNode};
 use rustc::hir::svh::Svh;
 use rustc_incremental::IncrementalHashesMap;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 use syntax::ast;
 use syntax_pos::Span;
 
+pub fn out_filename(sess: &Session,
+                crate_type: config::CrateType,
+                outputs: &OutputFilenames,
+                crate_name: &str)
+                -> PathBuf {
+    let default_filename = filename_for_input(sess, crate_type, crate_name, outputs);
+    let out_filename = outputs.outputs.get(&OutputType::Exe)
+                              .and_then(|s| s.to_owned())
+                              .or_else(|| outputs.single_output_file.clone())
+                              .unwrap_or(default_filename);
+
+    check_file_is_writeable(&out_filename, sess);
+
+    out_filename
+}
+
+// Make sure files are writeable.  Mac, FreeBSD, and Windows system linkers
+// check this already -- however, the Linux linker will happily overwrite a
+// read-only file.  We should be consistent.
+pub fn check_file_is_writeable(file: &Path, sess: &Session) {
+    if !is_writeable(file) {
+        sess.fatal(&format!("output file {} is not writeable -- check its \
+                            permissions", file.display()));
+    }
+}
+
+fn is_writeable(p: &Path) -> bool {
+    match p.metadata() {
+        Err(..) => true,
+        Ok(m) => !m.permissions().readonly()
+    }
+}
+
 pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMeta {
     let krate_dep_node = &DepNode::new_no_params(DepKind::Krate);
     let r = LinkMeta {