From 74cbc09fc914961d98a64e203b9a6dbc8bc00375 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 25 Apr 2024 20:39:17 +0200 Subject: [PATCH 1/2] Port run-make `--print=native-static-libs` to rmake.rs --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../print-native-static-libs/Makefile | 19 ------ .../print-native-static-libs/rmake.rs | 63 +++++++++++++++++++ 3 files changed, 63 insertions(+), 20 deletions(-) delete mode 100644 tests/run-make/print-native-static-libs/Makefile create mode 100644 tests/run-make/print-native-static-libs/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 9b3c0d0f1a5..1b560ee352c 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -220,7 +220,6 @@ run-make/pretty-print-to-file/Makefile run-make/pretty-print-with-dep-file/Makefile run-make/print-calling-conventions/Makefile run-make/print-cfg/Makefile -run-make/print-native-static-libs/Makefile run-make/print-target-list/Makefile run-make/profile/Makefile run-make/prune-link-args/Makefile diff --git a/tests/run-make/print-native-static-libs/Makefile b/tests/run-make/print-native-static-libs/Makefile deleted file mode 100644 index a16c8b0f2a4..00000000000 --- a/tests/run-make/print-native-static-libs/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include ../tools.mk - -# ignore-cross-compile -# ignore-wasm - -all: - $(RUSTC) --crate-type rlib -lbar_cli bar.rs - $(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 - - 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" - - # 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/rmake.rs b/tests/run-make/print-native-static-libs/rmake.rs new file mode 100644 index 00000000000..efc51d276ef --- /dev/null +++ b/tests/run-make/print-native-static-libs/rmake.rs @@ -0,0 +1,63 @@ +//! This checks the output of `--print=native-static-libs` +//! +//! Specifically, this test makes sure that one and only one +//! note is emitted with the text "native-static-libs:" as prefix +//! that the note contains the link args given in the source code +//! and cli of the current crate and downstream crates. +//! +//! It also checks that there aren't any duplicated consecutive +//! args, as they are useless and suboptimal for debugability. +//! See https://github.com/rust-lang/rust/issues/113209. + +//@ ignore-cross-compile +//@ ignore-wasm + +extern crate run_make_support; + +use std::io::BufRead; + +use run_make_support::rustc; + +fn main() { + // build supporting crate + rustc() + .input("bar.rs") + .crate_type("rlib") + .arg("-lbar_cli") + .run(); + + // build main crate as staticlib + let output = rustc() + .input("foo.rs") + .crate_type("staticlib") + .arg("-lfoo_cli") + .arg("-lfoo_cli") // 2nd time + .print("native-static-libs") + .run(); + + let mut found_note = false; + for l in output.stderr.lines() { + let l = l.expect("utf-8 string"); + + let Some(args) = l.strip_prefix("note: native-static-libs:") else { continue; }; + assert!(!found_note); + found_note = true; + + let args: Vec<&str> = args.trim().split_ascii_whitespace().collect(); + + assert!(args.contains(&"-lglib-2.0")); // in bar.rs + assert!(args.contains(&"-lsystemd")); // in foo.rs + assert!(args.contains(&"-lbar_cli")); + assert!(args.contains(&"-lfoo_cli")); + + // make sure that no args are consecutively present + let dedup_args: Vec<&str> = { + let mut args = args.clone(); + args.dedup(); + args + }; + assert_eq!(args, dedup_args); + } + + assert!(found_note); +} From 7688f798d543039387d87401889b75e9305a7a6d Mon Sep 17 00:00:00 2001 From: Urgau Date: Sat, 27 Apr 2024 00:26:06 +0200 Subject: [PATCH 2/2] Also support MSVC in print-native-static-libs test --- .../print-native-static-libs/rmake.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/run-make/print-native-static-libs/rmake.rs b/tests/run-make/print-native-static-libs/rmake.rs index efc51d276ef..fc8701777d1 100644 --- a/tests/run-make/print-native-static-libs/rmake.rs +++ b/tests/run-make/print-native-static-libs/rmake.rs @@ -16,7 +16,7 @@ use std::io::BufRead; -use run_make_support::rustc; +use run_make_support::{rustc, is_msvc}; fn main() { // build supporting crate @@ -45,10 +45,23 @@ fn main() { let args: Vec<&str> = args.trim().split_ascii_whitespace().collect(); - assert!(args.contains(&"-lglib-2.0")); // in bar.rs - assert!(args.contains(&"-lsystemd")); // in foo.rs - assert!(args.contains(&"-lbar_cli")); - assert!(args.contains(&"-lfoo_cli")); + macro_rules! assert_contains_lib { + ($lib:literal in $args:ident) => {{ + let lib = format!( + "{}{}{}", + if !is_msvc() { "-l" } else { "" }, + $lib, + if !is_msvc() { "" } else { ".lib" }, + ); + let found = $args.contains(&&*lib); + assert!(found, "unable to find lib `{}` in those linker args: {:?}", lib, $args); + }} + } + + assert_contains_lib!("glib-2.0" in args); // in bar.rs + assert_contains_lib!("systemd" in args); // in foo.rs + assert_contains_lib!("bar_cli" in args); + assert_contains_lib!("foo_cli" in args); // make sure that no args are consecutively present let dedup_args: Vec<&str> = {