Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader: suggest to set crate type explicitly #17943

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ impl<'a> Context<'a> {
(file.slice(dylib_prefix.len(), file.len() - suffix.len()),
false)
} else {
let static_lib = format!("lib{}.a", self.crate_name);
if file == static_lib.as_slice() {
let msg = format!("found staticlib `{}` instead of \
rlib `{}`, please compile using \
--crate-type rlib instead.",
self.crate_name, self.crate_name);
self.sess.span_warn(self.span, msg.as_slice());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we actually try to defer warnings such as this until the loading of the crate has failed entirely. It could be the case that a library is compiled as both an rlib and a staticlib, in which case this could end up just being a spurious warning.

Could this modify report_load_errs instead? You'll want to sort of flag some logic here to modify some internal state about the libs that were found as staticlibs, but the actual warnings/notes should be printed out at the end.

Also, can you add a test for this? It would likely be a run-make test in the src/test/run-make folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton ok, I'll try to do that. My solution is indeed too rough to use.

return FileDoesntMatch
};
info!("lib candidate: {}", path.display());
Expand Down