Skip to content

Commit e324594

Browse files
committed
Auto merge of #43842 - bjorn3:no_llvm_cleanup, r=alexcrichton
Cleanup for "Support compiling rustc without LLVM (try 2)" This includes a small patch to allow running tests without llvm. Also check if you are not trying to compile a dylib. cc #42932 r? @alexcrichton
2 parents f3cf206 + 005bc2c commit e324594

File tree

5 files changed

+144
-141
lines changed

5 files changed

+144
-141
lines changed

src/bootstrap/check.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,6 @@ impl Step for Compiletest {
618618
if let Some(ref dir) = build.lldb_python_dir {
619619
cmd.arg("--lldb-python-dir").arg(dir);
620620
}
621-
let llvm_config = build.llvm_config(target);
622-
let llvm_version = output(Command::new(&llvm_config).arg("--version"));
623-
cmd.arg("--llvm-version").arg(llvm_version);
624-
if !build.is_rust_llvm(target) {
625-
cmd.arg("--system-llvm");
626-
}
627621

628622
cmd.args(&build.config.cmd.test_args());
629623

@@ -635,17 +629,32 @@ impl Step for Compiletest {
635629
cmd.arg("--quiet");
636630
}
637631

638-
// Only pass correct values for these flags for the `run-make` suite as it
639-
// requires that a C++ compiler was configured which isn't always the case.
640-
if suite == "run-make" {
641-
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
642-
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
643-
cmd.arg("--cc").arg(build.cc(target))
644-
.arg("--cxx").arg(build.cxx(target).unwrap())
645-
.arg("--cflags").arg(build.cflags(target).join(" "))
646-
.arg("--llvm-components").arg(llvm_components.trim())
647-
.arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
648-
} else {
632+
if build.config.llvm_enabled {
633+
let llvm_config = build.llvm_config(target);
634+
let llvm_version = output(Command::new(&llvm_config).arg("--version"));
635+
cmd.arg("--llvm-version").arg(llvm_version);
636+
if !build.is_rust_llvm(target) {
637+
cmd.arg("--system-llvm");
638+
}
639+
640+
// Only pass correct values for these flags for the `run-make` suite as it
641+
// requires that a C++ compiler was configured which isn't always the case.
642+
if suite == "run-make" {
643+
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
644+
let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
645+
cmd.arg("--cc").arg(build.cc(target))
646+
.arg("--cxx").arg(build.cxx(target).unwrap())
647+
.arg("--cflags").arg(build.cflags(target).join(" "))
648+
.arg("--llvm-components").arg(llvm_components.trim())
649+
.arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
650+
}
651+
}
652+
if suite == "run-make" && !build.config.llvm_enabled {
653+
println!("Ignoring run-make test suite as they generally dont work without LLVM");
654+
return;
655+
}
656+
657+
if suite != "run-make" {
649658
cmd.arg("--cc").arg("")
650659
.arg("--cxx").arg("")
651660
.arg("--cflags").arg("")

src/librustc_driver/driver.rs

+27-35
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
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+
1113
use rustc::hir::{self, map as hir_map};
1214
use rustc::hir::lowering::lower_crate;
1315
use rustc::ich::Fingerprint;
@@ -19,8 +21,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
1921
use rustc::session::search_paths::PathKind;
2022
use rustc::lint;
2123
use rustc::middle::{self, stability, reachable};
22-
#[cfg(feature="llvm")]
23-
use rustc::middle::dependency_format;
2424
use rustc::middle::privacy::AccessLevels;
2525
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
2626
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
@@ -33,9 +33,7 @@ use rustc_incremental::{self, IncrementalHashesMap};
3333
use rustc_resolve::{MakeGlobMap, Resolver};
3434
use rustc_metadata::creader::CrateLoader;
3535
use rustc_metadata::cstore::{self, CStore};
36-
#[cfg(feature="llvm")]
37-
use rustc_trans::back::{link, write};
38-
#[cfg(feature="llvm")]
36+
use rustc_trans::back::write;
3937
use rustc_trans as trans;
4038
use rustc_typeck as typeck;
4139
use rustc_privacy;
@@ -73,11 +71,7 @@ pub fn compile_input(sess: &Session,
7371
output: &Option<PathBuf>,
7472
addl_plugins: Option<Vec<String>>,
7573
control: &CompileController) -> CompileResult {
76-
#[cfg(feature="llvm")]
7774
use rustc_trans::back::write::OngoingCrateTranslation;
78-
#[cfg(not(feature="llvm"))]
79-
type OngoingCrateTranslation = ();
80-
8175
macro_rules! controller_entry_point {
8276
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
8377
let state = &mut $make_state;
@@ -94,6 +88,23 @@ pub fn compile_input(sess: &Session,
9488
}}
9589
}
9690

91+
if cfg!(not(feature="llvm")) {
92+
use rustc::session::config::CrateType;
93+
if !sess.opts.debugging_opts.no_trans && sess.opts.output_types.should_trans() {
94+
sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
95+
}
96+
97+
if sess.opts.crate_types.iter().all(|&t|{
98+
t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
99+
}) && !sess.opts.crate_types.is_empty() {
100+
sess.err(
101+
"LLVM is not supported by this rustc, so non rlib libraries are not supported"
102+
);
103+
}
104+
105+
sess.abort_if_errors();
106+
}
107+
97108
// We need nested scopes here, because the intermediate results can keep
98109
// large chunks of memory alive and we want to free them as soon as
99110
// possible to keep the peak memory usage low
@@ -217,7 +228,6 @@ pub fn compile_input(sess: &Session,
217228
tcx.print_debug_stats();
218229
}
219230

220-
#[cfg(feature="llvm")]
221231
let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
222232
&outputs);
223233

@@ -233,24 +243,13 @@ pub fn compile_input(sess: &Session,
233243
}
234244
}
235245

236-
#[cfg(not(feature="llvm"))]
237-
{
238-
let _ = incremental_hashes_map;
239-
sess.err(&format!("LLVM is not supported by this rustc"));
240-
sess.abort_if_errors();
241-
unreachable!();
242-
}
243-
244-
#[cfg(feature="llvm")]
245246
Ok((outputs, trans))
246247
})??
247248
};
248249

249-
#[cfg(not(feature="llvm"))]
250-
{
251-
let _ = outputs;
252-
let _ = trans;
253-
unreachable!();
250+
if cfg!(not(feature="llvm")) {
251+
let (_, _) = (outputs, trans);
252+
sess.fatal("LLVM is not supported by this rustc");
254253
}
255254

256255
#[cfg(feature="llvm")]
@@ -393,7 +392,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
393392
pub resolutions: Option<&'a Resolutions>,
394393
pub analysis: Option<&'a ty::CrateAnalysis>,
395394
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
396-
#[cfg(feature="llvm")]
397395
pub trans: Option<&'a trans::CrateTranslation>,
398396
}
399397

@@ -420,7 +418,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
420418
resolutions: None,
421419
analysis: None,
422420
tcx: None,
423-
#[cfg(feature="llvm")]
424421
trans: None,
425422
}
426423
}
@@ -509,7 +506,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
509506
}
510507
}
511508

512-
#[cfg(feature="llvm")]
513509
fn state_after_llvm(input: &'a Input,
514510
session: &'tcx Session,
515511
out_dir: &'a Option<PathBuf>,
@@ -523,7 +519,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
523519
}
524520
}
525521

526-
#[cfg(feature="llvm")]
527522
fn state_when_compilation_done(input: &'a Input,
528523
session: &'tcx Session,
529524
out_dir: &'a Option<PathBuf>,
@@ -942,7 +937,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
942937
mir::provide(&mut local_providers);
943938
reachable::provide(&mut local_providers);
944939
rustc_privacy::provide(&mut local_providers);
945-
#[cfg(feature="llvm")]
946940
trans::provide(&mut local_providers);
947941
typeck::provide(&mut local_providers);
948942
ty::provide(&mut local_providers);
@@ -955,7 +949,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
955949

956950
let mut extern_providers = ty::maps::Providers::default();
957951
cstore::provide(&mut extern_providers);
958-
#[cfg(feature="llvm")]
959952
trans::provide(&mut extern_providers);
960953
ty::provide_extern(&mut extern_providers);
961954
traits::provide_extern(&mut extern_providers);
@@ -1102,7 +1095,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
11021095

11031096
/// Run the translation phase to LLVM, after which the AST and analysis can
11041097
/// be discarded.
1105-
#[cfg(feature="llvm")]
11061098
pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11071099
analysis: ty::CrateAnalysis,
11081100
incremental_hashes_map: IncrementalHashesMap,
@@ -1112,7 +1104,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11121104

11131105
time(time_passes,
11141106
"resolving dependency formats",
1115-
|| dependency_format::calculate(tcx));
1107+
|| ::rustc::middle::dependency_format::calculate(tcx));
11161108

11171109
let translation =
11181110
time(time_passes,
@@ -1147,9 +1139,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11471139
pub fn phase_6_link_output(sess: &Session,
11481140
trans: &trans::CrateTranslation,
11491141
outputs: &OutputFilenames) {
1150-
time(sess.time_passes(),
1151-
"linking",
1152-
|| link::link_binary(sess, trans, outputs, &trans.crate_name.as_str()));
1142+
time(sess.time_passes(), "linking", || {
1143+
::rustc_trans::back::link::link_binary(sess, trans, outputs, &trans.crate_name.as_str())
1144+
});
11531145
}
11541146

11551147
fn escape_dep_filename(filename: &str) -> String {

0 commit comments

Comments
 (0)