Skip to content

Commit 9342f29

Browse files
committed
Auto merge of rust-lang#51590 - bjorn3:codegen_llvm_extract, r=alexcrichton
Mostly fix metadata_only backend and extract some code out of rustc_codegen_llvm Removes dependency on the `ar` crate and removes the `llvm.enabled` config option in favour of setting `rust.codegen-backends` to `[]`.
2 parents 9fd3d78 + 23c0b3b commit 9342f29

File tree

15 files changed

+30
-110
lines changed

15 files changed

+30
-110
lines changed

src/Cargo.lock

-8
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ dependencies = [
5757
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
5858
]
5959

60-
[[package]]
61-
name = "ar"
62-
version = "0.3.1"
63-
source = "registry+https://github.com/rust-lang/crates.io-index"
64-
6560
[[package]]
6661
name = "arena"
6762
version = "0.0.0"
@@ -2031,7 +2026,6 @@ dependencies = [
20312026
name = "rustc_codegen_utils"
20322027
version = "0.0.0"
20332028
dependencies = [
2034-
"ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
20352029
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
20362030
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
20372031
"rustc 0.0.0",
@@ -2072,7 +2066,6 @@ dependencies = [
20722066
name = "rustc_driver"
20732067
version = "0.0.0"
20742068
dependencies = [
2075-
"ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
20762069
"arena 0.0.0",
20772070
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
20782071
"graphviz 0.0.0",
@@ -3077,7 +3070,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30773070
"checksum aho-corasick 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f0ba20154ea1f47ce2793322f049c5646cc6d0fa9759d5f333f286e507bf8080"
30783071
"checksum ammonia 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd4c682378117e4186a492b2252b9537990e1617f44aed9788b9a1149de45477"
30793072
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
3080-
"checksum ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "35c7a5669cb64f085739387e1308b74e6d44022464b7f1b63bbd4ceb6379ec31"
30813073
"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef"
30823074
"checksum assert_cli 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98589b0e465a6c510d95fceebd365bb79bedece7f6e18a480897f2015f85ec51"
30833075
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub mod util {
162162
pub mod ppaux;
163163
pub mod nodemap;
164164
pub mod fs;
165+
pub mod time_graph;
165166
}
166167

167168
// A private module so that macro-expanded idents like

src/librustc_codegen_llvm/base.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use builder::{Builder, MemFlags};
5656
use callee;
5757
use common::{C_bool, C_bytes_in_context, C_i32, C_usize};
5858
use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode};
59+
use rustc_mir::monomorphize::item::DefPathBasedNames;
5960
use common::{self, C_struct_in_context, C_array, val_ty};
6061
use consts;
6162
use context::{self, CodegenCx};
@@ -67,7 +68,7 @@ use monomorphize::Instance;
6768
use monomorphize::partitioning::{self, PartitioningStrategy, CodegenUnit, CodegenUnitExt};
6869
use rustc_codegen_utils::symbol_names_test;
6970
use time_graph;
70-
use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt, DefPathBasedNames};
71+
use mono_item::{MonoItem, BaseMonoItemExt, MonoItemExt};
7172
use type_::Type;
7273
use type_of::LayoutLlvmExt;
7374
use rustc::util::nodemap::{FxHashMap, FxHashSet, DefIdSet};
@@ -92,7 +93,7 @@ use syntax::ast;
9293

9394
use mir::operand::OperandValue;
9495

95-
pub use rustc_codegen_utils::check_for_rustc_errors_attr;
96+
use rustc_codegen_utils::check_for_rustc_errors_attr;
9697

9798
pub struct StatRecorder<'a, 'tcx: 'a> {
9899
cx: &'a CodegenCx<'a, 'tcx>,

src/librustc_codegen_llvm/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ use rustc::middle::lang_items::LangItem;
7676
use rustc::session::{Session, CompileIncomplete};
7777
use rustc::session::config::{OutputFilenames, OutputType, PrintRequest};
7878
use rustc::ty::{self, TyCtxt};
79+
use rustc::util::time_graph;
7980
use rustc::util::nodemap::{FxHashSet, FxHashMap};
8081
use rustc_mir::monomorphize;
8182
use rustc_codegen_utils::codegen_backend::CodegenBackend;
@@ -114,7 +115,6 @@ mod llvm_util;
114115
mod metadata;
115116
mod meth;
116117
mod mir;
117-
mod time_graph;
118118
mod mono_item;
119119
mod type_;
120120
mod type_of;
@@ -368,7 +368,7 @@ struct CodegenResults {
368368
crate_info: CrateInfo,
369369
}
370370

371-
// Misc info we load from metadata to persist beyond the tcx
371+
/// Misc info we load from metadata to persist beyond the tcx
372372
struct CrateInfo {
373373
panic_runtime: Option<CrateNum>,
374374
compiler_builtins: Option<CrateNum>,

src/librustc_codegen_llvm/mono_item.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::fmt;
3333

3434
pub use rustc::mir::mono::MonoItem;
3535

36-
pub use rustc_mir::monomorphize::item::*;
3736
pub use rustc_mir::monomorphize::item::MonoItemExt as BaseMonoItemExt;
3837

3938
pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {

src/librustc_codegen_llvm/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::ty::{self, Ty, TypeFoldable};
1616
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
1717
use rustc_target::spec::PanicStrategy;
1818
use rustc_target::abi::FloatTy;
19-
use mono_item::DefPathBasedNames;
19+
use rustc_mir::monomorphize::item::DefPathBasedNames;
2020
use type_::Type;
2121

2222
use std::fmt::Write;

src/librustc_codegen_utils/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ crate-type = ["dylib"]
1010
test = false
1111

1212
[dependencies]
13-
ar = "0.3.0"
1413
flate2 = "1.0"
1514
log = "0.4"
1615

src/librustc_codegen_utils/codegen_backend.rs

+19-84
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
#![feature(box_syntax)]
2323

2424
use std::any::Any;
25-
use std::io::prelude::*;
26-
use std::io::{self, Cursor};
25+
use std::io::{self, Write};
2726
use std::fs::File;
2827
use std::path::Path;
29-
use std::sync::mpsc;
28+
use std::sync::{mpsc, Arc};
3029

3130
use rustc_data_structures::owning_ref::OwningRef;
3231
use rustc_data_structures::sync::Lrc;
33-
use ar::{Archive, Builder, Header};
3432
use flate2::Compression;
3533
use flate2::write::DeflateEncoder;
3634

@@ -81,89 +79,21 @@ pub trait CodegenBackend {
8179
) -> Result<(), CompileIncomplete>;
8280
}
8381

84-
pub struct DummyCodegenBackend;
85-
86-
impl CodegenBackend for DummyCodegenBackend {
87-
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
88-
box DummyMetadataLoader(())
89-
}
90-
91-
fn provide(&self, _providers: &mut Providers) {
92-
bug!("DummyCodegenBackend::provide");
93-
}
94-
95-
fn provide_extern(&self, _providers: &mut Providers) {
96-
bug!("DummyCodegenBackend::provide_extern");
97-
}
98-
99-
fn codegen_crate<'a, 'tcx>(
100-
&self,
101-
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
102-
_rx: mpsc::Receiver<Box<Any + Send>>
103-
) -> Box<Any> {
104-
bug!("DummyCodegenBackend::codegen_backend");
105-
}
106-
107-
fn join_codegen_and_link(
108-
&self,
109-
_ongoing_codegen: Box<Any>,
110-
_sess: &Session,
111-
_dep_graph: &DepGraph,
112-
_outputs: &OutputFilenames,
113-
) -> Result<(), CompileIncomplete> {
114-
bug!("DummyCodegenBackend::join_codegen_and_link");
115-
}
116-
}
117-
118-
pub struct DummyMetadataLoader(());
119-
120-
impl MetadataLoader for DummyMetadataLoader {
121-
fn get_rlib_metadata(
122-
&self,
123-
_target: &Target,
124-
_filename: &Path
125-
) -> Result<MetadataRef, String> {
126-
bug!("DummyMetadataLoader::get_rlib_metadata");
127-
}
128-
129-
fn get_dylib_metadata(
130-
&self,
131-
_target: &Target,
132-
_filename: &Path
133-
) -> Result<MetadataRef, String> {
134-
bug!("DummyMetadataLoader::get_dylib_metadata");
135-
}
136-
}
137-
13882
pub struct NoLlvmMetadataLoader;
13983

14084
impl MetadataLoader for NoLlvmMetadataLoader {
14185
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
142-
let file = File::open(filename)
86+
let mut file = File::open(filename)
14387
.map_err(|e| format!("metadata file open err: {:?}", e))?;
144-
let mut archive = Archive::new(file);
145-
146-
while let Some(entry_result) = archive.next_entry() {
147-
let mut entry = entry_result
148-
.map_err(|e| format!("metadata section read err: {:?}", e))?;
149-
if entry.header().identifier() == "rust.metadata.bin" {
150-
let mut buf = Vec::new();
151-
io::copy(&mut entry, &mut buf).unwrap();
152-
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
153-
return Ok(rustc_erase_owner!(buf.map_owner_box()));
154-
}
155-
}
15688

157-
Err("Couldn't find metadata section".to_string())
89+
let mut buf = Vec::new();
90+
io::copy(&mut file, &mut buf).unwrap();
91+
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
92+
return Ok(rustc_erase_owner!(buf.map_owner_box()));
15893
}
15994

160-
fn get_dylib_metadata(
161-
&self,
162-
_target: &Target,
163-
_filename: &Path,
164-
) -> Result<MetadataRef, String> {
165-
// FIXME: Support reading dylibs from llvm enabled rustc
166-
self.get_rlib_metadata(_target, _filename)
95+
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
96+
self.get_rlib_metadata(target, filename)
16797
}
16898
}
16999

@@ -205,8 +135,13 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
205135
providers.target_features_whitelist = |_tcx, _cnum| {
206136
Lrc::new(FxHashMap()) // Just a dummy
207137
};
138+
providers.is_reachable_non_generic = |_tcx, _defid| true;
139+
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
140+
providers.wasm_custom_sections = |_tcx, _crate| Lrc::new(Vec::new());
141+
}
142+
fn provide_extern(&self, providers: &mut Providers) {
143+
providers.is_reachable_non_generic = |_tcx, _defid| true;
208144
}
209-
fn provide_extern(&self, _providers: &mut Providers) {}
210145

211146
fn codegen_crate<'a, 'tcx>(
212147
&self,
@@ -225,7 +160,8 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
225160
collector::MonoItemCollectionMode::Eager
226161
).0.iter()
227162
);
228-
::rustc::middle::dependency_format::calculate(tcx);
163+
// FIXME: Fix this
164+
// ::rustc::middle::dependency_format::calculate(tcx);
229165
let _ = tcx.link_args(LOCAL_CRATE);
230166
let _ = tcx.native_libraries(LOCAL_CRATE);
231167
for mono_item in
@@ -280,9 +216,8 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
280216
} else {
281217
&ongoing_codegen.metadata.raw_data
282218
};
283-
let mut builder = Builder::new(File::create(&output_name).unwrap());
284-
let header = Header::new("rust.metadata.bin".to_string(), metadata.len() as u64);
285-
builder.append(&header, Cursor::new(metadata)).unwrap();
219+
let mut file = File::create(&output_name).unwrap();
220+
file.write_all(metadata).unwrap();
286221
}
287222

288223
sess.abort_if_errors();

src/librustc_codegen_utils/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#![recursion_limit="256"]
2727

28-
extern crate ar;
2928
extern crate flate2;
3029
#[macro_use]
3130
extern crate log;
@@ -39,8 +38,6 @@ extern crate syntax;
3938
extern crate syntax_pos;
4039
#[macro_use] extern crate rustc_data_structures;
4140

42-
pub extern crate rustc as __rustc;
43-
4441
use rustc::ty::TyCtxt;
4542

4643
pub mod link;

src/librustc_driver/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ serialize = { path = "../libserialize" }
3737
syntax = { path = "../libsyntax" }
3838
syntax_ext = { path = "../libsyntax_ext" }
3939
syntax_pos = { path = "../libsyntax_pos" }
40-
41-
ar = "0.3.0"

src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ all:
44
/bin/echo || exit 0 # This test requires /bin/echo to exist
55
$(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \
66
-o $(TMPDIR)/the_backend.dylib
7-
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type bin -o $(TMPDIR)/some_crate \
7+
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
88
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options
99
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/some_crate

src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn main() {
12-
::std::process::exit(1);
13-
}
11+
#![feature(no_core)]
12+
#![no_core]

src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl CodegenBackend for TheBackend {
6363
let crate_name = ongoing_codegen.downcast::<Symbol>()
6464
.expect("in join_codegen_and_link: ongoing_codegen is not a Symbol");
6565
for &crate_type in sess.opts.crate_types.iter() {
66-
if crate_type != CrateType::CrateTypeExecutable {
66+
if crate_type != CrateType::CrateTypeRlib {
6767
sess.fatal(&format!("Crate type is {:?}", crate_type));
6868
}
6969
let output_name =

src/tools/tidy/src/deps.rs

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ static WHITELIST_CRATES: &'static [CrateVersion] = &[
5959
/// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
6060
static WHITELIST: &'static [Crate] = &[
6161
Crate("aho-corasick"),
62-
Crate("ar"),
6362
Crate("arrayvec"),
6463
Crate("atty"),
6564
Crate("backtrace"),

0 commit comments

Comments
 (0)