@@ -329,15 +329,15 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
329329 // metadata of the rlib we're generating somehow.
330330 for lib in codegen_results. crate_info . used_libraries . iter ( ) {
331331 match lib. kind {
332- NativeLibKind :: StaticBundle => { }
333- NativeLibKind :: StaticNoBundle
334- | NativeLibKind :: Dylib
335- | NativeLibKind :: Framework
332+ NativeLibKind :: Static { bundle : None | Some ( true ) , .. } => { }
333+ NativeLibKind :: Static { bundle : Some ( false ) , .. }
334+ | NativeLibKind :: Dylib { .. }
335+ | NativeLibKind :: Framework { .. }
336336 | NativeLibKind :: RawDylib
337337 | NativeLibKind :: Unspecified => continue ,
338338 }
339339 if let Some ( name) = lib. name {
340- ab. add_native_library ( name) ;
340+ ab. add_native_library ( name, lib . verbatim . unwrap_or ( false ) ) ;
341341 }
342342 }
343343
@@ -430,9 +430,10 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
430430 // Clearly this is not sufficient for a general purpose feature, and
431431 // we'd want to read from the library's metadata to determine which
432432 // object files come from where and selectively skip them.
433- let skip_object_files = native_libs
434- . iter ( )
435- . any ( |lib| lib. kind == NativeLibKind :: StaticBundle && !relevant_lib ( sess, lib) ) ;
433+ let skip_object_files = native_libs. iter ( ) . any ( |lib| {
434+ matches ! ( lib. kind, NativeLibKind :: Static { bundle: None | Some ( true ) , .. } )
435+ && !relevant_lib ( sess, lib)
436+ } ) ;
436437 ab. add_rlib (
437438 path,
438439 & name. as_str ( ) ,
@@ -931,7 +932,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
931932 let path = find_sanitizer_runtime ( & sess, & filename) ;
932933 let rpath = path. to_str ( ) . expect ( "non-utf8 component in path" ) ;
933934 linker. args ( & [ "-Wl,-rpath" , "-Xlinker" , rpath] ) ;
934- linker. link_dylib ( Symbol :: intern ( & filename) ) ;
935+ linker. link_dylib ( Symbol :: intern ( & filename) , false , true ) ;
935936 } else {
936937 let filename = format ! ( "librustc{}_rt.{}.a" , channel, name) ;
937938 let path = find_sanitizer_runtime ( & sess, & filename) . join ( & filename) ;
@@ -1080,21 +1081,25 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
10801081 . filter_map ( |lib| {
10811082 let name = lib. name ?;
10821083 match lib. kind {
1083- NativeLibKind :: StaticNoBundle
1084- | NativeLibKind :: Dylib
1084+ NativeLibKind :: Static { bundle : Some ( false ) , .. }
1085+ | NativeLibKind :: Dylib { .. }
10851086 | NativeLibKind :: Unspecified => {
1087+ let verbatim = lib. verbatim . unwrap_or ( false ) ;
10861088 if sess. target . is_like_msvc {
1087- Some ( format ! ( "{}.lib" , name) )
1089+ Some ( format ! ( "{}{}" , name, if verbatim { "" } else { ".lib" } ) )
1090+ } else if sess. target . linker_is_gnu {
1091+ Some ( format ! ( "-l{}{}" , if verbatim { ":" } else { "" } , name) )
10881092 } else {
10891093 Some ( format ! ( "-l{}" , name) )
10901094 }
10911095 }
1092- NativeLibKind :: Framework => {
1096+ NativeLibKind :: Framework { .. } => {
10931097 // ld-only syntax, since there are no frameworks in MSVC
10941098 Some ( format ! ( "-framework {}" , name) )
10951099 }
10961100 // These are included, no need to print them
1097- NativeLibKind :: StaticBundle | NativeLibKind :: RawDylib => None ,
1101+ NativeLibKind :: Static { bundle : None | Some ( true ) , .. }
1102+ | NativeLibKind :: RawDylib => None ,
10981103 }
10991104 } )
11001105 . collect ( ) ;
@@ -1808,11 +1813,20 @@ fn add_local_native_libraries(
18081813 Some ( l) => l,
18091814 None => continue ,
18101815 } ;
1816+ let verbatim = lib. verbatim . unwrap_or ( false ) ;
18111817 match lib. kind {
1812- NativeLibKind :: Dylib | NativeLibKind :: Unspecified => cmd. link_dylib ( name) ,
1813- NativeLibKind :: Framework => cmd. link_framework ( name) ,
1814- NativeLibKind :: StaticNoBundle => cmd. link_staticlib ( name) ,
1815- NativeLibKind :: StaticBundle => cmd. link_whole_staticlib ( name, & search_path) ,
1818+ NativeLibKind :: Dylib { as_needed } => {
1819+ cmd. link_dylib ( name, verbatim, as_needed. unwrap_or ( true ) )
1820+ }
1821+ NativeLibKind :: Unspecified => cmd. link_dylib ( name, verbatim, true ) ,
1822+ NativeLibKind :: Framework { as_needed } => {
1823+ cmd. link_framework ( name, as_needed. unwrap_or ( true ) )
1824+ }
1825+ NativeLibKind :: Static { bundle : None | Some ( true ) , .. }
1826+ | NativeLibKind :: Static { whole_archive : Some ( true ) , .. } => {
1827+ cmd. link_whole_staticlib ( name, verbatim, & search_path) ;
1828+ }
1829+ NativeLibKind :: Static { .. } => cmd. link_staticlib ( name, verbatim) ,
18161830 NativeLibKind :: RawDylib => {
18171831 // FIXME(#58713): Proper handling for raw dylibs.
18181832 bug ! ( "raw_dylib feature not yet implemented" ) ;
@@ -1996,9 +2010,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
19962010 // there's a static library that's not relevant we skip all object
19972011 // files.
19982012 let native_libs = & codegen_results. crate_info . native_libraries [ & cnum] ;
1999- let skip_native = native_libs
2000- . iter ( )
2001- . any ( |lib| lib. kind == NativeLibKind :: StaticBundle && !relevant_lib ( sess, lib) ) ;
2013+ let skip_native = native_libs. iter ( ) . any ( |lib| {
2014+ matches ! ( lib. kind, NativeLibKind :: Static { bundle: None | Some ( true ) , .. } )
2015+ && !relevant_lib ( sess, lib)
2016+ } ) ;
20022017
20032018 if ( !are_upstream_rust_objects_already_included ( sess)
20042019 || ignored_for_lto ( sess, & codegen_results. crate_info , cnum) )
@@ -2136,22 +2151,28 @@ fn add_upstream_native_libraries(
21362151 if !relevant_lib ( sess, & lib) {
21372152 continue ;
21382153 }
2154+ let verbatim = lib. verbatim . unwrap_or ( false ) ;
21392155 match lib. kind {
2140- NativeLibKind :: Dylib | NativeLibKind :: Unspecified => cmd. link_dylib ( name) ,
2141- NativeLibKind :: Framework => cmd. link_framework ( name) ,
2142- NativeLibKind :: StaticNoBundle => {
2156+ NativeLibKind :: Dylib { as_needed } => {
2157+ cmd. link_dylib ( name, verbatim, as_needed. unwrap_or ( true ) )
2158+ }
2159+ NativeLibKind :: Unspecified => cmd. link_dylib ( name, verbatim, true ) ,
2160+ NativeLibKind :: Framework { as_needed } => {
2161+ cmd. link_framework ( name, as_needed. unwrap_or ( true ) )
2162+ }
2163+ NativeLibKind :: Static { bundle : Some ( false ) , .. } => {
21432164 // Link "static-nobundle" native libs only if the crate they originate from
21442165 // is being linked statically to the current crate. If it's linked dynamically
21452166 // or is an rlib already included via some other dylib crate, the symbols from
21462167 // native libs will have already been included in that dylib.
21472168 if data[ cnum. as_usize ( ) - 1 ] == Linkage :: Static {
2148- cmd. link_staticlib ( name)
2169+ cmd. link_staticlib ( name, verbatim )
21492170 }
21502171 }
21512172 // ignore statically included native libraries here as we've
21522173 // already included them when we included the rust library
21532174 // previously
2154- NativeLibKind :: StaticBundle => { }
2175+ NativeLibKind :: Static { bundle : None | Some ( true ) , .. } => { }
21552176 NativeLibKind :: RawDylib => {
21562177 // FIXME(#58713): Proper handling for raw dylibs.
21572178 bug ! ( "raw_dylib feature not yet implemented" ) ;
0 commit comments