Mostly fix compiling without LLVM (with metadata_only backend)
This commit is contained in:
parent
6ceb1637b2
commit
95ed511514
11 changed files with 15 additions and 119 deletions
|
@ -14,10 +14,6 @@
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
[llvm]
|
[llvm]
|
||||||
|
|
||||||
# Indicates whether rustc will support compilation with LLVM
|
|
||||||
# note: rustc does not compile without LLVM at the moment
|
|
||||||
#enabled = true
|
|
||||||
|
|
||||||
# Indicates whether the LLVM build is a Release or Debug build
|
# Indicates whether the LLVM build is a Release or Debug build
|
||||||
#optimize = true
|
#optimize = true
|
||||||
|
|
||||||
|
|
|
@ -2031,8 +2031,6 @@ dependencies = [
|
||||||
name = "rustc_codegen_utils"
|
name = "rustc_codegen_utils"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc 0.0.0",
|
"rustc 0.0.0",
|
||||||
"rustc_data_structures 0.0.0",
|
"rustc_data_structures 0.0.0",
|
||||||
|
|
|
@ -114,10 +114,6 @@ fn main() {
|
||||||
|
|
||||||
cmd.env("RUSTC_BREAK_ON_ICE", "1");
|
cmd.env("RUSTC_BREAK_ON_ICE", "1");
|
||||||
|
|
||||||
if args.iter().find(|s| **s == OsString::from("___")).is_some() {
|
|
||||||
cmd.arg("-Zcodegen-backend=metadata_only");
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
// The stage0 compiler has a special sysroot distinct from what we
|
// The stage0 compiler has a special sysroot distinct from what we
|
||||||
// actually downloaded, so we just always pass the `--sysroot` option.
|
// actually downloaded, so we just always pass the `--sysroot` option.
|
||||||
|
|
|
@ -893,7 +893,7 @@ impl<'a> Builder<'a> {
|
||||||
//
|
//
|
||||||
// If LLVM support is disabled we need to use the snapshot compiler to compile
|
// If LLVM support is disabled we need to use the snapshot compiler to compile
|
||||||
// build scripts, as the new compiler doesn't support executables.
|
// build scripts, as the new compiler doesn't support executables.
|
||||||
if mode == Mode::Std || !self.config.llvm_enabled {
|
if mode == Mode::Std || self.config.rust_codegen_backends.is_empty() {
|
||||||
cargo
|
cargo
|
||||||
.env("RUSTC_SNAPSHOT", &self.initial_rustc)
|
.env("RUSTC_SNAPSHOT", &self.initial_rustc)
|
||||||
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
|
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
|
||||||
|
|
|
@ -74,7 +74,6 @@ pub struct Config {
|
||||||
pub backtrace_on_ice: bool,
|
pub backtrace_on_ice: bool,
|
||||||
|
|
||||||
// llvm codegen options
|
// llvm codegen options
|
||||||
pub llvm_enabled: bool,
|
|
||||||
pub llvm_assertions: bool,
|
pub llvm_assertions: bool,
|
||||||
pub llvm_optimize: bool,
|
pub llvm_optimize: bool,
|
||||||
pub llvm_release_debuginfo: bool,
|
pub llvm_release_debuginfo: bool,
|
||||||
|
@ -239,7 +238,6 @@ struct Install {
|
||||||
#[derive(Deserialize, Default)]
|
#[derive(Deserialize, Default)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||||
struct Llvm {
|
struct Llvm {
|
||||||
enabled: Option<bool>,
|
|
||||||
ccache: Option<StringOrBool>,
|
ccache: Option<StringOrBool>,
|
||||||
ninja: Option<bool>,
|
ninja: Option<bool>,
|
||||||
assertions: Option<bool>,
|
assertions: Option<bool>,
|
||||||
|
@ -341,7 +339,6 @@ impl Config {
|
||||||
|
|
||||||
pub fn default_opts() -> Config {
|
pub fn default_opts() -> Config {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.llvm_enabled = true;
|
|
||||||
config.llvm_optimize = true;
|
config.llvm_optimize = true;
|
||||||
config.llvm_version_check = true;
|
config.llvm_version_check = true;
|
||||||
config.use_jemalloc = true;
|
config.use_jemalloc = true;
|
||||||
|
@ -496,7 +493,6 @@ impl Config {
|
||||||
Some(StringOrBool::Bool(false)) | None => {}
|
Some(StringOrBool::Bool(false)) | None => {}
|
||||||
}
|
}
|
||||||
set(&mut config.ninja, llvm.ninja);
|
set(&mut config.ninja, llvm.ninja);
|
||||||
set(&mut config.llvm_enabled, llvm.enabled);
|
|
||||||
llvm_assertions = llvm.assertions;
|
llvm_assertions = llvm.assertions;
|
||||||
set(&mut config.llvm_optimize, llvm.optimize);
|
set(&mut config.llvm_optimize, llvm.optimize);
|
||||||
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
|
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ impl Step for Compiletest {
|
||||||
cmd.arg("--quiet");
|
cmd.arg("--quiet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if builder.config.llvm_enabled {
|
if !builder.config.rust_codegen_backends.is_empty() {
|
||||||
let llvm_config = builder.ensure(native::Llvm {
|
let llvm_config = builder.ensure(native::Llvm {
|
||||||
target: builder.config.build,
|
target: builder.config.build,
|
||||||
emscripten: false,
|
emscripten: false,
|
||||||
|
@ -1129,7 +1129,7 @@ impl Step for Compiletest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
|
if suite == "run-make-fulldeps" && builder.config.rust_codegen_backends.is_empty() {
|
||||||
builder.info(&format!(
|
builder.info(&format!(
|
||||||
"Ignoring run-make test suite as they generally don't work without LLVM"
|
"Ignoring run-make test suite as they generally don't work without LLVM"
|
||||||
));
|
));
|
||||||
|
|
|
@ -672,7 +672,7 @@ impl<'a> Builder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn llvm_bin_path(&self) -> Option<PathBuf> {
|
fn llvm_bin_path(&self) -> Option<PathBuf> {
|
||||||
if self.config.llvm_enabled && !self.config.dry_run {
|
if !self.config.rust_codegen_backends.is_empty() && !self.config.dry_run {
|
||||||
let llvm_config = self.ensure(native::Llvm {
|
let llvm_config = self.ensure(native::Llvm {
|
||||||
target: self.config.build,
|
target: self.config.build,
|
||||||
emscripten: false,
|
emscripten: false,
|
||||||
|
|
|
@ -10,8 +10,6 @@ crate-type = ["dylib"]
|
||||||
test = false
|
test = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ar = "0.3.0"
|
|
||||||
flate2 = "1.0"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
syntax = { path = "../libsyntax" }
|
syntax = { path = "../libsyntax" }
|
||||||
|
|
|
@ -22,17 +22,13 @@
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::io::prelude::*;
|
use std::io::{self, Write};
|
||||||
use std::io::{self, Cursor};
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{mpsc, Arc};
|
use std::sync::{mpsc, Arc};
|
||||||
|
|
||||||
use rustc_data_structures::owning_ref::OwningRef;
|
use rustc_data_structures::owning_ref::OwningRef;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use ar::{Archive, Builder, Header};
|
|
||||||
use flate2::Compression;
|
|
||||||
use flate2::write::DeflateEncoder;
|
|
||||||
|
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
use rustc::hir::def_id::LOCAL_CRATE;
|
use rustc::hir::def_id::LOCAL_CRATE;
|
||||||
|
@ -80,96 +76,27 @@ pub trait CodegenBackend {
|
||||||
) -> Result<(), CompileIncomplete>;
|
) -> Result<(), CompileIncomplete>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DummyCodegenBackend;
|
|
||||||
|
|
||||||
impl CodegenBackend for DummyCodegenBackend {
|
|
||||||
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
|
|
||||||
box DummyMetadataLoader(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn provide(&self, _providers: &mut Providers) {
|
|
||||||
bug!("DummyCodegenBackend::provide");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn provide_extern(&self, _providers: &mut Providers) {
|
|
||||||
bug!("DummyCodegenBackend::provide_extern");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn codegen_crate<'a, 'tcx>(
|
|
||||||
&self,
|
|
||||||
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
||||||
_rx: mpsc::Receiver<Box<Any + Send>>
|
|
||||||
) -> Box<Any> {
|
|
||||||
bug!("DummyCodegenBackend::codegen_backend");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn join_codegen_and_link(
|
|
||||||
&self,
|
|
||||||
_ongoing_codegen: Box<Any>,
|
|
||||||
_sess: &Session,
|
|
||||||
_dep_graph: &DepGraph,
|
|
||||||
_outputs: &OutputFilenames,
|
|
||||||
) -> Result<(), CompileIncomplete> {
|
|
||||||
bug!("DummyCodegenBackend::join_codegen_and_link");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DummyMetadataLoader(());
|
|
||||||
|
|
||||||
impl MetadataLoader for DummyMetadataLoader {
|
|
||||||
fn get_rlib_metadata(
|
|
||||||
&self,
|
|
||||||
_target: &Target,
|
|
||||||
_filename: &Path
|
|
||||||
) -> Result<MetadataRef, String> {
|
|
||||||
bug!("DummyMetadataLoader::get_rlib_metadata");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_dylib_metadata(
|
|
||||||
&self,
|
|
||||||
_target: &Target,
|
|
||||||
_filename: &Path
|
|
||||||
) -> Result<MetadataRef, String> {
|
|
||||||
bug!("DummyMetadataLoader::get_dylib_metadata");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct NoLlvmMetadataLoader;
|
pub struct NoLlvmMetadataLoader;
|
||||||
|
|
||||||
impl MetadataLoader for NoLlvmMetadataLoader {
|
impl MetadataLoader for NoLlvmMetadataLoader {
|
||||||
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
|
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
|
||||||
let file = File::open(filename)
|
let mut file = File::open(filename)
|
||||||
.map_err(|e| format!("metadata file open err: {:?}", e))?;
|
.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 buf = Vec::new();
|
||||||
let mut entry = entry_result
|
io::copy(&mut file, &mut buf).unwrap();
|
||||||
.map_err(|e| format!("metadata section read err: {:?}", e))?;
|
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
|
||||||
if entry.header().identifier() == "rust.metadata.bin" {
|
return Ok(rustc_erase_owner!(buf.map_owner_box()));
|
||||||
let mut buf = Vec::new();
|
|
||||||
io::copy(&mut entry, &mut buf).unwrap();
|
|
||||||
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
|
|
||||||
return Ok(rustc_erase_owner!(buf.map_owner_box()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err("Couldn't find metadata section".to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dylib_metadata(
|
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
|
||||||
&self,
|
self.get_rlib_metadata(target, filename)
|
||||||
_target: &Target,
|
|
||||||
_filename: &Path,
|
|
||||||
) -> Result<MetadataRef, String> {
|
|
||||||
// FIXME: Support reading dylibs from llvm enabled rustc
|
|
||||||
self.get_rlib_metadata(_target, _filename)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MetadataOnlyCodegenBackend(());
|
pub struct MetadataOnlyCodegenBackend(());
|
||||||
pub struct OngoingCodegen {
|
pub struct OngoingCodegen {
|
||||||
metadata: EncodedMetadata,
|
metadata: EncodedMetadata,
|
||||||
metadata_version: Vec<u8>,
|
|
||||||
crate_name: Symbol,
|
crate_name: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +184,6 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
|
||||||
|
|
||||||
box OngoingCodegen {
|
box OngoingCodegen {
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
metadata_version: tcx.metadata_encoding_version().to_vec(),
|
|
||||||
crate_name: tcx.crate_name(LOCAL_CRATE),
|
crate_name: tcx.crate_name(LOCAL_CRATE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,18 +203,9 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
|
||||||
}
|
}
|
||||||
let output_name =
|
let output_name =
|
||||||
out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str());
|
out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str());
|
||||||
let mut compressed = ongoing_codegen.metadata_version.clone();
|
let metadata = &ongoing_codegen.metadata.raw_data;
|
||||||
let metadata = if crate_type == CrateType::CrateTypeDylib {
|
let mut file = File::create(&output_name).unwrap();
|
||||||
DeflateEncoder::new(&mut compressed, Compression::fast())
|
file.write_all(metadata).unwrap();
|
||||||
.write_all(&ongoing_codegen.metadata.raw_data)
|
|
||||||
.unwrap();
|
|
||||||
&compressed
|
|
||||||
} else {
|
|
||||||
&ongoing_codegen.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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sess.abort_if_errors();
|
sess.abort_if_errors();
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
#![recursion_limit="256"]
|
#![recursion_limit="256"]
|
||||||
|
|
||||||
extern crate ar;
|
|
||||||
extern crate flate2;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
|
@ -39,8 +37,6 @@ extern crate syntax;
|
||||||
extern crate syntax_pos;
|
extern crate syntax_pos;
|
||||||
#[macro_use] extern crate rustc_data_structures;
|
#[macro_use] extern crate rustc_data_structures;
|
||||||
|
|
||||||
pub extern crate rustc as __rustc;
|
|
||||||
|
|
||||||
use rustc::ty::TyCtxt;
|
use rustc::ty::TyCtxt;
|
||||||
|
|
||||||
pub mod link;
|
pub mod link;
|
||||||
|
|
|
@ -59,7 +59,6 @@ static WHITELIST_CRATES: &'static [CrateVersion] = &[
|
||||||
/// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
|
/// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
|
||||||
static WHITELIST: &'static [Crate] = &[
|
static WHITELIST: &'static [Crate] = &[
|
||||||
Crate("aho-corasick"),
|
Crate("aho-corasick"),
|
||||||
Crate("ar"),
|
|
||||||
Crate("arrayvec"),
|
Crate("arrayvec"),
|
||||||
Crate("atty"),
|
Crate("atty"),
|
||||||
Crate("backtrace"),
|
Crate("backtrace"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue