Skip to content

Commit fa78d5b

Browse files
committed
Auto merge of #41565 - rkruppe:llvm-sys, r=eddyb
Make only rustc_trans depend on rustc_llvm With these changes, only rustc_trans depends directly on rustc_llvm (and no crate gained a new dependency on trans). This means changing LLVM doesn't rebuild librustc or rustc_metadata, only rustc_trans, rustc_driver and the rustc executable Also, rustc_driver technically doesn't know about LLVM any more (of course, it still handles a ton of options that conceptually refer to LLVM, but it delegates their implementation to trans). What I *didn't* implement was merging most or all of rustc_llvm into rustc_trans. I ran into a nasty bug, which was probably just a silly typo somewhere but I probably won't have the time to figure it out in the next week or two. I opened #41699 for that step. Fixes #41473
2 parents ae33d99 + 04a16ff commit fa78d5b

28 files changed

+425
-327
lines changed

src/Cargo.lock

+18-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ arena = { path = "../libarena" }
1313
fmt_macros = { path = "../libfmt_macros" }
1414
graphviz = { path = "../libgraphviz" }
1515
log = "0.3"
16+
owning_ref = "0.3.3"
1617
rustc_back = { path = "../librustc_back" }
1718
rustc_bitflags = { path = "../librustc_bitflags" }
1819
rustc_const_math = { path = "../librustc_const_math" }
1920
rustc_data_structures = { path = "../librustc_data_structures" }
2021
rustc_errors = { path = "../librustc_errors" }
21-
rustc_llvm = { path = "../librustc_llvm" }
2222
serialize = { path = "../libserialize" }
2323
syntax = { path = "../libsyntax" }
2424
syntax_pos = { path = "../libsyntax_pos" }

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern crate fmt_macros;
5454
extern crate getopts;
5555
extern crate graphviz;
5656
extern crate libc;
57-
extern crate rustc_llvm as llvm;
57+
extern crate owning_ref;
5858
extern crate rustc_back;
5959
extern crate rustc_data_structures;
6060
extern crate serialize;

src/librustc/middle/cstore.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ use session::search_paths::PathKind;
3636
use util::nodemap::{NodeSet, DefIdMap};
3737

3838
use std::any::Any;
39-
use std::path::PathBuf;
39+
use std::path::{Path, PathBuf};
4040
use std::rc::Rc;
41+
use owning_ref::ErasedBoxRef;
4142
use syntax::ast;
4243
use syntax::ext::base::SyntaxExtension;
4344
use syntax::symbol::Symbol;
@@ -201,11 +202,33 @@ impl EncodedMetadataHashes {
201202
}
202203
}
203204

205+
/// The backend's way to give the crate store access to the metadata in a library.
206+
/// Note that it returns the raw metadata bytes stored in the library file, whether
207+
/// it is compressed, uncompressed, some weird mix, etc.
208+
/// rmeta files are backend independent and not handled here.
209+
///
210+
/// At the time of this writing, there is only one backend and one way to store
211+
/// metadata in library -- this trait just serves to decouple rustc_metadata from
212+
/// the archive reader, which depends on LLVM.
213+
pub trait MetadataLoader {
214+
fn get_rlib_metadata(&self,
215+
target: &Target,
216+
filename: &Path)
217+
-> Result<ErasedBoxRef<[u8]>, String>;
218+
fn get_dylib_metadata(&self,
219+
target: &Target,
220+
filename: &Path)
221+
-> Result<ErasedBoxRef<[u8]>, String>;
222+
}
223+
204224
/// A store of Rust crates, through with their metadata
205225
/// can be accessed.
206226
pub trait CrateStore {
207227
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
208228

229+
// access to the metadata loader
230+
fn metadata_loader(&self) -> &MetadataLoader;
231+
209232
// item info
210233
fn visibility(&self, def: DefId) -> ty::Visibility;
211234
fn visible_parent_map<'a>(&'a self) -> ::std::cell::Ref<'a, DefIdMap<DefId>>;
@@ -275,8 +298,6 @@ pub trait CrateStore {
275298
fn used_link_args(&self) -> Vec<String>;
276299

277300
// utility functions
278-
fn metadata_filename(&self) -> &str;
279-
fn metadata_section_name(&self, target: &Target) -> &str;
280301
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
281302
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
282303
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
@@ -413,8 +434,6 @@ impl CrateStore for DummyCrateStore {
413434
fn used_link_args(&self) -> Vec<String> { vec![] }
414435

415436
// utility functions
416-
fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
417-
fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
418437
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
419438
{ vec![] }
420439
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
@@ -427,6 +446,9 @@ impl CrateStore for DummyCrateStore {
427446
bug!("encode_metadata")
428447
}
429448
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
449+
450+
// access to the metadata loader
451+
fn metadata_loader(&self) -> &MetadataLoader { bug!("metadata_loader") }
430452
}
431453

432454
pub trait CrateLoader {

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ top_level_options!(
328328
}
329329
);
330330

331-
#[derive(Clone, PartialEq, Eq)]
331+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
332332
pub enum PrintRequest {
333333
FileNames,
334334
Sysroot,

src/librustc/session/mod.rs

-54
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@ use syntax_pos::{Span, MultiSpan, FileMap};
3737
use rustc_back::{LinkerFlavor, PanicStrategy};
3838
use rustc_back::target::Target;
3939
use rustc_data_structures::flock;
40-
use llvm;
4140

4241
use std::path::{Path, PathBuf};
4342
use std::cell::{self, Cell, RefCell};
4443
use std::collections::HashMap;
4544
use std::env;
46-
use std::ffi::CString;
4745
use std::io::Write;
4846
use std::rc::Rc;
4947
use std::fmt;
5048
use std::time::Duration;
5149
use std::sync::Arc;
52-
use libc::c_int;
5350

5451
mod code_stats;
5552
pub mod config;
@@ -713,8 +710,6 @@ pub fn build_session_(sopts: config::Options,
713710
out_of_fuel: Cell::new(false),
714711
};
715712

716-
init_llvm(&sess);
717-
718713
sess
719714
}
720715

@@ -743,55 +738,6 @@ pub enum IncrCompSession {
743738
}
744739
}
745740

746-
fn init_llvm(sess: &Session) {
747-
unsafe {
748-
// Before we touch LLVM, make sure that multithreading is enabled.
749-
use std::sync::Once;
750-
static INIT: Once = Once::new();
751-
static mut POISONED: bool = false;
752-
INIT.call_once(|| {
753-
if llvm::LLVMStartMultithreaded() != 1 {
754-
// use an extra bool to make sure that all future usage of LLVM
755-
// cannot proceed despite the Once not running more than once.
756-
POISONED = true;
757-
}
758-
759-
configure_llvm(sess);
760-
});
761-
762-
if POISONED {
763-
bug!("couldn't enable multi-threaded LLVM");
764-
}
765-
}
766-
}
767-
768-
unsafe fn configure_llvm(sess: &Session) {
769-
let mut llvm_c_strs = Vec::new();
770-
let mut llvm_args = Vec::new();
771-
772-
{
773-
let mut add = |arg: &str| {
774-
let s = CString::new(arg).unwrap();
775-
llvm_args.push(s.as_ptr());
776-
llvm_c_strs.push(s);
777-
};
778-
add("rustc"); // fake program name
779-
if sess.time_llvm_passes() { add("-time-passes"); }
780-
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
781-
782-
for arg in &sess.opts.cg.llvm_args {
783-
add(&(*arg));
784-
}
785-
}
786-
787-
llvm::LLVMInitializePasses();
788-
789-
llvm::initialize_available_targets();
790-
791-
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
792-
llvm_args.as_ptr());
793-
}
794-
795741
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
796742
let emitter: Box<Emitter> = match output {
797743
config::ErrorOutputType::HumanReadable(color_config) => {

src/librustc_driver/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ rustc_data_structures = { path = "../librustc_data_structures" }
2222
rustc_errors = { path = "../librustc_errors" }
2323
rustc_incremental = { path = "../librustc_incremental" }
2424
rustc_lint = { path = "../librustc_lint" }
25-
rustc_llvm = { path = "../librustc_llvm" }
2625
rustc_metadata = { path = "../librustc_metadata" }
2726
rustc_mir = { path = "../librustc_mir" }
2827
rustc_passes = { path = "../librustc_passes" }

0 commit comments

Comments
 (0)