Skip to content

Commit d44a256

Browse files
committed
Allow building stage 2 compiler libraries
1 parent cba53f0 commit d44a256

File tree

9 files changed

+90
-58
lines changed

9 files changed

+90
-58
lines changed

src/bootstrap/bin/rustc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ fn main() {
159159
cmd.arg("-C").arg("panic=abort");
160160
}
161161

162+
if cfg!(not(feature="llvm")) && stage != "0" {
163+
cmd.arg("-Zno-trans");
164+
}
165+
162166
// Set various options from config.toml to configure how we're building
163167
// code.
164168
if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {

src/bootstrap/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ 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+
if mode == Mode::Libstd || !self.build.config.llvm_enabled {
535535
cargo.env("RUSTC_SNAPSHOT", &self.initial_rustc)
536536
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
537537
} else {

src/bootstrap/compile.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ impl Step for Std {
104104

105105
let out_dir = build.cargo_out(compiler, Mode::Libstd, target);
106106
build.clear_if_dirty(&out_dir, &builder.rustc(compiler));
107-
let mut cargo = if compiler.stage == 0 {
108-
builder.cargo(compiler, Mode::Libstd, target, "build")
109-
}else{
110-
builder.cargo(compiler, Mode::Libstd, target, "check")
111-
};
107+
let mut cargo = builder.cargo(compiler, Mode::Libstd, target, "build");
112108
std_cargo(build, &compiler, target, &mut cargo);
113109
run_cargo(build,
114110
&mut cargo,
@@ -165,7 +161,6 @@ pub fn std_cargo(build: &Build,
165161
// missing
166162
// We also only build the runtimes when --enable-sanitizers (or its
167163
// config.toml equivalent) is used
168-
//cargo.env("RUST_FLAGS", "-Zno-trans");
169164
cargo.env("LLVM_CONFIG", build.llvm_config(target));
170165
}
171166

src/librustc_driver/driver.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use derive_registrar;
6969

7070
use profile;
7171

72-
pub fn compile_input(sess: &Session,
72+
pub fn compile_input(sess: &mut Session,
7373
cstore: &CStore,
7474
input: &Input,
7575
outdir: &Option<PathBuf>,
@@ -100,17 +100,32 @@ pub fn compile_input(sess: &Session,
100100
sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
101101
}
102102

103-
if sess.opts.crate_types.iter().all(|&t|{
104-
t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
105-
}) && !sess.opts.crate_types.is_empty() {
106-
sess.err(
107-
"LLVM is not supported by this rustc, so non rlib libraries are not supported"
108-
);
103+
for cty in sess.opts.crate_types.iter_mut() {
104+
match *cty {
105+
CrateType::CrateTypeRlib | CrateType::CrateTypeExecutable => {},
106+
CrateType::CrateTypeDylib | CrateType::CrateTypeCdylib |
107+
CrateType::CrateTypeStaticlib => {
108+
sess.parse_sess.span_diagnostic.warn(
109+
&format!("LLVM unsupported, so non rlib output type {} \
110+
will be treated like rlib lib", cty)
111+
);
112+
*cty = CrateType::CrateTypeRlib;
113+
},
114+
CrateType::CrateTypeProcMacro => {
115+
sess.parse_sess.span_diagnostic.err(
116+
"No LLVM support, so cant compile proc macros"
117+
);
118+
}
119+
}
109120
}
110121

111122
sess.abort_if_errors();
112123
}
113124

125+
// Make sure nobody changes sess after crate types
126+
// have optionally been adjusted for no llvm builds
127+
let sess = &*sess;
128+
114129
if sess.profile_queries() {
115130
profile::begin();
116131
}
@@ -267,6 +282,10 @@ pub fn compile_input(sess: &Session,
267282

268283
if cfg!(not(feature="llvm")) {
269284
let (_, _) = (outputs, trans);
285+
286+
if sess.opts.crate_types.contains(&CrateType::CrateTypeRlib) {
287+
return Ok(())
288+
}
270289
sess.fatal("LLVM is not supported by this rustc");
271290
}
272291

@@ -300,9 +319,9 @@ pub fn compile_input(sess: &Session,
300319
CompileState::state_when_compilation_done(input, sess, outdir, output),
301320
Ok(())
302321
);
303-
304-
Ok(())
305322
}
323+
324+
Ok(())
306325
}
307326

308327
fn keep_hygiene_data(sess: &Session) -> bool {

src/librustc_metadata/locator.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ impl<'a> Context<'a> {
457457
//
458458
// The goal of this step is to look at as little metadata as possible.
459459
self.filesearch.search(|path, kind| {
460+
let mut path = path.to_owned();
461+
if cfg!(not(feature="llvm")) {
462+
// This is a hack to make crates both defined as dylib
463+
// and rlib to be findable without LLVM
464+
path.set_extension("rlib");
465+
}
466+
let path = &path;
467+
460468
let file = match path.file_name().and_then(|s| s.to_str()) {
461469
None => return FileDoesntMatch,
462470
Some(file) => file,
@@ -745,7 +753,15 @@ impl<'a> Context<'a> {
745753
let mut rmetas = FxHashMap();
746754
let mut dylibs = FxHashMap();
747755
{
748-
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
756+
let locs = locs.map(|l| PathBuf::from(l))
757+
.map(|mut l| {
758+
if cfg!(not(feature="llvm")) {
759+
// This is a hack to make crates both defined as dylib
760+
// and rlib to be findable without LLVM
761+
l.set_extension("rlib");
762+
}
763+
l
764+
}).filter(|loc| {
749765
if !loc.exists() {
750766
sess.err(&format!("extern location for {} does not exist: {}",
751767
self.crate_name,

src/librustc_trans/back/link.rs

Lines changed: 3 additions & 39 deletions
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-
extern crate rustc_trans_utils;
12-
1311
use super::archive::{ArchiveBuilder, ArchiveConfig};
1412
use super::linker::Linker;
1513
use super::command::Command;
@@ -27,7 +25,6 @@ use {CrateTranslation, CrateInfo};
2725
use rustc::util::common::time;
2826
use rustc::util::fs::fix_windows_verbatim_for_gcc;
2927
use rustc::hir::def_id::CrateNum;
30-
use rustc::hir::svh::Svh;
3128
use rustc_back::tempdir::TempDir;
3229
use rustc_back::{PanicStrategy, RelroLevel};
3330
use context::get_reloc_model;
@@ -88,9 +85,9 @@ pub const RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET: usize =
8885
pub const RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET: usize =
8986
RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET + 8;
9087

91-
pub use self::rustc_trans_utils::link::{find_crate_name, filename_for_input,
92-
default_output_for_target, invalid_output_for_target,
93-
build_link_meta};
88+
pub use rustc_trans_utils::link::{find_crate_name, filename_for_input, default_output_for_target,
89+
invalid_output_for_target, build_link_meta, out_filename,
90+
check_file_is_writeable};
9491

9592
// The third parameter is for env vars, used on windows to set up the
9693
// path for MSVC to find its DLLs, and gcc to find its bundled
@@ -218,13 +215,6 @@ pub fn link_binary(sess: &Session,
218215
out_filenames
219216
}
220217

221-
fn is_writeable(p: &Path) -> bool {
222-
match p.metadata() {
223-
Err(..) => true,
224-
Ok(m) => !m.permissions().readonly()
225-
}
226-
}
227-
228218
fn filename_for_metadata(sess: &Session, crate_name: &str, outputs: &OutputFilenames) -> PathBuf {
229219
let out_filename = outputs.single_output_file.clone()
230220
.unwrap_or(outputs
@@ -288,32 +278,6 @@ pub fn ignored_for_lto(info: &CrateInfo, cnum: CrateNum) -> bool {
288278
info.is_no_builtins.contains(&cnum) || info.compiler_builtins == Some(cnum)
289279
}
290280

291-
fn out_filename(sess: &Session,
292-
crate_type: config::CrateType,
293-
outputs: &OutputFilenames,
294-
crate_name: &str)
295-
-> PathBuf {
296-
let default_filename = filename_for_input(sess, crate_type, crate_name, outputs);
297-
let out_filename = outputs.outputs.get(&OutputType::Exe)
298-
.and_then(|s| s.to_owned())
299-
.or_else(|| outputs.single_output_file.clone())
300-
.unwrap_or(default_filename);
301-
302-
check_file_is_writeable(&out_filename, sess);
303-
304-
out_filename
305-
}
306-
307-
// Make sure files are writeable. Mac, FreeBSD, and Windows system linkers
308-
// check this already -- however, the Linux linker will happily overwrite a
309-
// read-only file. We should be consistent.
310-
fn check_file_is_writeable(file: &Path, sess: &Session) {
311-
if !is_writeable(file) {
312-
sess.fatal(&format!("output file {} is not writeable -- check its \
313-
permissions", file.display()));
314-
}
315-
}
316-
317281
fn link_binary_output(sess: &Session,
318282
trans: &CrateTranslation,
319283
crate_type: config::CrateType,

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
938938
pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
939939
rx: mpsc::Receiver<Box<Any + Send>>)
940940
-> OngoingCrateTranslation {
941-
use back::link::rustc_trans_utils::find_exported_symbols;
941+
use rustc_trans_utils::find_exported_symbols;
942942

943943
check_for_rustc_errors_attr(tcx);
944944

src/librustc_trans/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern crate rustc_incremental;
5050
extern crate rustc_llvm as llvm;
5151
extern crate rustc_platform_intrinsics as intrinsics;
5252
extern crate rustc_const_math;
53+
extern crate rustc_trans_utils;
5354
extern crate rustc_demangle;
5455
extern crate jobserver;
5556
extern crate num_cpus;

src/librustc_trans_utils/link.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,43 @@ use rustc::middle::cstore::{self, LinkMeta};
1414
use rustc::dep_graph::{DepKind, DepNode};
1515
use rustc::hir::svh::Svh;
1616
use rustc_incremental::IncrementalHashesMap;
17-
use std::path::PathBuf;
17+
use std::path::{Path, PathBuf};
1818
use syntax::ast;
1919
use syntax_pos::Span;
2020

21+
pub fn out_filename(sess: &Session,
22+
crate_type: config::CrateType,
23+
outputs: &OutputFilenames,
24+
crate_name: &str)
25+
-> PathBuf {
26+
let default_filename = filename_for_input(sess, crate_type, crate_name, outputs);
27+
let out_filename = outputs.outputs.get(&OutputType::Exe)
28+
.and_then(|s| s.to_owned())
29+
.or_else(|| outputs.single_output_file.clone())
30+
.unwrap_or(default_filename);
31+
32+
check_file_is_writeable(&out_filename, sess);
33+
34+
out_filename
35+
}
36+
37+
// Make sure files are writeable. Mac, FreeBSD, and Windows system linkers
38+
// check this already -- however, the Linux linker will happily overwrite a
39+
// read-only file. We should be consistent.
40+
pub fn check_file_is_writeable(file: &Path, sess: &Session) {
41+
if !is_writeable(file) {
42+
sess.fatal(&format!("output file {} is not writeable -- check its \
43+
permissions", file.display()));
44+
}
45+
}
46+
47+
fn is_writeable(p: &Path) -> bool {
48+
match p.metadata() {
49+
Err(..) => true,
50+
Ok(m) => !m.permissions().readonly()
51+
}
52+
}
53+
2154
pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMeta {
2255
let krate_dep_node = &DepNode::new_no_params(DepKind::Krate);
2356
let r = LinkMeta {

0 commit comments

Comments
 (0)