From 06779d5d08b1083bd75e9176b03d140f348bd957 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 17 Feb 2024 04:31:46 +0100 Subject: [PATCH 1/2] Always emit native-static-libs note, even if it is empty --- compiler/rustc_codegen_ssa/src/back/link.rs | 14 +++++--------- .../ui/codegen/empty-static-libs-issue-108825.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 tests/ui/codegen/empty-static-libs-issue-108825.rs diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index a564e0e391fee..2e614a1f06f1f 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1560,17 +1560,13 @@ fn print_native_static_libs( match out { OutFileName::Real(path) => { out.overwrite(&lib_args.join(" "), sess); - if !lib_args.is_empty() { - sess.dcx().emit_note(errors::StaticLibraryNativeArtifactsToFile { path }); - } + sess.dcx().emit_note(errors::StaticLibraryNativeArtifactsToFile { path }); } OutFileName::Stdout => { - if !lib_args.is_empty() { - sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts); - // Prefix for greppability - // Note: This must not be translated as tools are allowed to depend on this exact string. - sess.dcx().note(format!("native-static-libs: {}", lib_args.join(" "))); - } + sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts); + // Prefix for greppability + // Note: This must not be translated as tools are allowed to depend on this exact string. + sess.dcx().note(format!("native-static-libs: {}", lib_args.join(" "))); } } } diff --git a/tests/ui/codegen/empty-static-libs-issue-108825.rs b/tests/ui/codegen/empty-static-libs-issue-108825.rs new file mode 100644 index 0000000000000..25c471e235ffb --- /dev/null +++ b/tests/ui/codegen/empty-static-libs-issue-108825.rs @@ -0,0 +1,16 @@ +//! Test that linking a no_std application still outputs the +//! `native-static-libs: ` note, even though it's empty. + +//@ compile-flags: -Cpanic=abort --print=native-static-libs +//@ build-pass +//@ error-pattern: note: native-static-libs: +//@ dont-check-compiler-stderr libcore links `/defaultlib:msvcrt` or `/defaultlib:libcmt` on MSVC +//@ ignore-cross-compile doesn't produce any output on i686-unknown-linux-gnu for some reason? + +#![crate_type = "staticlib"] +#![no_std] + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} From 54edf8c744f181e5bb24cab12eee065f9b73b25b Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Thu, 27 Mar 2025 01:14:01 +0800 Subject: [PATCH 2/2] [DO NOT MERGE] What happens if we don't ignore-cross-compile --- tests/ui/codegen/empty-static-libs-issue-108825.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/codegen/empty-static-libs-issue-108825.rs b/tests/ui/codegen/empty-static-libs-issue-108825.rs index 25c471e235ffb..9abe9799270c6 100644 --- a/tests/ui/codegen/empty-static-libs-issue-108825.rs +++ b/tests/ui/codegen/empty-static-libs-issue-108825.rs @@ -5,7 +5,7 @@ //@ build-pass //@ error-pattern: note: native-static-libs: //@ dont-check-compiler-stderr libcore links `/defaultlib:msvcrt` or `/defaultlib:libcmt` on MSVC -//@ ignore-cross-compile doesn't produce any output on i686-unknown-linux-gnu for some reason? +//-@ ignore-cross-compile doesn't produce any output on i686-unknown-linux-gnu for some reason? #![crate_type = "staticlib"] #![no_std]