@@ -329,15 +329,15 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
329
329
// metadata of the rlib we're generating somehow.
330
330
for lib in codegen_results.crate_info.used_libraries.iter() {
331
331
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 { .. }
336
336
| NativeLibKind::RawDylib
337
337
| NativeLibKind::Unspecified => continue,
338
338
}
339
339
if let Some(name) = lib.name {
340
- ab.add_native_library(name);
340
+ ab.add_native_library(name, lib.verbatim.unwrap_or(false) );
341
341
}
342
342
}
343
343
@@ -430,9 +430,10 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
430
430
// Clearly this is not sufficient for a general purpose feature, and
431
431
// we'd want to read from the library's metadata to determine which
432
432
// 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
+ });
436
437
ab.add_rlib(
437
438
path,
438
439
&name.as_str(),
@@ -931,7 +932,7 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
931
932
let path = find_sanitizer_runtime(&sess, &filename);
932
933
let rpath = path.to_str().expect("non-utf8 component in path");
933
934
linker.args(&["-Wl,-rpath", "-Xlinker", rpath]);
934
- linker.link_dylib(Symbol::intern(&filename));
935
+ linker.link_dylib(Symbol::intern(&filename), false, true );
935
936
} else {
936
937
let filename = format!("librustc{}_rt.{}.a", channel, name);
937
938
let path = find_sanitizer_runtime(&sess, &filename).join(&filename);
@@ -1080,21 +1081,25 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
1080
1081
.filter_map(|lib| {
1081
1082
let name = lib.name?;
1082
1083
match lib.kind {
1083
- NativeLibKind::StaticNoBundle
1084
- | NativeLibKind::Dylib
1084
+ NativeLibKind::Static { bundle: Some(false), .. }
1085
+ | NativeLibKind::Dylib { .. }
1085
1086
| NativeLibKind::Unspecified => {
1087
+ let verbatim = lib.verbatim.unwrap_or(false);
1086
1088
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))
1088
1092
} else {
1089
1093
Some(format!("-l{}", name))
1090
1094
}
1091
1095
}
1092
- NativeLibKind::Framework => {
1096
+ NativeLibKind::Framework { .. } => {
1093
1097
// ld-only syntax, since there are no frameworks in MSVC
1094
1098
Some(format!("-framework {}", name))
1095
1099
}
1096
1100
// 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,
1098
1103
}
1099
1104
})
1100
1105
.collect();
@@ -1812,11 +1817,20 @@ fn add_local_native_libraries(
1812
1817
Some(l) => l,
1813
1818
None => continue,
1814
1819
};
1820
+ let verbatim = lib.verbatim.unwrap_or(false);
1815
1821
match lib.kind {
1816
- NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name),
1817
- NativeLibKind::Framework => cmd.link_framework(name),
1818
- NativeLibKind::StaticNoBundle => cmd.link_staticlib(name),
1819
- NativeLibKind::StaticBundle => cmd.link_whole_staticlib(name, &search_path),
1822
+ NativeLibKind::Dylib { as_needed } => {
1823
+ cmd.link_dylib(name, verbatim, as_needed.unwrap_or(true))
1824
+ }
1825
+ NativeLibKind::Unspecified => cmd.link_dylib(name, verbatim, true),
1826
+ NativeLibKind::Framework { as_needed } => {
1827
+ cmd.link_framework(name, as_needed.unwrap_or(true))
1828
+ }
1829
+ NativeLibKind::Static { bundle: None | Some(true), .. }
1830
+ | NativeLibKind::Static { whole_archive: Some(true), .. } => {
1831
+ cmd.link_whole_staticlib(name, verbatim, &search_path);
1832
+ }
1833
+ NativeLibKind::Static { .. } => cmd.link_staticlib(name, verbatim),
1820
1834
NativeLibKind::RawDylib => {
1821
1835
// FIXME(#58713): Proper handling for raw dylibs.
1822
1836
bug!("raw_dylib feature not yet implemented");
@@ -2000,9 +2014,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
2000
2014
// there's a static library that's not relevant we skip all object
2001
2015
// files.
2002
2016
let native_libs = &codegen_results.crate_info.native_libraries[&cnum];
2003
- let skip_native = native_libs
2004
- .iter()
2005
- .any(|lib| lib.kind == NativeLibKind::StaticBundle && !relevant_lib(sess, lib));
2017
+ let skip_native = native_libs.iter().any(|lib| {
2018
+ matches!(lib.kind, NativeLibKind::Static { bundle: None | Some(true), .. })
2019
+ && !relevant_lib(sess, lib)
2020
+ });
2006
2021
2007
2022
if (!are_upstream_rust_objects_already_included(sess)
2008
2023
|| ignored_for_lto(sess, &codegen_results.crate_info, cnum))
@@ -2144,22 +2159,28 @@ fn add_upstream_native_libraries(
2144
2159
if !relevant_lib(sess, &lib) {
2145
2160
continue;
2146
2161
}
2162
+ let verbatim = lib.verbatim.unwrap_or(false);
2147
2163
match lib.kind {
2148
- NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name),
2149
- NativeLibKind::Framework => cmd.link_framework(name),
2150
- NativeLibKind::StaticNoBundle => {
2164
+ NativeLibKind::Dylib { as_needed } => {
2165
+ cmd.link_dylib(name, verbatim, as_needed.unwrap_or(true))
2166
+ }
2167
+ NativeLibKind::Unspecified => cmd.link_dylib(name, verbatim, true),
2168
+ NativeLibKind::Framework { as_needed } => {
2169
+ cmd.link_framework(name, as_needed.unwrap_or(true))
2170
+ }
2171
+ NativeLibKind::Static { bundle: Some(false), .. } => {
2151
2172
// Link "static-nobundle" native libs only if the crate they originate from
2152
2173
// is being linked statically to the current crate. If it's linked dynamically
2153
2174
// or is an rlib already included via some other dylib crate, the symbols from
2154
2175
// native libs will have already been included in that dylib.
2155
2176
if data[cnum.as_usize() - 1] == Linkage::Static {
2156
- cmd.link_staticlib(name)
2177
+ cmd.link_staticlib(name, verbatim )
2157
2178
}
2158
2179
}
2159
2180
// ignore statically included native libraries here as we've
2160
2181
// already included them when we included the rust library
2161
2182
// previously
2162
- NativeLibKind::StaticBundle => {}
2183
+ NativeLibKind::Static { bundle: None | Some(true), .. } => {}
2163
2184
NativeLibKind::RawDylib => {
2164
2185
// FIXME(#58713): Proper handling for raw dylibs.
2165
2186
bug!("raw_dylib feature not yet implemented");
0 commit comments