Skip to content
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

Port run-make --print=native-static-libs to rmake.rs #124383

Merged
merged 2 commits into from
Apr 27, 2024
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
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions tests/run-make/print-native-static-libs/Makefile

This file was deleted.

76 changes: 76 additions & 0 deletions tests/run-make/print-native-static-libs/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//! This checks the output of `--print=native-static-libs`
jieyouxu marked this conversation as resolved.
Show resolved Hide resolved
//!
//! 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, is_msvc};

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
jieyouxu marked this conversation as resolved.
Show resolved Hide resolved
.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();

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> = {
let mut args = args.clone();
args.dedup();
args
};
assert_eq!(args, dedup_args);
}

assert!(found_note);
}
Loading