Skip to content

Commit f71476d

Browse files
committed
Auto merge of #127693 - Rejyr:migrate-crate-hash-rustc-version-rmake, r=<try>
Migrate `crate-hash-rustc-version` to `rmake` Part of #121876. r? `@jieyouxu` try-job: x86_64-gnu-llvm-18 try-job: dist-x86_64-linux
2 parents b01a977 + eea6502 commit f71476d

File tree

3 files changed

+57
-39
lines changed

3 files changed

+57
-39
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ run-make/cat-and-grep-sanity-check/Makefile
1010
run-make/cdylib-dylib-linkage/Makefile
1111
run-make/compiler-lookup-paths-2/Makefile
1212
run-make/compiler-rt-works-on-mingw/Makefile
13-
run-make/crate-hash-rustc-version/Makefile
1413
run-make/cross-lang-lto-clang/Makefile
1514
run-make/cross-lang-lto-pgo-smoketest/Makefile
1615
run-make/cross-lang-lto-upstream-rlibs/Makefile

tests/run-make/crate-hash-rustc-version/Makefile

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Ensure that crates compiled with different rustc versions cannot
2+
// be dynamically linked.
3+
4+
//@ ignore-cross-compile
5+
//@ only-unix
6+
7+
use run_make_support::llvm;
8+
use run_make_support::{diff, dynamic_lib_name, is_darwin, run, run_fail, rustc};
9+
10+
fn llvm_readobj() -> llvm::LlvmReadobj {
11+
let mut cmd = llvm::llvm_readobj();
12+
if is_darwin() {
13+
cmd.symbols();
14+
} else {
15+
cmd.dynamic_table();
16+
}
17+
cmd
18+
}
19+
20+
fn main() {
21+
let flags = ["-Cprefer-dynamic", "-Csymbol-mangling-version=v0"];
22+
23+
// a.rs is compiled to a dylib
24+
rustc().input("a.rs").crate_type("dylib").args(&flags).run();
25+
26+
// Store symbols
27+
let symbols_before = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8();
28+
29+
// b.rs is compiled to a binary
30+
rustc()
31+
.input("b.rs")
32+
.extern_("a", dynamic_lib_name("a"))
33+
.crate_type("bin")
34+
.arg("-Crpath")
35+
.args(&flags)
36+
.run();
37+
run("b");
38+
39+
// Now re-compile a.rs with another rustc version
40+
rustc()
41+
.env("RUSTC_FORCE_RUSTC_VERSION", "deadfeed")
42+
.input("a.rs")
43+
.crate_type("dylib")
44+
.args(&flags)
45+
.run();
46+
47+
// After compiling with a different rustc version, store symbols again.
48+
let symbols_after = llvm_readobj().arg(dynamic_lib_name("a")).run().stdout_utf8();
49+
50+
// As a sanity check, test if the symbols changed:
51+
// If the symbols are identical, there's been an error.
52+
diff()
53+
.expected_text("symbols_before", symbols_before)
54+
.actual_text("symbols_after", symbols_after)
55+
.run_fail();
56+
run_fail("b");
57+
}

0 commit comments

Comments
 (0)