From a167caf1061ea81cb946ff4be2ca31cc1bc98310 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 28 May 2014 08:49:07 +1000 Subject: [PATCH] rustc: clarify warning about native deps for a staticlib. This adjusts the "unlinked native library" warning one receives when compiling with `crate_type="staticlib"`. The warning is just trying to tell the user that they need to link against these libraries, but the old text wasn't making this obvious; the new text says this explicitly. --- src/librustc/back/link.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 89a79dbb80d..3939f708b5d 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -1019,6 +1019,8 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) { a.add_native_library("compiler-rt").unwrap(); let crates = sess.cstore.get_used_crates(cstore::RequireStatic); + let mut all_native_libs = vec![]; + for &(cnum, ref path) in crates.iter() { let name = sess.cstore.get_crate_data(cnum).name.clone(); let p = match *path { @@ -1029,17 +1031,25 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) { } }; a.add_rlib(&p, name.as_slice(), sess.lto()).unwrap(); + let native_libs = csearch::get_native_libraries(&sess.cstore, cnum); - for &(kind, ref lib) in native_libs.iter() { - let name = match kind { - cstore::NativeStatic => "static library", - cstore::NativeUnknown => "library", - cstore::NativeFramework => "framework", - }; - sess.warn(format!("unlinked native {}: {}", - name, - *lib).as_slice()); - } + all_native_libs.extend(native_libs.move_iter()); + } + + if !all_native_libs.is_empty() { + sess.warn("link against the following native artifacts when linking against \ + this static library"); + sess.note("the order and any duplication can be significant on some platforms, \ + and so may need to be preserved"); + } + + for &(kind, ref lib) in all_native_libs.iter() { + let name = match kind { + cstore::NativeStatic => "static library", + cstore::NativeUnknown => "library", + cstore::NativeFramework => "framework", + }; + sess.note(format!("{}: {}", name, *lib).as_slice()); } }