Skip to content

Commit 9ce6229

Browse files
committed
rewrite compiler-lookup-paths to rmake
1 parent 16b5690 commit 9ce6229

File tree

4 files changed

+111
-45
lines changed

4 files changed

+111
-45
lines changed

src/tools/run-make-support/src/rustc.rs

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ impl Rustc {
242242
self
243243
}
244244

245+
/// Add a directory to the library search path with a restriction. Equivalent to `-L KIND=PATH` in rustc.
246+
pub fn specific_library_search_path<P: AsRef<Path>>(&mut self, kind: &str, path: P) -> &mut Self {
247+
assert!(["dependency", "native", "all", "framework", "crate"].contains(&kind));
248+
let path = path.as_ref().to_string_lossy();
249+
self.cmd.arg(format!("-L{kind}={path}"));
250+
self
251+
}
252+
245253
/// Override the system root. Equivalent to `--sysroot` in rustc.
246254
pub fn sysroot<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
247255
self.cmd.arg("--sysroot");

src/tools/tidy/src/allowed_run_make_makefiles.txt

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

tests/run-make/compiler-lookup-paths/Makefile

-44
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Since #19941, rustc can accept specifications on its library search paths.
2+
// This test runs Rust programs with varied library dependencies, expecting them
3+
// to succeed or fail depending on the situation.
4+
// The second part of the tests also checks that libraries with an incorrect hash
5+
// fail to be used by the compiler.
6+
// See https://github.com/rust-lang/rust/pull/19941
7+
8+
use run_make_support::fs_wrapper;
9+
use run_make_support::{rmake_out_path, rustc};
10+
11+
fn main() {
12+
assert!(rmake_out_path("libnative.a").exists());
13+
fs_wrapper::create_dir_all(rmake_out_path("crate"));
14+
fs_wrapper::create_dir_all(rmake_out_path("native"));
15+
fs_wrapper::rename(rmake_out_path("libnative.a"), rmake_out_path("native"));
16+
rustc().input("a.rs").run();
17+
fs_wrapper::rename(rmake_out_path("liba.a"), rmake_out_path("crate"));
18+
rustc()
19+
.input("b.rs")
20+
.specific_library_search_path("native", rmake_out_path("crate"))
21+
.run_fail();
22+
rustc()
23+
.input("b.rs")
24+
.specific_library_search_path("dependency", rmake_out_path("crate"))
25+
.run_fail();
26+
rustc().input("b.rs").specific_library_search_path("crate", rmake_out_path("crate")).run();
27+
rustc().input("b.rs").specific_library_search_path("all", rmake_out_path("crate")).run();
28+
29+
rustc()
30+
.input("c.rs")
31+
.specific_library_search_path("native", rmake_out_path("crate"))
32+
.run_fail();
33+
rustc().input("c.rs").specific_library_search_path("crate", rmake_out_path("crate")).run_fail();
34+
rustc().input("c.rs").specific_library_search_path("dependency", rmake_out_path("crate")).run();
35+
rustc().input("c.rs").specific_library_search_path("all", rmake_out_path("crate")).run();
36+
37+
rustc()
38+
.input("d.rs")
39+
.specific_library_search_path("dependency", rmake_out_path("native"))
40+
.run_fail();
41+
rustc()
42+
.input("d.rs")
43+
.specific_library_search_path("crate", rmake_out_path("native"))
44+
.run_fail();
45+
rustc().input("d.rs").specific_library_search_path("native", rmake_out_path("native")).run();
46+
rustc().input("d.rs").specific_library_search_path("all", rmake_out_path("native")).run();
47+
48+
// Deduplication tests.
49+
fs_wrapper::create_dir_all(rmake_out_path("e1"));
50+
fs_wrapper::create_dir_all(rmake_out_path("e2"));
51+
52+
rustc().input("e.rs").output(rmake_out_path("e1/libe.rlib")).run();
53+
rustc().input("e.rs").output(rmake_out_path("e2/libe.rlib")).run();
54+
// If the library hash is correct, compilation should succeed.
55+
rustc()
56+
.input("f.rs")
57+
.library_search_path(rmake_out_path("e1"))
58+
.library_search_path(rmake_out_path("e2"))
59+
.run();
60+
rustc()
61+
.input("f.rs")
62+
.specific_library_search_path("crate", rmake_out_path("e1"))
63+
.library_search_path(rmake_out_path("e2"))
64+
.run();
65+
rustc()
66+
.input("f.rs")
67+
.specific_library_search_path("crate", rmake_out_path("e1"))
68+
.specific_library_search_path("crate", rmake_out_path("e2"))
69+
.run();
70+
// If the library has a different hash, errors should occur.
71+
rustc().input("e2.rs").output(rmake_out_path("e2/libe.rlib")).run();
72+
rustc()
73+
.input("f.rs")
74+
.library_search_path(rmake_out_path("e1"))
75+
.library_search_path(rmake_out_path("e2"))
76+
.run_fail();
77+
rustc()
78+
.input("f.rs")
79+
.specific_library_search_path("crate", rmake_out_path("e1"))
80+
.library_search_path(rmake_out_path("e2"))
81+
.run_fail();
82+
rustc()
83+
.input("f.rs")
84+
.specific_library_search_path("crate", rmake_out_path("e1"))
85+
.specific_library_search_path("crate", rmake_out_path("e2"))
86+
.run_fail();
87+
// Native and dependency paths do not cause errors.
88+
rustc()
89+
.input("f.rs")
90+
.specific_library_search_path("native", rmake_out_path("e1"))
91+
.library_search_path(rmake_out_path("e2"))
92+
.run();
93+
rustc()
94+
.input("f.rs")
95+
.specific_library_search_path("dependency", rmake_out_path("e1"))
96+
.library_search_path(rmake_out_path("e2"))
97+
.run();
98+
rustc()
99+
.input("f.rs")
100+
.specific_library_search_path("dependency", rmake_out_path("e1"))
101+
.specific_library_search_path("crate", rmake_out_path("e2"))
102+
.run();
103+
}

0 commit comments

Comments
 (0)