|
| 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