From cba53f0be575196083fe52ecd2ec8f1c015664ce Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 13 Aug 2017 18:53:50 +0200 Subject: Allow writing metadata without llvm --- src/bootstrap/compile.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 335e1690a2e..2e368ddf43f 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -104,7 +104,11 @@ 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 = builder.cargo(compiler, Mode::Libstd, target, "build"); + let mut cargo = if compiler.stage == 0 { + builder.cargo(compiler, Mode::Libstd, target, "build") + }else{ + builder.cargo(compiler, Mode::Libstd, target, "check") + }; std_cargo(build, &compiler, target, &mut cargo); run_cargo(build, &mut cargo, @@ -161,6 +165,7 @@ 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)); } -- cgit 1.4.1-3-g733a5 From d44a256157f1773f146465107de1f211401ebf93 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 26 Aug 2017 17:31:32 +0200 Subject: Allow building stage 2 compiler libraries --- src/bootstrap/bin/rustc.rs | 4 ++++ src/bootstrap/builder.rs | 2 +- src/bootstrap/compile.rs | 7 +------ src/librustc_driver/driver.rs | 37 ++++++++++++++++++++++++++--------- src/librustc_metadata/locator.rs | 18 ++++++++++++++++- src/librustc_trans/back/link.rs | 42 +++------------------------------------- src/librustc_trans/base.rs | 2 +- src/librustc_trans/lib.rs | 1 + src/librustc_trans_utils/link.rs | 35 ++++++++++++++++++++++++++++++++- 9 files changed, 90 insertions(+), 58 deletions(-) (limited to 'src/bootstrap') 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, @@ -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>) -> 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 { -- cgit 1.4.1-3-g733a5 From 2c03c57bf5ac9e106440ea474827be16092f1807 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 2 Sep 2017 12:27:28 +0200 Subject: Dont do no-trans for llvm enabled builds --- src/bootstrap/bin/rustc.rs | 2 +- src/bootstrap/builder.rs | 6 ++++++ src/librustc_driver/Cargo.toml | 2 +- src/librustc_metadata/Cargo.toml | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index df9c55ce0be..2768d9c7f04 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -159,7 +159,7 @@ fn main() { cmd.arg("-C").arg("panic=abort"); } - if cfg!(not(feature="llvm")) && stage != "0" { + if env::var("RUSTC_LLVM_ENABLED") == Ok("0".to_string()) && stage != "0" { cmd.arg("-Zno-trans"); } diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index de6dd10938e..99712d9fcab 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -539,6 +539,12 @@ impl<'a> Builder<'a> { .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler)); } + if self.build.config.llvm_enabled { + cargo.env("RUSTC_LLVM_ENABLED", "1"); + } else { + cargo.env("RUSTC_LLVM_ENABLED", "0"); + } + // Ignore incremental modes except for stage0, since we're // not guaranteeing correctness across builds if the compiler // is changing under your feet.` diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index d6155f53485..dabe15b6a6e 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -41,4 +41,4 @@ syntax_pos = { path = "../libsyntax_pos" } ar = "0.3.0" [features] -llvm = ["rustc_trans"] +llvm = ["rustc_trans", "rustc_metadata/llvm"] diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml index 40b75be36fe..2c17797ed5d 100644 --- a/src/librustc_metadata/Cargo.toml +++ b/src/librustc_metadata/Cargo.toml @@ -21,3 +21,6 @@ serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } syntax_ext = { path = "../libsyntax_ext" } syntax_pos = { path = "../libsyntax_pos" } + +[features] +llvm = [] -- cgit 1.4.1-3-g733a5 From 9eeaba18bd31e63c5ae576ea6c7b88cfd50fcb60 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 18 Sep 2017 17:37:57 +0200 Subject: Move NoLlvmMetadataLoader to rustc_trans_traits --- src/Cargo.lock | 4 + src/bootstrap/bin/rustc.rs | 4 - src/bootstrap/builder.rs | 3 + src/librustc_driver/driver.rs | 63 +++++-------- src/librustc_driver/lib.rs | 166 +---------------------------------- src/librustc_trans_traits/Cargo.toml | 4 + src/librustc_trans_traits/lib.rs | 136 +++++++++++++++++++++++++++- 7 files changed, 169 insertions(+), 211 deletions(-) (limited to 'src/bootstrap') diff --git a/src/Cargo.lock b/src/Cargo.lock index 693bf5b2619..49db077849c 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1781,10 +1781,14 @@ dependencies = [ name = "rustc_trans_traits" version = "0.0.0" dependencies = [ + "ar 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_back 0.0.0", "rustc_incremental 0.0.0", + "rustc_trans_utils 0.0.0", + "syntax 0.0.0", ] [[package]] diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 2768d9c7f04..848b10d312c 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -159,10 +159,6 @@ fn main() { cmd.arg("-C").arg("panic=abort"); } - if env::var("RUSTC_LLVM_ENABLED") == Ok("0".to_string()) && 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 99712d9fcab..8307a536c33 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -531,6 +531,9 @@ 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 LLVM support is disabled we need to use the snapshot compiler to compile + // build scripts, as the new compiler doesnt support executables. if mode == Mode::Libstd || !self.build.config.llvm_enabled { cargo.env("RUSTC_SNAPSHOT", &self.initial_rustc) .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()); diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 9aab169023c..aa0000653cc 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(not(feature="llvm"), allow(dead_code))] - use rustc::dep_graph::DepGraph; use rustc::hir::{self, map as hir_map}; use rustc::hir::lowering::lower_crate; @@ -96,10 +94,6 @@ pub fn compile_input(sess: &Session, } if cfg!(not(feature="llvm")) { - if !sess.opts.debugging_opts.no_trans && sess.opts.output_types.should_trans() { - sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile") - } - for cty in sess.opts.crate_types.iter() { match *cty { CrateType::CrateTypeRlib | CrateType::CrateTypeDylib | @@ -269,48 +263,36 @@ pub fn compile_input(sess: &Session, })?? }; - if cfg!(not(feature="llvm")) { - let (_, _) = (outputs, trans); - - if sess.opts.crate_types.contains(&CrateType::CrateTypeRlib) - || sess.opts.crate_types.contains(&CrateType::CrateTypeDylib) { - return Ok(()) - } - sess.fatal("LLVM is not supported by this rustc"); + if sess.opts.debugging_opts.print_type_sizes { + sess.code_stats.borrow().print_type_sizes(); } - #[cfg(feature="llvm")] - { - if sess.opts.debugging_opts.print_type_sizes { - sess.code_stats.borrow().print_type_sizes(); - } - - let (phase5_result, trans) = phase_5_run_llvm_passes::(sess, &dep_graph, trans); - - controller_entry_point!(after_llvm, - sess, - CompileState::state_after_llvm(input, sess, outdir, output, &trans), - phase5_result); - phase5_result?; + let (phase5_result, trans) = phase_5_run_llvm_passes::(sess, &dep_graph, trans); - phase_6_link_output::(sess, &trans, &outputs); + controller_entry_point!(after_llvm, + sess, + CompileState::state_after_llvm(input, sess, outdir, output, &trans), + phase5_result); + phase5_result?; - // Now that we won't touch anything in the incremental compilation directory - // any more, we can finalize it (which involves renaming it) - rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash); + phase_6_link_output::(sess, &trans, &outputs); - if sess.opts.debugging_opts.perf_stats { - sess.print_perf_stats(); - } + // Now that we won't touch anything in the incremental compilation directory + // any more, we can finalize it (which involves renaming it) + #[cfg(feature="llvm")] + rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash); - controller_entry_point!( - compilation_done, - sess, - CompileState::state_when_compilation_done(input, sess, outdir, output), - Ok(()) - ); + if sess.opts.debugging_opts.perf_stats { + sess.print_perf_stats(); } + controller_entry_point!( + compilation_done, + sess, + CompileState::state_when_compilation_done(input, sess, outdir, output), + Ok(()) + ); + Ok(()) } @@ -1171,7 +1153,6 @@ pub fn phase_5_run_llvm_passes(sess: &Session, /// Run the linker on any artifacts that resulted from the LLVM run. /// This should produce either a finished executable or library. -#[cfg(feature="llvm")] pub fn phase_6_link_output(sess: &Session, trans: &::TranslatedCrate, outputs: &OutputFilenames) { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index fda738db85f..db56ff7afc3 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -25,8 +25,6 @@ #![feature(rustc_diagnostic_macros)] #![feature(set_stdio)] -extern crate ar; -extern crate flate2; extern crate arena; extern crate getopts; extern crate graphviz; @@ -155,173 +153,17 @@ pub fn run(run_compiler: F) -> isize } #[cfg(not(feature="llvm"))] -pub use trans_metadata_only::MetadataOnlyTransCrate as DefaultTransCrate; +pub use rustc_trans_traits::MetadataOnlyTransCrate as DefaultTransCrate; #[cfg(feature="llvm")] pub use rustc_trans::LlvmTransCrate as DefaultTransCrate; -mod no_llvm_metadata_loader { - extern crate owning_ref; - - use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait; - use rustc_back::target::Target; - use std::io; - use std::fs::File; - use std::path::Path; - - use ar::Archive; - use self::owning_ref::{OwningRef, ErasedBoxRef}; - - pub struct NoLlvmMetadataLoader; - - impl MetadataLoaderTrait for NoLlvmMetadataLoader { - fn get_rlib_metadata( - &self, - _: &Target, - filename: &Path - ) -> Result, String> { - let file = File::open(filename).map_err(|e| { - format!("metadata file open err: {:?}", e) - })?; - let mut archive = Archive::new(file); - - while let Some(entry_result) = archive.next_entry() { - let mut entry = entry_result.map_err(|e| { - format!("metadata section read err: {:?}", e) - })?; - if entry.header().identifier() == "rust.metadata.bin" { - let mut buf = Vec::new(); - io::copy(&mut entry, &mut buf).unwrap(); - let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); - return Ok(buf.map_owner_box().erase_owner()); - } - } - - Err("Couldnt find metadata section".to_string()) - } - - fn get_dylib_metadata(&self, - _target: &Target, - _filename: &Path) - -> Result, String> { - // FIXME: Support reading dylibs from llvm enabled rustc - self.get_rlib_metadata(_target, _filename) - } - } -} - -mod trans_metadata_only { - use std::io::prelude::*; - use std::io::Cursor; - use std::fs::File; - - use ar::{Builder, Header}; - use flate2::Compression; - use flate2::write::DeflateEncoder; - - use syntax::symbol::Symbol; - use rustc::hir::def_id::LOCAL_CRATE; - use rustc::session::Session; - use rustc::session::config::{OutputFilenames, CrateType}; - use rustc::ty::{TyCtxt, CrateAnalysis}; - use rustc::ty::maps::Providers; - use rustc::middle::cstore::{MetadataLoader, EncodedMetadata}; - use rustc::dep_graph::DepGraph; - use rustc_incremental::IncrementalHashesMap; - use rustc_trans_utils::find_exported_symbols; - use rustc_trans_utils::link::{out_filename, build_link_meta}; - use rustc_trans_traits::TransCrate; - - #[allow(dead_code)] - pub struct MetadataOnlyTransCrate; - pub struct OngoingCrateTranslation { - metadata: EncodedMetadata, - metadata_version: Vec, - crate_name: Symbol, - } - pub struct TranslatedCrate(OngoingCrateTranslation); - - impl MetadataOnlyTransCrate { - #[allow(dead_code)] - pub fn new(/*_sess: &Session*/) -> Self { - MetadataOnlyTransCrate - } - } - - impl TransCrate for MetadataOnlyTransCrate { - type MetadataLoader = ::no_llvm_metadata_loader::NoLlvmMetadataLoader; - type OngoingCrateTranslation = OngoingCrateTranslation; - type TranslatedCrate = TranslatedCrate; - - fn metadata_loader() -> Box { - box ::no_llvm_metadata_loader::NoLlvmMetadataLoader - } - - fn provide(_providers: &mut Providers) {} - - fn trans_crate<'a, 'tcx>( - tcx: TyCtxt<'a, 'tcx, 'tcx>, - analysis: CrateAnalysis, - incr_hashes_map: IncrementalHashesMap, - _output_filenames: &OutputFilenames - ) -> Self::OngoingCrateTranslation { - let link_meta = build_link_meta(&incr_hashes_map); - let exported_symbols = find_exported_symbols(tcx, &analysis.reachable); - let (metadata, _hashes) = tcx.encode_metadata(&link_meta, &exported_symbols); - - OngoingCrateTranslation { - metadata: metadata, - metadata_version: tcx.metadata_encoding_version().to_vec(), - crate_name: tcx.crate_name(LOCAL_CRATE), - } - } - - fn join_trans( - trans: Self::OngoingCrateTranslation, - _sess: &Session, - _dep_graph: &DepGraph, - ) -> Self::TranslatedCrate { - TranslatedCrate(trans) - } - - fn link_binary(sess: &Session, - trans: &Self::TranslatedCrate, - outputs: &OutputFilenames) { - for &crate_type in sess.opts.crate_types.iter() { - if crate_type != CrateType::CrateTypeRlib && - crate_type != CrateType::CrateTypeDylib { - continue; - } - let output_name = - out_filename(sess, crate_type, &outputs, &trans.0.crate_name.as_str()); - let mut compressed = trans.0.metadata_version.clone(); - let metadata = if crate_type == CrateType::CrateTypeDylib { - DeflateEncoder::new(&mut compressed, Compression::Fast) - .write_all(&trans.0.metadata.raw_data).unwrap(); - &compressed - } else { - &trans.0.metadata.raw_data - }; - let mut builder = Builder::new(File::create(&output_name).unwrap()); - let header = Header::new( - "rust.metadata.bin".to_string(), - metadata.len() as u64 - ); - builder - .append(&header, Cursor::new(metadata)) - .unwrap(); - } - } - - fn dump_incremental_data(_trans: &Self::TranslatedCrate) {} - } -} - #[cfg(not(feature="llvm"))] mod rustc_trans { use syntax_pos::symbol::Symbol; use rustc::session::Session; use rustc::session::config::PrintRequest; - pub use trans_metadata_only::MetadataOnlyTransCrate as LlvmTransCrate; + pub use rustc_trans_traits::MetadataOnlyTransCrate as LlvmTransCrate; + pub use rustc_trans_traits::TranslatedCrate as CrateTranslation; pub fn init(_sess: &Session) {} pub fn enable_llvm_debug() {} @@ -330,8 +172,6 @@ mod rustc_trans { pub fn print(_req: PrintRequest, _sess: &Session) {} pub fn target_features(_sess: &Session) -> Vec { vec![] } - pub struct CrateTranslation(()); - pub mod back { pub mod write { pub const RELOC_MODEL_ARGS: [(&'static str, ()); 0] = []; diff --git a/src/librustc_trans_traits/Cargo.toml b/src/librustc_trans_traits/Cargo.toml index 418de173fd1..4ba0ed1e1c7 100644 --- a/src/librustc_trans_traits/Cargo.toml +++ b/src/librustc_trans_traits/Cargo.toml @@ -10,8 +10,12 @@ crate-type = ["dylib"] test = false [dependencies] +ar = "0.3.0" +flate2 = "0.2" owning_ref = "0.3.3" +syntax = { path = "../libsyntax" } rustc = { path = "../librustc" } rustc_back = { path = "../librustc_back" } rustc_incremental = { path = "../librustc_incremental" } +rustc_trans_utils = { path = "../librustc_trans_utils" } diff --git a/src/librustc_trans_traits/lib.rs b/src/librustc_trans_traits/lib.rs index 340d54c1029..3f5f44eb906 100644 --- a/src/librustc_trans_traits/lib.rs +++ b/src/librustc_trans_traits/lib.rs @@ -21,24 +21,40 @@ #![feature(box_syntax)] +extern crate ar; +extern crate flate2; extern crate owning_ref; +extern crate syntax; #[macro_use] extern crate rustc; extern crate rustc_back; extern crate rustc_incremental; +extern crate rustc_trans_utils; +use std::io::prelude::*; +use std::io::{self, Cursor}; +use std::fs::File; use std::path::Path; -use owning_ref::ErasedBoxRef; +use owning_ref::{ErasedBoxRef, OwningRef}; +use ar::{Archive, Builder, Header}; +use flate2::Compression; +use flate2::write::DeflateEncoder; + +use syntax::symbol::Symbol; +use rustc::hir::def_id::LOCAL_CRATE; use rustc::session::Session; -use rustc::session::config::OutputFilenames; -use rustc::ty::{TyCtxt, CrateAnalysis}; +use rustc::session::config::{CrateType, OutputFilenames}; +use rustc::ty::{CrateAnalysis, TyCtxt}; use rustc::ty::maps::Providers; +use rustc::middle::cstore::EncodedMetadata; use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait; use rustc::dep_graph::DepGraph; use rustc_back::target::Target; use rustc_incremental::IncrementalHashesMap; +use rustc_trans_utils::find_exported_symbols; +use rustc_trans_utils::link::{build_link_meta, out_filename}; pub trait TransCrate { type MetadataLoader: MetadataLoaderTrait; @@ -114,3 +130,117 @@ impl MetadataLoaderTrait for DummyMetadataLoader { bug!("DummyMetadataLoader::get_dylib_metadata"); } } + +pub struct NoLlvmMetadataLoader; + +impl MetadataLoaderTrait for NoLlvmMetadataLoader { + fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result, String> { + let file = File::open(filename) + .map_err(|e| format!("metadata file open err: {:?}", e))?; + let mut archive = Archive::new(file); + + while let Some(entry_result) = archive.next_entry() { + let mut entry = entry_result + .map_err(|e| format!("metadata section read err: {:?}", e))?; + if entry.header().identifier() == "rust.metadata.bin" { + let mut buf = Vec::new(); + io::copy(&mut entry, &mut buf).unwrap(); + let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); + return Ok(buf.map_owner_box().erase_owner()); + } + } + + Err("Couldnt find metadata section".to_string()) + } + + fn get_dylib_metadata( + &self, + _target: &Target, + _filename: &Path, + ) -> Result, String> { + // FIXME: Support reading dylibs from llvm enabled rustc + self.get_rlib_metadata(_target, _filename) + } +} + +#[allow(dead_code)] +pub struct MetadataOnlyTransCrate; +pub struct OngoingCrateTranslation { + metadata: EncodedMetadata, + metadata_version: Vec, + crate_name: Symbol, +} +pub struct TranslatedCrate(OngoingCrateTranslation); + +impl MetadataOnlyTransCrate { + #[allow(dead_code)] + pub fn new() -> Self { + MetadataOnlyTransCrate + } +} + +impl TransCrate for MetadataOnlyTransCrate { + type MetadataLoader = NoLlvmMetadataLoader; + type OngoingCrateTranslation = OngoingCrateTranslation; + type TranslatedCrate = TranslatedCrate; + + fn metadata_loader() -> Box { + box NoLlvmMetadataLoader + } + + fn provide(_providers: &mut Providers) {} + + fn trans_crate<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + analysis: CrateAnalysis, + incr_hashes_map: IncrementalHashesMap, + _output_filenames: &OutputFilenames, + ) -> Self::OngoingCrateTranslation { + let link_meta = build_link_meta(&incr_hashes_map); + let exported_symbols = find_exported_symbols(tcx, &analysis.reachable); + let (metadata, _hashes) = tcx.encode_metadata(&link_meta, &exported_symbols); + + OngoingCrateTranslation { + metadata: metadata, + metadata_version: tcx.metadata_encoding_version().to_vec(), + crate_name: tcx.crate_name(LOCAL_CRATE), + } + } + + fn join_trans( + trans: Self::OngoingCrateTranslation, + _sess: &Session, + _dep_graph: &DepGraph, + ) -> Self::TranslatedCrate { + TranslatedCrate(trans) + } + + fn link_binary(sess: &Session, trans: &Self::TranslatedCrate, outputs: &OutputFilenames) { + for &crate_type in sess.opts.crate_types.iter() { + if crate_type != CrateType::CrateTypeRlib && crate_type != CrateType::CrateTypeDylib { + continue; + } + let output_name = + out_filename(sess, crate_type, &outputs, &trans.0.crate_name.as_str()); + let mut compressed = trans.0.metadata_version.clone(); + let metadata = if crate_type == CrateType::CrateTypeDylib { + DeflateEncoder::new(&mut compressed, Compression::Fast) + .write_all(&trans.0.metadata.raw_data) + .unwrap(); + &compressed + } else { + &trans.0.metadata.raw_data + }; + let mut builder = Builder::new(File::create(&output_name).unwrap()); + let header = Header::new("rust.metadata.bin".to_string(), metadata.len() as u64); + builder.append(&header, Cursor::new(metadata)).unwrap(); + } + + if !sess.opts.crate_types.contains(&CrateType::CrateTypeRlib) + && !sess.opts.crate_types.contains(&CrateType::CrateTypeDylib) { + sess.fatal("Executables are not supported by the metadata-only backend."); + } + } + + fn dump_incremental_data(_trans: &Self::TranslatedCrate) {} +} -- cgit 1.4.1-3-g733a5 From 95fb1d008f20943e61f1c40460cbb2f89818cf4b Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 23 Sep 2017 15:26:34 +0200 Subject: Remove leftover --- src/bootstrap/builder.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/bootstrap') diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 8307a536c33..ffd959d86f5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -542,12 +542,6 @@ impl<'a> Builder<'a> { .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_libdir(compiler)); } - if self.build.config.llvm_enabled { - cargo.env("RUSTC_LLVM_ENABLED", "1"); - } else { - cargo.env("RUSTC_LLVM_ENABLED", "0"); - } - // Ignore incremental modes except for stage0, since we're // not guaranteeing correctness across builds if the compiler // is changing under your feet.` -- cgit 1.4.1-3-g733a5