Allow building stage 2 compiler libraries

This commit is contained in:
bjorn3 2017-08-26 17:31:32 +02:00
parent cba53f0be5
commit d44a256157
9 changed files with 90 additions and 58 deletions

View File

@ -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()) {

View File

@ -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 {

View File

@ -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));
}

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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 {