Skip to content

Commit 80b6695

Browse files
authored
Unrolled build for rust-lang#124383
Rollup merge of rust-lang#124383 - Urgau:port-print-native-static-libs, r=jieyouxu Port run-make `--print=native-static-libs` to rmake.rs This PR port the run-make `--print=native-static-libs` test to rmake.rs The dedup was really awful in the `Makefile`, I'm glad to finally have a proper dedup detection for this. Related to rust-lang#121876 r? `@jieyouxu`
2 parents aa6a8ee + 7688f79 commit 80b6695

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ run-make/pretty-print-to-file/Makefile
220220
run-make/pretty-print-with-dep-file/Makefile
221221
run-make/print-calling-conventions/Makefile
222222
run-make/print-cfg/Makefile
223-
run-make/print-native-static-libs/Makefile
224223
run-make/print-target-list/Makefile
225224
run-make/profile/Makefile
226225
run-make/prune-link-args/Makefile

tests/run-make/print-native-static-libs/Makefile

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//! This checks the output of `--print=native-static-libs`
2+
//!
3+
//! Specifically, this test makes sure that one and only one
4+
//! note is emitted with the text "native-static-libs:" as prefix
5+
//! that the note contains the link args given in the source code
6+
//! and cli of the current crate and downstream crates.
7+
//!
8+
//! It also checks that there aren't any duplicated consecutive
9+
//! args, as they are useless and suboptimal for debugability.
10+
//! See https://github.com/rust-lang/rust/issues/113209.
11+
12+
//@ ignore-cross-compile
13+
//@ ignore-wasm
14+
15+
extern crate run_make_support;
16+
17+
use std::io::BufRead;
18+
19+
use run_make_support::{rustc, is_msvc};
20+
21+
fn main() {
22+
// build supporting crate
23+
rustc()
24+
.input("bar.rs")
25+
.crate_type("rlib")
26+
.arg("-lbar_cli")
27+
.run();
28+
29+
// build main crate as staticlib
30+
let output = rustc()
31+
.input("foo.rs")
32+
.crate_type("staticlib")
33+
.arg("-lfoo_cli")
34+
.arg("-lfoo_cli") // 2nd time
35+
.print("native-static-libs")
36+
.run();
37+
38+
let mut found_note = false;
39+
for l in output.stderr.lines() {
40+
let l = l.expect("utf-8 string");
41+
42+
let Some(args) = l.strip_prefix("note: native-static-libs:") else { continue; };
43+
assert!(!found_note);
44+
found_note = true;
45+
46+
let args: Vec<&str> = args.trim().split_ascii_whitespace().collect();
47+
48+
macro_rules! assert_contains_lib {
49+
($lib:literal in $args:ident) => {{
50+
let lib = format!(
51+
"{}{}{}",
52+
if !is_msvc() { "-l" } else { "" },
53+
$lib,
54+
if !is_msvc() { "" } else { ".lib" },
55+
);
56+
let found = $args.contains(&&*lib);
57+
assert!(found, "unable to find lib `{}` in those linker args: {:?}", lib, $args);
58+
}}
59+
}
60+
61+
assert_contains_lib!("glib-2.0" in args); // in bar.rs
62+
assert_contains_lib!("systemd" in args); // in foo.rs
63+
assert_contains_lib!("bar_cli" in args);
64+
assert_contains_lib!("foo_cli" in args);
65+
66+
// make sure that no args are consecutively present
67+
let dedup_args: Vec<&str> = {
68+
let mut args = args.clone();
69+
args.dedup();
70+
args
71+
};
72+
assert_eq!(args, dedup_args);
73+
}
74+
75+
assert!(found_note);
76+
}

0 commit comments

Comments
 (0)