Skip to content

Commit 55be59d

Browse files
committed
Auto merge of rust-lang#113626 - Urgau:dedup-native-static-libs, r=petrochenkov
De-duplicate consecutive libs when printing native-static-libs This PR adds a de-duplicate step just before printing the `native-static-libs`. This step de-duplicates all the consecutive libs based only on the relevant comparison elements (this exclude spans, ast elements, ...). Fixes rust-lang#113209
2 parents 00a39cc + ad16606 commit 55be59d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,11 @@ fn print_native_static_libs(
13921392
let mut lib_args: Vec<_> = all_native_libs
13931393
.iter()
13941394
.filter(|l| relevant_lib(sess, l))
1395+
// Deduplication of successive repeated libraries, see rust-lang/rust#113209
1396+
//
1397+
// note: we don't use PartialEq/Eq because NativeLib transitively depends on local
1398+
// elements like spans, which we don't care about and would make the deduplication impossible
1399+
.dedup_by(|l1, l2| l1.name == l2.name && l1.kind == l2.kind && l1.verbatim == l2.verbatim)
13951400
.filter_map(|lib| {
13961401
let name = lib.name;
13971402
match lib.kind {

tests/run-make/print-native-static-libs/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ include ../tools.mk
55

66
all:
77
$(RUSTC) --crate-type rlib -lbar_cli bar.rs
8-
$(RUSTC) foo.rs -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \
8+
$(RUSTC) foo.rs -lfoo_cli -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \
99
| grep 'note: native-static-libs: ' \
1010
| sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt
1111

1212
cat $(TMPDIR)/libs.txt | grep -F "glib-2.0" # in bar.rs
1313
cat $(TMPDIR)/libs.txt | grep -F "systemd" # in foo.rs
1414
cat $(TMPDIR)/libs.txt | grep -F "bar_cli"
1515
cat $(TMPDIR)/libs.txt | grep -F "foo_cli"
16+
17+
# make sure that foo_cli and glib-2.0 are not consecutively present
18+
cat $(TMPDIR)/libs.txt | grep -Fv "foo_cli -lfoo_cli"
19+
cat $(TMPDIR)/libs.txt | grep -Fv "glib-2.0 -lglib-2.0"

tests/run-make/print-native-static-libs/bar.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 {
33
// Obviously makes no sense but...
44
unsafe {
55
g_free(std::ptr::null_mut());
6+
g_free2(std::ptr::null_mut());
67
}
78
left + right
89
}
@@ -11,3 +12,8 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 {
1112
extern "C" {
1213
fn g_free(p: *mut ());
1314
}
15+
16+
#[link(name = "glib-2.0")]
17+
extern "C" {
18+
fn g_free2(p: *mut ());
19+
}

0 commit comments

Comments
 (0)