Skip to content

Commit 0c97bbf

Browse files
committed
Remove some more cfg's
1 parent 03584a2 commit 0c97bbf

File tree

4 files changed

+119
-106
lines changed

4 files changed

+119
-106
lines changed

src/bootstrap/check.rs

Lines changed: 26 additions & 17 deletions
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.flags.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");
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

Lines changed: 27 additions & 28 deletions
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,8 +71,6 @@ pub fn compile_input(sess: &Session,
7371
output: &Option<PathBuf>,
7472
addl_plugins: Option<Vec<String>>,
7573
control: &CompileController) -> CompileResult {
76-
use rustc_trans::back::write::OngoingCrateTranslation;
77-
7874
macro_rules! controller_entry_point {
7975
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
8076
let state = &mut $make_state;
@@ -91,10 +87,27 @@ pub fn compile_input(sess: &Session,
9187
}}
9288
}
9389

90+
if cfg!(not(feature="llvm")) {
91+
use rustc::session::config::CrateType;
92+
if !sess.opts.debugging_opts.no_trans && sess.opts.output_types.should_trans() {
93+
sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
94+
}
95+
96+
if sess.opts.crate_types.iter().all(|&t|{
97+
t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
98+
}) {
99+
sess.err(
100+
"LLVM is not supported by this rustc, so non rlib libraries are not supported"
101+
);
102+
}
103+
104+
sess.abort_if_errors();
105+
}
106+
94107
// We need nested scopes here, because the intermediate results can keep
95108
// large chunks of memory alive and we want to free them as soon as
96109
// possible to keep the peak memory usage low
97-
let (outputs, trans): (OutputFilenames, OngoingCrateTranslation) = {
110+
let (outputs, trans): (OutputFilenames, write::OngoingCrateTranslation) = {
98111
let krate = match phase_1_parse_input(control, sess, input) {
99112
Ok(krate) => krate,
100113
Err(mut parse_error) => {
@@ -214,7 +227,6 @@ pub fn compile_input(sess: &Session,
214227
tcx.print_debug_stats();
215228
}
216229

217-
#[cfg(feature="llvm")]
218230
let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
219231
&outputs);
220232

@@ -230,24 +242,14 @@ pub fn compile_input(sess: &Session,
230242
}
231243
}
232244

233-
#[cfg(not(feature="llvm"))]
234-
{
235-
let _ = incremental_hashes_map;
236-
sess.err(&format!("LLVM is not supported by this rustc"));
237-
sess.abort_if_errors();
238-
unreachable!();
239-
}
240-
241-
#[cfg(feature="llvm")]
242245
Ok((outputs, trans))
243246
})??
244247
};
245248

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

253255
#[cfg(feature="llvm")]
@@ -504,7 +506,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
504506
}
505507
}
506508

507-
#[cfg(feature="llvm")]
508509
fn state_after_llvm(input: &'a Input,
509510
session: &'tcx Session,
510511
out_dir: &'a Option<PathBuf>,
@@ -518,7 +519,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
518519
}
519520
}
520521

521-
#[cfg(feature="llvm")]
522522
fn state_when_compilation_done(input: &'a Input,
523523
session: &'tcx Session,
524524
out_dir: &'a Option<PathBuf>,
@@ -1095,7 +1095,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
10951095

10961096
/// Run the translation phase to LLVM, after which the AST and analysis can
10971097
/// be discarded.
1098-
#[cfg(feature="llvm")]
10991098
pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11001099
analysis: ty::CrateAnalysis,
11011100
incremental_hashes_map: IncrementalHashesMap,
@@ -1105,7 +1104,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11051104

11061105
time(time_passes,
11071106
"resolving dependency formats",
1108-
|| dependency_format::calculate(tcx));
1107+
|| ::rustc::middle::dependency_format::calculate(tcx));
11091108

11101109
let translation =
11111110
time(time_passes,
@@ -1140,9 +1139,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11401139
pub fn phase_6_link_output(sess: &Session,
11411140
trans: &trans::CrateTranslation,
11421141
outputs: &OutputFilenames) {
1143-
time(sess.time_passes(),
1144-
"linking",
1145-
|| 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+
});
11461145
}
11471146

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

0 commit comments

Comments
 (0)