|
| 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; |
| 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 | + assert!(args.contains(&"-lglib-2.0")); // in bar.rs |
| 49 | + assert!(args.contains(&"-lsystemd")); // in foo.rs |
| 50 | + assert!(args.contains(&"-lbar_cli")); |
| 51 | + assert!(args.contains(&"-lfoo_cli")); |
| 52 | + |
| 53 | + // make sure that no args are consecutively present |
| 54 | + let dedup_args: Vec<&str> = { |
| 55 | + let mut args = args.clone(); |
| 56 | + args.dedup(); |
| 57 | + args |
| 58 | + }; |
| 59 | + assert_eq!(args, dedup_args); |
| 60 | + } |
| 61 | + |
| 62 | + assert!(found_note); |
| 63 | +} |
0 commit comments