diff options
| author | bors <bors@rust-lang.org> | 2023-07-16 10:59:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-16 10:59:45 +0000 |
| commit | 55be59d2cefe33529a07b0e011384658c9240035 (patch) | |
| tree | ed2f3439c3e5d9e8bff65daec5bae23516c9b20c | |
| parent | 00a39cc785fcbb4f1e9c9454e9ee8a85e6ff021c (diff) | |
| parent | ad16606471db319ebcb42bef9a05538079c21ab9 (diff) | |
| download | rust-55be59d2cefe33529a07b0e011384658c9240035.tar.gz rust-55be59d2cefe33529a07b0e011384658c9240035.zip | |
Auto merge of #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 https://github.com/rust-lang/rust/issues/113209
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 5 | ||||
| -rw-r--r-- | tests/run-make/print-native-static-libs/Makefile | 6 | ||||
| -rw-r--r-- | tests/run-make/print-native-static-libs/bar.rs | 6 |
3 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b603a878746..0dfb41f42f0 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1392,6 +1392,11 @@ fn print_native_static_libs( let mut lib_args: Vec<_> = all_native_libs .iter() .filter(|l| relevant_lib(sess, l)) + // Deduplication of successive repeated libraries, see rust-lang/rust#113209 + // + // note: we don't use PartialEq/Eq because NativeLib transitively depends on local + // elements like spans, which we don't care about and would make the deduplication impossible + .dedup_by(|l1, l2| l1.name == l2.name && l1.kind == l2.kind && l1.verbatim == l2.verbatim) .filter_map(|lib| { let name = lib.name; match lib.kind { diff --git a/tests/run-make/print-native-static-libs/Makefile b/tests/run-make/print-native-static-libs/Makefile index 98e72d7696f..a16c8b0f2a4 100644 --- a/tests/run-make/print-native-static-libs/Makefile +++ b/tests/run-make/print-native-static-libs/Makefile @@ -5,7 +5,7 @@ include ../tools.mk all: $(RUSTC) --crate-type rlib -lbar_cli bar.rs - $(RUSTC) foo.rs -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \ + $(RUSTC) foo.rs -lfoo_cli -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \ | grep 'note: native-static-libs: ' \ | sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt @@ -13,3 +13,7 @@ all: cat $(TMPDIR)/libs.txt | grep -F "systemd" # in foo.rs cat $(TMPDIR)/libs.txt | grep -F "bar_cli" cat $(TMPDIR)/libs.txt | grep -F "foo_cli" + + # make sure that foo_cli and glib-2.0 are not consecutively present + cat $(TMPDIR)/libs.txt | grep -Fv "foo_cli -lfoo_cli" + cat $(TMPDIR)/libs.txt | grep -Fv "glib-2.0 -lglib-2.0" diff --git a/tests/run-make/print-native-static-libs/bar.rs b/tests/run-make/print-native-static-libs/bar.rs index a563bbc2a22..cd9c1c453e5 100644 --- a/tests/run-make/print-native-static-libs/bar.rs +++ b/tests/run-make/print-native-static-libs/bar.rs @@ -3,6 +3,7 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 { // Obviously makes no sense but... unsafe { g_free(std::ptr::null_mut()); + g_free2(std::ptr::null_mut()); } left + right } @@ -11,3 +12,8 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 { extern "C" { fn g_free(p: *mut ()); } + +#[link(name = "glib-2.0")] +extern "C" { + fn g_free2(p: *mut ()); +} |
