Skip to content

Commit edd82ee

Browse files
committed
Auto merge of #42932 - bjorn3:no_llvm_try2, r=eddyb
Support compiling rustc without LLVM (try 2) Now doesn't change rustc_driver. Supersedes #42752
2 parents 38bdbb7 + e539996 commit edd82ee

File tree

15 files changed

+416
-154
lines changed

15 files changed

+416
-154
lines changed

Diff for: src/Cargo.lock

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

Diff for: src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub struct Config {
5353
pub profiler: bool,
5454

5555
// llvm codegen options
56+
pub llvm_enabled: bool,
5657
pub llvm_assertions: bool,
5758
pub llvm_optimize: bool,
5859
pub llvm_release_debuginfo: bool,
@@ -192,6 +193,7 @@ struct Install {
192193
#[derive(Deserialize, Default)]
193194
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
194195
struct Llvm {
196+
enabled: Option<bool>,
195197
ccache: Option<StringOrBool>,
196198
ninja: Option<bool>,
197199
assertions: Option<bool>,
@@ -265,6 +267,7 @@ struct TomlTarget {
265267
impl Config {
266268
pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
267269
let mut config = Config::default();
270+
config.llvm_enabled = true;
268271
config.llvm_optimize = true;
269272
config.use_jemalloc = true;
270273
config.backtrace = true;
@@ -345,6 +348,7 @@ impl Config {
345348
Some(StringOrBool::Bool(false)) | None => {}
346349
}
347350
set(&mut config.ninja, llvm.ninja);
351+
set(&mut config.llvm_enabled, llvm.enabled);
348352
set(&mut config.llvm_assertions, llvm.assertions);
349353
set(&mut config.llvm_optimize, llvm.optimize);
350354
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);

Diff for: src/bootstrap/config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# =============================================================================
1515
[llvm]
1616

17+
# Indicates whether rustc will support compilation with LLVM
18+
# note: rustc does not compile without LLVM at the moment
19+
#enabled = true
20+
1721
# Indicates whether the LLVM build is a Release or Debug build
1822
#optimize = true
1923

Diff for: src/bootstrap/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ impl Build {
429429
if self.config.use_jemalloc {
430430
features.push_str(" jemalloc");
431431
}
432+
if self.config.llvm_enabled {
433+
features.push_str(" llvm");
434+
}
432435
features
433436
}
434437

Diff for: src/bootstrap/native.rs

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl Step for Llvm {
5656
fn run(self, builder: &Builder) {
5757
let build = builder.build;
5858
let target = self.target;
59+
60+
// If we're not compiling for LLVM bail out here.
61+
if !build.config.llvm_enabled {
62+
return;
63+
}
64+
5965
// If we're using a custom LLVM bail out here, but we can only use a
6066
// custom LLVM for the build triple.
6167
if let Some(config) = build.config.target_config.get(&target) {

Diff for: src/librustc_driver/Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ crate-type = ["dylib"]
1212
arena = { path = "../libarena" }
1313
graphviz = { path = "../libgraphviz" }
1414
log = { version = "0.3", features = ["release_max_level_info"] }
15+
owning_ref = "0.3.3"
1516
env_logger = { version = "0.4", default-features = false }
1617
rustc = { path = "../librustc" }
1718
rustc_allocator = { path = "../librustc_allocator" }
@@ -29,9 +30,15 @@ rustc_plugin = { path = "../librustc_plugin" }
2930
rustc_privacy = { path = "../librustc_privacy" }
3031
rustc_resolve = { path = "../librustc_resolve" }
3132
rustc_save_analysis = { path = "../librustc_save_analysis" }
32-
rustc_trans = { path = "../librustc_trans" }
33+
rustc_trans = { path = "../librustc_trans", optional = true }
34+
rustc_trans_utils = { path = "../librustc_trans_utils" }
3335
rustc_typeck = { path = "../librustc_typeck" }
3436
serialize = { path = "../libserialize" }
3537
syntax = { path = "../libsyntax" }
3638
syntax_ext = { path = "../libsyntax_ext" }
3739
syntax_pos = { path = "../libsyntax_pos" }
40+
41+
ar = "0.3.0"
42+
43+
[features]
44+
llvm = ["rustc_trans"]

Diff for: src/librustc_driver/driver.rs

+73-27
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use rustc::session::CompileIncomplete;
1818
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
1919
use rustc::session::search_paths::PathKind;
2020
use rustc::lint;
21-
use rustc::middle::{self, dependency_format, stability, reachable};
21+
use rustc::middle::{self, stability, reachable};
22+
#[cfg(feature="llvm")]
23+
use rustc::middle::dependency_format;
2224
use rustc::middle::privacy::AccessLevels;
2325
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
2426
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
@@ -31,7 +33,9 @@ use rustc_incremental::{self, IncrementalHashesMap};
3133
use rustc_resolve::{MakeGlobMap, Resolver};
3234
use rustc_metadata::creader::CrateLoader;
3335
use rustc_metadata::cstore::{self, CStore};
36+
#[cfg(feature="llvm")]
3437
use rustc_trans::back::{link, write};
38+
#[cfg(feature="llvm")]
3539
use rustc_trans as trans;
3640
use rustc_typeck as typeck;
3741
use rustc_privacy;
@@ -69,6 +73,11 @@ pub fn compile_input(sess: &Session,
6973
output: &Option<PathBuf>,
7074
addl_plugins: Option<Vec<String>>,
7175
control: &CompileController) -> CompileResult {
76+
#[cfg(feature="llvm")]
77+
use rustc_trans::back::write::OngoingCrateTranslation;
78+
#[cfg(not(feature="llvm"))]
79+
type OngoingCrateTranslation = ();
80+
7281
macro_rules! controller_entry_point {
7382
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
7483
let state = &mut $make_state;
@@ -88,7 +97,7 @@ pub fn compile_input(sess: &Session,
8897
// We need nested scopes here, because the intermediate results can keep
8998
// large chunks of memory alive and we want to free them as soon as
9099
// possible to keep the peak memory usage low
91-
let (outputs, trans) = {
100+
let (outputs, trans): (OutputFilenames, OngoingCrateTranslation) = {
92101
let krate = match phase_1_parse_input(control, sess, input) {
93102
Ok(krate) => krate,
94103
Err(mut parse_error) => {
@@ -113,7 +122,8 @@ pub fn compile_input(sess: &Session,
113122
};
114123

115124
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
116-
let crate_name = link::find_crate_name(Some(sess), &krate.attrs, input);
125+
let crate_name =
126+
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
117127
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
118128
phase_2_configure_and_expand(
119129
sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map,
@@ -206,6 +216,8 @@ pub fn compile_input(sess: &Session,
206216
println!("Pre-trans");
207217
tcx.print_debug_stats();
208218
}
219+
220+
#[cfg(feature="llvm")]
209221
let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
210222
&outputs);
211223

@@ -221,38 +233,59 @@ pub fn compile_input(sess: &Session,
221233
}
222234
}
223235

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")]
224245
Ok((outputs, trans))
225246
})??
226247
};
227248

228-
if sess.opts.debugging_opts.print_type_sizes {
229-
sess.code_stats.borrow().print_type_sizes();
249+
#[cfg(not(feature="llvm"))]
250+
{
251+
let _ = outputs;
252+
let _ = trans;
253+
unreachable!();
230254
}
231255

232-
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, trans);
256+
#[cfg(feature="llvm")]
257+
{
258+
if sess.opts.debugging_opts.print_type_sizes {
259+
sess.code_stats.borrow().print_type_sizes();
260+
}
233261

234-
controller_entry_point!(after_llvm,
235-
sess,
236-
CompileState::state_after_llvm(input, sess, outdir, output, &trans),
237-
phase5_result);
238-
phase5_result?;
262+
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, trans);
239263

240-
phase_6_link_output(sess, &trans, &outputs);
264+
controller_entry_point!(after_llvm,
265+
sess,
266+
CompileState::state_after_llvm(input, sess, outdir, output, &trans),
267+
phase5_result);
268+
phase5_result?;
241269

242-
// Now that we won't touch anything in the incremental compilation directory
243-
// any more, we can finalize it (which involves renaming it)
244-
rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash);
270+
phase_6_link_output(sess, &trans, &outputs);
245271

246-
if sess.opts.debugging_opts.perf_stats {
247-
sess.print_perf_stats();
248-
}
272+
// Now that we won't touch anything in the incremental compilation directory
273+
// any more, we can finalize it (which involves renaming it)
274+
rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash);
249275

250-
controller_entry_point!(compilation_done,
251-
sess,
252-
CompileState::state_when_compilation_done(input, sess, outdir, output),
253-
Ok(()));
276+
if sess.opts.debugging_opts.perf_stats {
277+
sess.print_perf_stats();
278+
}
279+
280+
controller_entry_point!(
281+
compilation_done,
282+
sess,
283+
CompileState::state_when_compilation_done(input, sess, outdir, output),
284+
Ok(())
285+
);
254286

255-
Ok(())
287+
Ok(())
288+
}
256289
}
257290

258291
fn keep_hygiene_data(sess: &Session) -> bool {
@@ -360,6 +393,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
360393
pub resolutions: Option<&'a Resolutions>,
361394
pub analysis: Option<&'a ty::CrateAnalysis>,
362395
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
396+
#[cfg(feature="llvm")]
363397
pub trans: Option<&'a trans::CrateTranslation>,
364398
}
365399

@@ -386,6 +420,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
386420
resolutions: None,
387421
analysis: None,
388422
tcx: None,
423+
#[cfg(feature="llvm")]
389424
trans: None,
390425
}
391426
}
@@ -474,7 +509,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
474509
}
475510
}
476511

477-
512+
#[cfg(feature="llvm")]
478513
fn state_after_llvm(input: &'a Input,
479514
session: &'tcx Session,
480515
out_dir: &'a Option<PathBuf>,
@@ -488,6 +523,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
488523
}
489524
}
490525

526+
#[cfg(feature="llvm")]
491527
fn state_when_compilation_done(input: &'a Input,
492528
session: &'tcx Session,
493529
out_dir: &'a Option<PathBuf>,
@@ -906,6 +942,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
906942
mir::provide(&mut local_providers);
907943
reachable::provide(&mut local_providers);
908944
rustc_privacy::provide(&mut local_providers);
945+
#[cfg(feature="llvm")]
909946
trans::provide(&mut local_providers);
910947
typeck::provide(&mut local_providers);
911948
ty::provide(&mut local_providers);
@@ -918,6 +955,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
918955

919956
let mut extern_providers = ty::maps::Providers::default();
920957
cstore::provide(&mut extern_providers);
958+
#[cfg(feature="llvm")]
921959
trans::provide(&mut extern_providers);
922960
ty::provide_extern(&mut extern_providers);
923961
traits::provide_extern(&mut extern_providers);
@@ -1064,6 +1102,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
10641102

10651103
/// Run the translation phase to LLVM, after which the AST and analysis can
10661104
/// be discarded.
1105+
#[cfg(feature="llvm")]
10671106
pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10681107
analysis: ty::CrateAnalysis,
10691108
incremental_hashes_map: IncrementalHashesMap,
@@ -1085,6 +1124,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10851124

10861125
/// Run LLVM itself, producing a bitcode file, assembly file or object file
10871126
/// as a side effect.
1127+
#[cfg(feature="llvm")]
10881128
pub fn phase_5_run_llvm_passes(sess: &Session,
10891129
trans: write::OngoingCrateTranslation)
10901130
-> (CompileResult, trans::CrateTranslation) {
@@ -1103,6 +1143,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11031143

11041144
/// Run the linker on any artifacts that resulted from the LLVM run.
11051145
/// This should produce either a finished executable or library.
1146+
#[cfg(feature="llvm")]
11061147
pub fn phase_6_link_output(sess: &Session,
11071148
trans: &trans::CrateTranslation,
11081149
outputs: &OutputFilenames) {
@@ -1124,7 +1165,12 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
11241165
match *output_type {
11251166
OutputType::Exe => {
11261167
for output in sess.crate_types.borrow().iter() {
1127-
let p = link::filename_for_input(sess, *output, crate_name, outputs);
1168+
let p = ::rustc_trans_utils::link::filename_for_input(
1169+
sess,
1170+
*output,
1171+
crate_name,
1172+
outputs
1173+
);
11281174
out_filenames.push(p);
11291175
}
11301176
}
@@ -1234,15 +1280,15 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<c
12341280
if base.is_empty() {
12351281
base.extend(attr_types);
12361282
if base.is_empty() {
1237-
base.push(link::default_output_for_target(session));
1283+
base.push(::rustc_trans_utils::link::default_output_for_target(session));
12381284
}
12391285
base.sort();
12401286
base.dedup();
12411287
}
12421288

12431289
base.into_iter()
12441290
.filter(|crate_type| {
1245-
let res = !link::invalid_output_for_target(session, *crate_type);
1291+
let res = !::rustc_trans_utils::link::invalid_output_for_target(session, *crate_type);
12461292

12471293
if !res {
12481294
session.warn(&format!("dropping unsupported crate type `{}` for target `{}`",

0 commit comments

Comments
 (0)