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:
commit
9ac48785d6
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
6
src/test/run-make/prune-link-args/Makefile
Normal file
6
src/test/run-make/prune-link-args/Makefile
Normal 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
|
1
src/test/run-make/prune-link-args/empty.rs
Normal file
1
src/test/run-make/prune-link-args/empty.rs
Normal file
@ -0,0 +1 @@
|
||||
fn main() { }
|
Loading…
Reference in New Issue
Block a user