auto merge of #10749 : Blei/rust/fix-linker-args, r=alexcrichton

This is inspired by a mystifying linker failure when using `pkg-config` to
generate the linker args: `pkg-config` produces output that ends in a
space, thus resulting in an empty linker argument.

Also added some updates to the concerning error messages that helped
spotting this bug.
This commit is contained in:
bors 2013-12-01 11:26:57 -08:00
commit 9ac48785d6
4 changed files with 18 additions and 5 deletions

View File

@ -362,12 +362,12 @@ pub fn run_assembler(sess: Session, assembly: &Path, object: &Path) {
~"-o", object.as_str().unwrap().to_owned(),
assembly.as_str().unwrap().to_owned()];
debug!("{} {}", cc, args.connect(" "));
debug!("{} '{}'", cc, args.connect("' '"));
let prog = run::process_output(cc, args);
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
sess.note(format!("{} arguments: {}", cc, args.connect(" ")));
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}
@ -1061,7 +1061,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
let mut cc_args = sess.targ_cfg.target_strs.cc_args.clone();
cc_args.push_all_move(link_args(sess, dylib, obj_filename, out_filename));
if (sess.opts.debugging_opts & session::print_link_args) != 0 {
println!("{} link args: {}", cc_prog, cc_args.connect(" "));
println!("{} link args: '{}'", cc_prog, cc_args.connect("' '"));
}
// May have not found libraries in the right formats.
@ -1073,7 +1073,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}", cc_prog, cc_args.connect(" ")));
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}

View File

@ -762,7 +762,13 @@ pub fn build_session_options(binary: @str,
let ar = matches.opt_str("ar");
let linker = matches.opt_str("linker");
let linker_args = matches.opt_strs("link-args").flat_map( |a| {
a.split(' ').map(|arg| arg.to_owned()).collect()
a.split(' ').filter_map(|arg| {
if arg.is_empty() {
None
} else {
Some(arg.to_owned())
}
}).collect()
});
let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter);

View File

@ -0,0 +1,6 @@
-include ../tools.mk
# Notice the space in the end, this emulates the output of pkg-config
RUSTC_FLAGS = --link-args "-lc "
all:
$(RUSTC) $(RUSTC_FLAGS) empty.rs

View File

@ -0,0 +1 @@
fn main() { }