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 (56 lines) | stat: -rw-r--r-- 1,575 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
// Ensure that crates compiled with different rustc versions cannot
// be dynamically linked.

//@ ignore-cross-compile
//@ only-unix

use run_make_support::{diff, dynamic_lib_name, is_darwin, llvm, run, run_fail, rustc};

fn llvm_readobj() -> llvm::LlvmReadobj {
    let mut cmd = llvm::llvm_readobj();
    if is_darwin() {
        cmd.symbols();
    } else {
        cmd.dynamic_table();
    }
    cmd
}

fn main() {
    let flags = ["-Cprefer-dynamic", "-Csymbol-mangling-version=v0"];

    // a.rs is compiled to a dylib
    rustc().input("a.rs").crate_type("dylib").args(&flags).run();

    // Store symbols
    let symbols_before = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8();

    // b.rs is compiled to a binary
    rustc()
        .input("b.rs")
        .extern_("a", dynamic_lib_name("a"))
        .crate_type("bin")
        .arg("-Crpath")
        .args(&flags)
        .run();
    run("b");

    // Now re-compile a.rs with another rustc version
    rustc()
        .env("RUSTC_FORCE_RUSTC_VERSION", "deadfeed")
        .input("a.rs")
        .crate_type("dylib")
        .args(&flags)
        .run();

    // After compiling with a different rustc version, store symbols again.
    let symbols_after = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8();

    // As a sanity check, test if the symbols changed:
    // If the symbols are identical, there's been an error.
    diff()
        .expected_text("symbols_before", symbols_before)
        .actual_text("symbols_after", symbols_after)
        .run_fail();
    run_fail("b");
}