File: rmake.rs

package info (click to toggle)
rustc 1.89.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 906,624 kB
  • sloc: xml: 158,148; python: 34,888; javascript: 19,595; sh: 19,221; ansic: 13,046; cpp: 7,144; asm: 4,376; makefile: 692; lisp: 174; sql: 15
file content (68 lines) | stat: -rw-r--r-- 2,239 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! 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

use run_make_support::{is_msvc, 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_utf8().lines() {
        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);
}