mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Auto merge of #21978 - Potpourri:error-extern-crate-staticlib, r=alexcrichton
Add special error for this case and help message `please recompile this crate using --crate-type lib`, also list found candidates. See issue #14416 r? @alexcrichton
This commit is contained in:
commit
e62fec36b9
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -419,6 +419,7 @@ impl<'a> CrateReader<'a> {
|
|||||||
root: root,
|
root: root,
|
||||||
rejected_via_hash: vec!(),
|
rejected_via_hash: vec!(),
|
||||||
rejected_via_triple: vec!(),
|
rejected_via_triple: vec!(),
|
||||||
|
rejected_via_kind: vec!(),
|
||||||
should_match_name: true,
|
should_match_name: true,
|
||||||
};
|
};
|
||||||
let library = load_ctxt.load_library_crate();
|
let library = load_ctxt.load_library_crate();
|
||||||
@ -483,6 +484,7 @@ impl<'a> CrateReader<'a> {
|
|||||||
root: &None,
|
root: &None,
|
||||||
rejected_via_hash: vec!(),
|
rejected_via_hash: vec!(),
|
||||||
rejected_via_triple: vec!(),
|
rejected_via_triple: vec!(),
|
||||||
|
rejected_via_kind: vec!(),
|
||||||
should_match_name: true,
|
should_match_name: true,
|
||||||
};
|
};
|
||||||
let library = match load_ctxt.maybe_load_library_crate() {
|
let library = match load_ctxt.maybe_load_library_crate() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
@ -257,6 +257,7 @@ pub struct Context<'a> {
|
|||||||
pub root: &'a Option<CratePaths>,
|
pub root: &'a Option<CratePaths>,
|
||||||
pub rejected_via_hash: Vec<CrateMismatch>,
|
pub rejected_via_hash: Vec<CrateMismatch>,
|
||||||
pub rejected_via_triple: Vec<CrateMismatch>,
|
pub rejected_via_triple: Vec<CrateMismatch>,
|
||||||
|
pub rejected_via_kind: Vec<CrateMismatch>,
|
||||||
pub should_match_name: bool,
|
pub should_match_name: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,6 +312,8 @@ impl<'a> Context<'a> {
|
|||||||
} else if self.rejected_via_triple.len() > 0 {
|
} else if self.rejected_via_triple.len() > 0 {
|
||||||
format!("couldn't find crate `{}` with expected target triple {}",
|
format!("couldn't find crate `{}` with expected target triple {}",
|
||||||
self.ident, self.triple)
|
self.ident, self.triple)
|
||||||
|
} else if self.rejected_via_kind.len() > 0 {
|
||||||
|
format!("found staticlib `{}` instead of rlib or dylib", self.ident)
|
||||||
} else {
|
} else {
|
||||||
format!("can't find crate for `{}`", self.ident)
|
format!("can't find crate for `{}`", self.ident)
|
||||||
};
|
};
|
||||||
@ -335,8 +338,8 @@ impl<'a> Context<'a> {
|
|||||||
let mismatches = self.rejected_via_hash.iter();
|
let mismatches = self.rejected_via_hash.iter();
|
||||||
for (i, &CrateMismatch{ ref path, .. }) in mismatches.enumerate() {
|
for (i, &CrateMismatch{ ref path, .. }) in mismatches.enumerate() {
|
||||||
self.sess.fileline_note(self.span,
|
self.sess.fileline_note(self.span,
|
||||||
&format!("crate `{}` path {}{}: {}",
|
&format!("crate `{}` path #{}: {}",
|
||||||
self.ident, "#", i+1, path.display())[]);
|
self.ident, i+1, path.display())[]);
|
||||||
}
|
}
|
||||||
match self.root {
|
match self.root {
|
||||||
&None => {}
|
&None => {}
|
||||||
@ -349,6 +352,16 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self.rejected_via_kind.len() > 0 {
|
||||||
|
self.sess.span_help(self.span, "please recompile this crate using \
|
||||||
|
--crate-type lib");
|
||||||
|
let mismatches = self.rejected_via_kind.iter();
|
||||||
|
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {
|
||||||
|
self.sess.fileline_note(self.span,
|
||||||
|
&format!("crate `{}` path #{}: {}",
|
||||||
|
self.ident, i+1, path.display())[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
self.sess.abort_if_errors();
|
self.sess.abort_if_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,8 +382,10 @@ impl<'a> Context<'a> {
|
|||||||
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
|
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
|
||||||
let dylib_prefix = format!("{}{}", dypair.0, self.crate_name);
|
let dylib_prefix = format!("{}{}", dypair.0, self.crate_name);
|
||||||
let rlib_prefix = format!("lib{}", self.crate_name);
|
let rlib_prefix = format!("lib{}", self.crate_name);
|
||||||
|
let staticlib_prefix = format!("lib{}", self.crate_name);
|
||||||
|
|
||||||
let mut candidates = HashMap::new();
|
let mut candidates = HashMap::new();
|
||||||
|
let mut staticlibs = vec!();
|
||||||
|
|
||||||
// First, find all possible candidate rlibs and dylibs purely based on
|
// First, find all possible candidate rlibs and dylibs purely based on
|
||||||
// the name of the files themselves. We're trying to match against an
|
// the name of the files themselves. We're trying to match against an
|
||||||
@ -391,7 +406,7 @@ impl<'a> Context<'a> {
|
|||||||
Some(file) => file,
|
Some(file) => file,
|
||||||
};
|
};
|
||||||
let (hash, rlib) = if file.starts_with(&rlib_prefix[]) &&
|
let (hash, rlib) = if file.starts_with(&rlib_prefix[]) &&
|
||||||
file.ends_with(".rlib") {
|
file.ends_with(".rlib") {
|
||||||
(&file[(rlib_prefix.len()) .. (file.len() - ".rlib".len())],
|
(&file[(rlib_prefix.len()) .. (file.len() - ".rlib".len())],
|
||||||
true)
|
true)
|
||||||
} else if file.starts_with(&dylib_prefix) &&
|
} else if file.starts_with(&dylib_prefix) &&
|
||||||
@ -399,6 +414,13 @@ impl<'a> Context<'a> {
|
|||||||
(&file[(dylib_prefix.len()) .. (file.len() - dypair.1.len())],
|
(&file[(dylib_prefix.len()) .. (file.len() - dypair.1.len())],
|
||||||
false)
|
false)
|
||||||
} else {
|
} else {
|
||||||
|
if file.starts_with(&staticlib_prefix[]) &&
|
||||||
|
file.ends_with(".a") {
|
||||||
|
staticlibs.push(CrateMismatch {
|
||||||
|
path: path.clone(),
|
||||||
|
got: "static".to_string()
|
||||||
|
});
|
||||||
|
}
|
||||||
return FileDoesntMatch
|
return FileDoesntMatch
|
||||||
};
|
};
|
||||||
info!("lib candidate: {}", path.display());
|
info!("lib candidate: {}", path.display());
|
||||||
@ -415,6 +437,7 @@ impl<'a> Context<'a> {
|
|||||||
|
|
||||||
FileMatches
|
FileMatches
|
||||||
});
|
});
|
||||||
|
self.rejected_via_kind.extend(staticlibs.into_iter());
|
||||||
|
|
||||||
// We have now collected all known libraries into a set of candidates
|
// We have now collected all known libraries into a set of candidates
|
||||||
// keyed of the filename hash listed. For each filename, we also have a
|
// keyed of the filename hash listed. For each filename, we also have a
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
-include ../tools.mk
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(RUSTC) foo.rs --crate-type staticlib
|
||||||
|
$(RUSTC) bar.rs 2>&1 | grep "error: found staticlib"
|
15
src/test/run-make/error-found-staticlib-instead-crate/bar.rs
Normal file
15
src/test/run-make/error-found-staticlib-instead-crate/bar.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
extern crate foo;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo::foo();
|
||||||
|
}
|
11
src/test/run-make/error-found-staticlib-instead-crate/foo.rs
Normal file
11
src/test/run-make/error-found-staticlib-instead-crate/foo.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
pub fn foo() {}
|
Loading…
Reference in New Issue
Block a user