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 (84 lines) | stat: -rw-r--r-- 3,122 bytes parent folder | download | duplicates (15)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler
// only require a native library and no supplementary object files to compile.
// #105601 made it possible to have this behaviour without an unstable flag by
// passing +bundle in modifiers, and this test checks that this feature successfully
// compiles and includes only the static libraries, with no object files.
// See https://github.com/rust-lang/rust/pull/105601

use run_make_support::{
    build_native_static_lib, llvm_ar, regex, rfs, rust_lib_name, rustc, static_lib_name,
};

//@ ignore-cross-compile
// Reason: Invalid library format (not ELF) causes compilation failure
// in the final `rustc` call.

//@ only-linux
// Reason: differences in the native lib compilation process causes differences
// in the --print link-args output

fn main() {
    build_native_static_lib("native_dep_1");
    build_native_static_lib("native_dep_2");
    build_native_static_lib("native_dep_3");
    build_native_static_lib("native_dep_4");
    // Test cfg with packed bundle.
    rustc().input("rust_dep_cfg.rs").crate_type("rlib").run();
    rustc()
        .input("main.rs")
        .extern_("rust_dep", rust_lib_name("rust_dep_cfg"))
        .crate_type("staticlib")
        .cfg("should_add")
        .run();
    // Only static libraries should appear, no object files at all.
    llvm_ar()
        .arg("t")
        .arg(rust_lib_name("rust_dep_cfg"))
        .run()
        .assert_stdout_contains(static_lib_name("native_dep_1"));
    llvm_ar()
        .arg("t")
        .arg(rust_lib_name("rust_dep_cfg"))
        .run()
        .assert_stdout_contains(static_lib_name("native_dep_2"));
    llvm_ar().arg("t").arg(static_lib_name("main")).run().assert_stdout_contains("native_dep_1.o");
    llvm_ar()
        .arg("t")
        .arg(static_lib_name("main"))
        .run()
        .assert_stdout_not_contains("native_dep_2.o");

    // Test bundle with whole archive.
    rustc().input("rust_dep.rs").crate_type("rlib").run();
    // Only deps with `+bundle` should appear.
    llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1");
    llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3");
    llvm_ar()
        .arg("t")
        .arg(rust_lib_name("rust_dep"))
        .run()
        .assert_stdout_not_contains("native_dep_2");
    llvm_ar()
        .arg("t")
        .arg(rust_lib_name("rust_dep"))
        .run()
        .assert_stdout_not_contains("native_dep_4");

    // The compiler shouldn't use files which it doesn't know about.
    rfs::remove_file(static_lib_name("native_dep_1"));
    rfs::remove_file(static_lib_name("native_dep_3"));

    let out = rustc()
        .input("main.rs")
        .extern_("rust_dep", rust_lib_name("rust_dep"))
        .print("link-args")
        .run()
        .assert_stdout_not_contains("native_dep_3")
        .stdout_utf8();

    let re = regex::Regex::new(
"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4"
    ).unwrap();

    assert!(re.is_match(&out));
}