Skip to content

Fix local libs not included when printing native static libs #111675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ fn link_staticlib<'a>(
}
}

all_native_libs.extend_from_slice(&codegen_results.crate_info.used_libraries);

if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/run-make/print-native-static-libs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ../tools.mk

# ignore-cross-compile
# ignore-wasm

all:
$(RUSTC) --crate-type rlib -lbar_cli bar.rs
$(RUSTC) foo.rs -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

cat $(TMPDIR)/libs.txt | grep -F "glib-2.0" # in bar.rs
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"
13 changes: 13 additions & 0 deletions tests/run-make/print-native-static-libs/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[no_mangle]
pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 {
// Obviously makes no sense but...
unsafe {
g_free(std::ptr::null_mut());
}
left + right
}

#[link(name = "glib-2.0")]
extern "C" {
fn g_free(p: *mut ());
}
15 changes: 15 additions & 0 deletions tests/run-make/print-native-static-libs/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extern crate bar;

#[no_mangle]
pub extern "C" fn my_foo_add(left: i32, right: i32) -> i32 {
// Obviously makes no sense but...
unsafe {
init(std::ptr::null_mut());
}
bar::my_bar_add(left, right)
}

#[link(name = "systemd")]
extern "C" {
fn init(p: *mut ());
}