Skip to content

Commit 89af6d5

Browse files
committed
[WIP] Less hacky way of supporting dylibs
1 parent d935a8d commit 89af6d5

File tree

6 files changed

+16
-40
lines changed

6 files changed

+16
-40
lines changed

src/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc_driver/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ crate-type = ["dylib"]
1010

1111
[dependencies]
1212
arena = { path = "../libarena" }
13+
flate2 = "0.2"
1314
graphviz = { path = "../libgraphviz" }
1415
log = { version = "0.3", features = ["release_max_level_info"] }
1516
owning_ref = "0.3.3"
@@ -41,4 +42,4 @@ syntax_pos = { path = "../libsyntax_pos" }
4142
ar = "0.3.0"
4243

4344
[features]
44-
llvm = ["rustc_trans", "rustc_metadata/llvm"]
45+
llvm = ["rustc_trans"]

src/librustc_driver/driver.rs

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

103-
for cty in sess.opts.crate_types.iter_mut() {
103+
for cty in sess.opts.crate_types.iter() {
104104
match *cty {
105-
CrateType::CrateTypeRlib | CrateType::CrateTypeExecutable => {},
106-
CrateType::CrateTypeDylib | CrateType::CrateTypeCdylib |
107-
CrateType::CrateTypeStaticlib => {
105+
CrateType::CrateTypeRlib | CrateType::CrateTypeDylib |
106+
CrateType::CrateTypeExecutable => {},
107+
_ => {
108108
sess.parse_sess.span_diagnostic.warn(
109-
&format!("LLVM unsupported, so non rlib output type {} \
110-
will be treated like rlib lib", cty)
109+
&format!("LLVM unsupported, so output type {} is not supported", cty)
111110
);
112-
*cty = CrateType::CrateTypeRlib;
113111
},
114-
CrateType::CrateTypeProcMacro => {
115-
sess.parse_sess.span_diagnostic.err(
116-
"No LLVM support, so cant compile proc macros"
117-
);
118-
}
119112
}
120113
}
121114

122115
sess.abort_if_errors();
123116
}
124117

125-
// Make sure nobody changes sess after crate types
126-
// have optionally been adjusted for no llvm builds
127-
let sess = &*sess;
128-
129118
if sess.profile_queries() {
130119
profile::begin();
131120
}
@@ -283,7 +272,8 @@ pub fn compile_input(sess: &mut Session,
283272
if cfg!(not(feature="llvm")) {
284273
let (_, _) = (outputs, trans);
285274

286-
if sess.opts.crate_types.contains(&CrateType::CrateTypeRlib) {
275+
if sess.opts.crate_types.contains(&CrateType::CrateTypeRlib)
276+
|| sess.opts.crate_types.contains(&CrateType::CrateTypeDylib) {
287277
return Ok(())
288278
}
289279
sess.fatal("LLVM is not supported by this rustc");

src/librustc_driver/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#[cfg(not(feature="llvm"))]
2929
extern crate ar;
30+
#[cfg(not(feature="llvm"))]
31+
extern crate flate2;
3032
extern crate arena;
3133
extern crate getopts;
3234
extern crate graphviz;
@@ -202,7 +204,8 @@ mod no_llvm_metadata_loader {
202204
_target: &Target,
203205
_filename: &Path)
204206
-> Result<ErasedBoxRef<[u8]>, String> {
205-
panic!("Dylib metadata loading not supported without LLVM")
207+
// FIXME: Support reading dylibs from llvm enabled rustc
208+
self.get_rlib_metadata(_target, _filename)
206209
}
207210
}
208211
}

src/librustc_metadata/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ serialize = { path = "../libserialize" }
2121
syntax = { path = "../libsyntax" }
2222
syntax_ext = { path = "../libsyntax_ext" }
2323
syntax_pos = { path = "../libsyntax_pos" }
24-
25-
[features]
26-
llvm = []

src/librustc_metadata/locator.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,6 @@ 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-
468460
let file = match path.file_name().and_then(|s| s.to_str()) {
469461
None => return FileDoesntMatch,
470462
Some(file) => file,
@@ -753,15 +745,7 @@ impl<'a> Context<'a> {
753745
let mut rmetas = FxHashMap();
754746
let mut dylibs = FxHashMap();
755747
{
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| {
748+
let locs = locs.map(|l| PathBuf::from(l)).filter(|loc| {
765749
if !loc.exists() {
766750
sess.err(&format!("extern location for {} does not exist: {}",
767751
self.crate_name,

0 commit comments

Comments
 (0)