Skip to content

Commit f64503e

Browse files
committed
Auto merge of #85554 - 12101111:fix-dedup-native-libs, r=petrochenkov
native lib: defer the duplicate check after relevant_lib check. #84794 break code using conditional-compilation with `#[link]` attributes. ```rust #[cfg(target_env = "musl")] cfg_if::cfg_if! { if #[cfg(any(target_feature = "crt-static", feature = "llvm-libunwind"))] { #[link(name = "unwind", kind = "static", modifiers = "-bundle")] extern "C" {} } else { #[link(name = "unwind", cfg(feature = "system-llvm-libunwind"))] #[link(name = "gcc_s", cfg(not(feature = "system-llvm-libunwind")))] extern "C" {} } } ```
2 parents d8af907 + 8e42fa5 commit f64503e

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1805,13 +1805,14 @@ fn add_local_native_libraries(
18051805
let search_path = archive_search_paths(sess);
18061806
let mut last = (NativeLibKind::Unspecified, None);
18071807
for lib in relevant_libs {
1808-
// Skip if this library is the same as the last.
1809-
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
1810-
18111808
let name = match lib.name {
18121809
Some(l) => l,
18131810
None => continue,
18141811
};
1812+
1813+
// Skip if this library is the same as the last.
1814+
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
1815+
18151816
let verbatim = lib.verbatim.unwrap_or(false);
18161817
match lib.kind {
18171818
NativeLibKind::Dylib { as_needed } => {
@@ -2144,16 +2145,17 @@ fn add_upstream_native_libraries(
21442145
let mut last = (NativeLibKind::Unspecified, None);
21452146
for &(cnum, _) in crates {
21462147
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
2147-
// Skip if this library is the same as the last.
2148-
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
2149-
21502148
let name = match lib.name {
21512149
Some(l) => l,
21522150
None => continue,
21532151
};
21542152
if !relevant_lib(sess, &lib) {
21552153
continue;
21562154
}
2155+
2156+
// Skip if this library is the same as the last.
2157+
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
2158+
21572159
let verbatim = lib.verbatim.unwrap_or(false);
21582160
match lib.kind {
21592161
NativeLibKind::Dylib { as_needed } => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ignore-msvc
2+
3+
-include ../tools.mk
4+
5+
all:
6+
$(RUSTC) depa.rs
7+
$(RUSTC) depb.rs
8+
$(RUSTC) depc.rs
9+
$(RUSTC) empty.rs --cfg bar 2>&1 | $(CGREP) '"-ltesta" "-ltestb" "-ltesta"'
10+
$(RUSTC) empty.rs 2>&1 | $(CGREP) '"-ltesta"'
11+
$(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltestb"'
12+
$(RUSTC) empty.rs 2>&1 | $(CGREP) -v '"-ltesta" "-ltesta"'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_type = "rlib"]
2+
3+
#[link(name = "testa")]
4+
extern "C" {}
5+
6+
#[link(name = "testa")]
7+
extern "C" {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(link_cfg)]
2+
#![crate_type = "rlib"]
3+
4+
#[link(name = "testb", cfg(foo))]
5+
extern "C" {}
6+
7+
#[link(name = "testb", cfg(bar))]
8+
extern "C" {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![crate_type = "rlib"]
2+
3+
#[link(name = "testa")]
4+
extern "C" {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate depa;
2+
extern crate depb;
3+
extern crate depc;
4+
5+
fn main() {}

0 commit comments

Comments
 (0)