Skip to content

Commit 3df1f7b

Browse files
committed
Auto merge of #44085 - bjorn3:no_llvm_write_metadata, r=arielb1
Allow writing metadata without llvm # Todo: * [x] Rebase * [x] Fix eventual errors * [x] <strike>Find some crate to write elf files</strike> (will do it later) Cc #43842
2 parents 91dbf52 + 843cd5b commit 3df1f7b

File tree

13 files changed

+523
-267
lines changed

13 files changed

+523
-267
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ version.texi
103103
.cargo
104104
!src/vendor/**
105105
/src/target/
106+
107+
no_llvm_build
108+

src/Cargo.lock

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

src/bootstrap/builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,10 @@ impl<'a> Builder<'a> {
531531
// For other crates, however, we know that we've already got a standard
532532
// library up and running, so we can use the normal compiler to compile
533533
// build scripts in that situation.
534-
if mode == Mode::Libstd {
534+
//
535+
// If LLVM support is disabled we need to use the snapshot compiler to compile
536+
// build scripts, as the new compiler doesnt support executables.
537+
if mode == Mode::Libstd || !self.build.config.llvm_enabled {
535538
cargo.env("RUSTC_SNAPSHOT", &self.initial_rustc)
536539
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
537540
} else {

src/librustc_driver/driver.rs

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

11-
#![cfg_attr(not(feature="llvm"), allow(dead_code))]
12-
1311
use rustc::dep_graph::DepGraph;
1412
use rustc::hir::{self, map as hir_map};
1513
use rustc::hir::lowering::lower_crate;
@@ -34,15 +32,16 @@ use rustc_incremental;
3432
use rustc_resolve::{MakeGlobMap, Resolver};
3533
use rustc_metadata::creader::CrateLoader;
3634
use rustc_metadata::cstore::{self, CStore};
37-
use rustc_trans::back::write;
3835
use rustc_trans as trans;
36+
use rustc_trans_utils::trans_crate::TransCrate;
3937
use rustc_typeck as typeck;
4038
use rustc_privacy;
4139
use rustc_plugin::registry::Registry;
4240
use rustc_plugin as plugin;
4341
use rustc_passes::{ast_validation, no_asm, loops, consts, static_recursion, hir_stats};
4442
use rustc_const_eval::{self, check_match};
4543
use super::Compilation;
44+
use ::DefaultTransCrate;
4645

4746
use serialize::json;
4847

@@ -76,7 +75,8 @@ pub fn compile_input(sess: &Session,
7675
output: &Option<PathBuf>,
7776
addl_plugins: Option<Vec<String>>,
7877
control: &CompileController) -> CompileResult {
79-
use rustc_trans::back::write::OngoingCrateTranslation;
78+
use rustc::session::config::CrateType;
79+
8080
macro_rules! controller_entry_point {
8181
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
8282
let state = &mut $make_state;
@@ -94,17 +94,16 @@ pub fn compile_input(sess: &Session,
9494
}
9595

9696
if cfg!(not(feature="llvm")) {
97-
use rustc::session::config::CrateType;
98-
if !sess.opts.debugging_opts.no_trans && sess.opts.output_types.should_trans() {
99-
sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
100-
}
101-
102-
if sess.opts.crate_types.iter().all(|&t|{
103-
t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
104-
}) && !sess.opts.crate_types.is_empty() {
105-
sess.err(
106-
"LLVM is not supported by this rustc, so non rlib libraries are not supported"
107-
);
97+
for cty in sess.opts.crate_types.iter() {
98+
match *cty {
99+
CrateType::CrateTypeRlib | CrateType::CrateTypeDylib |
100+
CrateType::CrateTypeExecutable => {},
101+
_ => {
102+
sess.parse_sess.span_diagnostic.warn(
103+
&format!("LLVM unsupported, so output type {} is not supported", cty)
104+
);
105+
},
106+
}
108107
}
109108

110109
sess.abort_if_errors();
@@ -117,7 +116,7 @@ pub fn compile_input(sess: &Session,
117116
// We need nested scopes here, because the intermediate results can keep
118117
// large chunks of memory alive and we want to free them as soon as
119118
// possible to keep the peak memory usage low
120-
let (outputs, trans, dep_graph): (OutputFilenames, OngoingCrateTranslation, DepGraph) = {
119+
let (outputs, trans, dep_graph) = {
121120
let krate = match phase_1_parse_input(control, sess, input) {
122121
Ok(krate) => krate,
123122
Err(mut parse_error) => {
@@ -246,7 +245,7 @@ pub fn compile_input(sess: &Session,
246245
tcx.print_debug_stats();
247246
}
248247

249-
let trans = phase_4_translate_to_llvm(tcx, rx);
248+
let trans = phase_4_translate_to_llvm::<DefaultTransCrate>(tcx, rx);
250249

251250
if log_enabled!(::log::LogLevel::Info) {
252251
println!("Post-trans");
@@ -264,44 +263,42 @@ pub fn compile_input(sess: &Session,
264263
})??
265264
};
266265

267-
if cfg!(not(feature="llvm")) {
268-
let (_, _) = (outputs, trans);
269-
sess.fatal("LLVM is not supported by this rustc");
266+
if sess.opts.debugging_opts.print_type_sizes {
267+
sess.code_stats.borrow().print_type_sizes();
270268
}
271269

272-
#[cfg(feature="llvm")]
273-
{
274-
if sess.opts.debugging_opts.print_type_sizes {
275-
sess.code_stats.borrow().print_type_sizes();
276-
}
277-
278-
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, &dep_graph, trans);
270+
let (phase5_result, trans) =
271+
phase_5_run_llvm_passes::<DefaultTransCrate>(sess, &dep_graph, trans);
279272

280-
controller_entry_point!(after_llvm,
281-
sess,
282-
CompileState::state_after_llvm(input, sess, outdir, output, &trans),
283-
phase5_result);
284-
phase5_result?;
273+
controller_entry_point!(after_llvm,
274+
sess,
275+
CompileState::state_after_llvm(input, sess, outdir, output, &trans),
276+
phase5_result);
277+
phase5_result?;
285278

286-
phase_6_link_output(sess, &trans, &outputs);
287-
288-
// Now that we won't touch anything in the incremental compilation directory
289-
// any more, we can finalize it (which involves renaming it)
290-
rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash);
279+
// Run the linker on any artifacts that resulted from the LLVM run.
280+
// This should produce either a finished executable or library.
281+
time(sess.time_passes(), "linking", || {
282+
DefaultTransCrate::link_binary(sess, &trans, &outputs)
283+
});
291284

292-
if sess.opts.debugging_opts.perf_stats {
293-
sess.print_perf_stats();
294-
}
285+
// Now that we won't touch anything in the incremental compilation directory
286+
// any more, we can finalize it (which involves renaming it)
287+
#[cfg(feature="llvm")]
288+
rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash);
295289

296-
controller_entry_point!(
297-
compilation_done,
298-
sess,
299-
CompileState::state_when_compilation_done(input, sess, outdir, output),
300-
Ok(())
301-
);
290+
if sess.opts.debugging_opts.perf_stats {
291+
sess.print_perf_stats();
292+
}
302293

294+
controller_entry_point!(
295+
compilation_done,
296+
sess,
297+
CompileState::state_when_compilation_done(input, sess, outdir, output),
303298
Ok(())
304-
}
299+
);
300+
301+
Ok(())
305302
}
306303

307304
fn keep_hygiene_data(sess: &Session) -> bool {
@@ -970,7 +967,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
970967
mir::provide(&mut local_providers);
971968
reachable::provide(&mut local_providers);
972969
rustc_privacy::provide(&mut local_providers);
973-
trans::provide_local(&mut local_providers);
970+
DefaultTransCrate::provide_local(&mut local_providers);
974971
typeck::provide(&mut local_providers);
975972
ty::provide(&mut local_providers);
976973
traits::provide(&mut local_providers);
@@ -982,7 +979,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
982979

983980
let mut extern_providers = ty::maps::Providers::default();
984981
cstore::provide(&mut extern_providers);
985-
trans::provide_extern(&mut extern_providers);
982+
DefaultTransCrate::provide_extern(&mut extern_providers);
986983
ty::provide_extern(&mut extern_providers);
987984
traits::provide_extern(&mut extern_providers);
988985
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
@@ -1126,9 +1123,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
11261123

11271124
/// Run the translation phase to LLVM, after which the AST and analysis can
11281125
/// be discarded.
1129-
pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1126+
pub fn phase_4_translate_to_llvm<'a, 'tcx, Trans: TransCrate>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11301127
rx: mpsc::Receiver<Box<Any + Send>>)
1131-
-> write::OngoingCrateTranslation {
1128+
-> <Trans as TransCrate>::OngoingCrateTranslation {
11321129
let time_passes = tcx.sess.time_passes();
11331130

11341131
time(time_passes,
@@ -1137,9 +1134,8 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11371134

11381135
let translation =
11391136
time(time_passes, "translation", move || {
1140-
trans::trans_crate(tcx, rx)
1137+
Trans::trans_crate(tcx, rx)
11411138
});
1142-
11431139
if tcx.sess.profile_queries() {
11441140
profile::dump("profile_queries".to_string())
11451141
}
@@ -1149,15 +1145,14 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11491145

11501146
/// Run LLVM itself, producing a bitcode file, assembly file or object file
11511147
/// as a side effect.
1152-
#[cfg(feature="llvm")]
1153-
pub fn phase_5_run_llvm_passes(sess: &Session,
1148+
pub fn phase_5_run_llvm_passes<Trans: TransCrate>(sess: &Session,
11541149
dep_graph: &DepGraph,
1155-
trans: write::OngoingCrateTranslation)
1156-
-> (CompileResult, trans::CrateTranslation) {
1157-
let trans = trans.join(sess, dep_graph);
1150+
trans: <Trans as TransCrate>::OngoingCrateTranslation)
1151+
-> (CompileResult, <Trans as TransCrate>::TranslatedCrate) {
1152+
let trans = Trans::join_trans(trans, sess, dep_graph);
11581153

11591154
if sess.opts.debugging_opts.incremental_info {
1160-
write::dump_incremental_data(&trans);
1155+
Trans::dump_incremental_data(&trans);
11611156
}
11621157

11631158
time(sess.time_passes(),
@@ -1167,20 +1162,6 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11671162
(sess.compile_status(), trans)
11681163
}
11691164

1170-
/// Run the linker on any artifacts that resulted from the LLVM run.
1171-
/// This should produce either a finished executable or library.
1172-
#[cfg(feature="llvm")]
1173-
pub fn phase_6_link_output(sess: &Session,
1174-
trans: &trans::CrateTranslation,
1175-
outputs: &OutputFilenames) {
1176-
time(sess.time_passes(), "linking", || {
1177-
::rustc_trans::back::link::link_binary(sess,
1178-
trans,
1179-
outputs,
1180-
&trans.crate_name.as_str())
1181-
});
1182-
}
1183-
11841165
fn escape_dep_filename(filename: &str) -> String {
11851166
// Apparently clang and gcc *only* escape spaces:
11861167
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4

0 commit comments

Comments
 (0)