1//@ needs-target-std
2//
3// Since #19941, rustc can accept specifications on its library search paths.
4// This test runs Rust programs with varied library dependencies, expecting them
5// to succeed or fail depending on the situation.
6// The second part of the tests also checks that libraries with an incorrect hash
7// fail to be used by the compiler.
8// See https://github.com/rust-lang/rust/pull/19941
9
10//@ ignore-wasm32
11//@ ignore-wasm64
12// Reason: a C compiler is required for build_native_static_lib
13
14use run_make_support::{build_native_static_lib, rfs, rustc, static_lib_name};
15
16fn main() {
17 build_native_static_lib("native");
18 let lib_native = static_lib_name("native");
19 rfs::create_dir_all("crate");
20 rfs::create_dir_all("native");
21 rfs::rename(&lib_native, format!("native/{}", &lib_native));
22 rustc().input("a.rs").run();
23 rfs::rename("liba.rlib", "crate/liba.rlib");
24 rustc().input("b.rs").specific_library_search_path("native", "crate").run_fail();
25 rustc().input("b.rs").specific_library_search_path("dependency", "crate").run_fail();
26 rustc().input("b.rs").specific_library_search_path("crate", "crate").run();
27 rustc().input("b.rs").specific_library_search_path("all", "crate").run();
28
29 rustc().input("c.rs").specific_library_search_path("native", "crate").run_fail();
30 rustc().input("c.rs").specific_library_search_path("crate", "crate").run_fail();
31 rustc().input("c.rs").specific_library_search_path("dependency", "crate").run();
32 rustc().input("c.rs").specific_library_search_path("all", "crate").run();
33
34 rustc().input("d.rs").specific_library_search_path("dependency", "native").run_fail();
35 rustc().input("d.rs").specific_library_search_path("crate", "native").run_fail();
36 rustc().input("d.rs").specific_library_search_path("native", "native").run();
37 rustc().input("d.rs").specific_library_search_path("all", "native").run();
38
39 // Deduplication tests.
40 rfs::create_dir_all("e1");
41 rfs::create_dir_all("e2");
42
43 rustc().input("e.rs").output("e1/libe.rlib").run();
44 rustc().input("e.rs").output("e2/libe.rlib").run();
45 // If the library hash is correct, compilation should succeed.
46 rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run();
47 rustc()
48 .input("f.rs")
49 .specific_library_search_path("crate", "e1")
50 .library_search_path("e2")
51 .run();
52 rustc()
53 .input("f.rs")
54 .specific_library_search_path("crate", "e1")
55 .specific_library_search_path("crate", "e2")
56 .run();
57 // If the library has a different hash, errors should occur.
58 rustc().input("e2.rs").output("e2/libe.rlib").run();
59 rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run_fail();
60 rustc()
61 .input("f.rs")
62 .specific_library_search_path("crate", "e1")
63 .library_search_path("e2")
64 .run_fail();
65 rustc()
66 .input("f.rs")
67 .specific_library_search_path("crate", "e1")
68 .specific_library_search_path("crate", "e2")
69 .run_fail();
70 // Native and dependency paths do not cause errors.
71 rustc()
72 .input("f.rs")
73 .specific_library_search_path("native", "e1")
74 .library_search_path("e2")
75 .run();
76 rustc()
77 .input("f.rs")
78 .specific_library_search_path("dependency", "e1")
79 .library_search_path("e2")
80 .run();
81 rustc()
82 .input("f.rs")
83 .specific_library_search_path("dependency", "e1")
84 .specific_library_search_path("crate", "e2")
85 .run();
86}