|
| 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 | +//@ ignore-wasm32 |
| 9 | +//@ ignore-wasm64 |
| 10 | +// Reason: a C compiler is required for build_native_static_lib |
| 11 | + |
| 12 | +use run_make_support::{build_native_static_lib, fs_wrapper, rustc, static_lib_name}; |
| 13 | + |
| 14 | +fn main() { |
| 15 | + build_native_static_lib("native"); |
| 16 | + let lib_native = static_lib_name("native"); |
| 17 | + fs_wrapper::create_dir_all("crate"); |
| 18 | + fs_wrapper::create_dir_all("native"); |
| 19 | + fs_wrapper::rename(&lib_native, format!("native/{}", &lib_native)); |
| 20 | + rustc().input("a.rs").run(); |
| 21 | + fs_wrapper::rename("liba.rlib", "crate/liba.rlib"); |
| 22 | + rustc().input("b.rs").specific_library_search_path("native", "crate").run_fail(); |
| 23 | + rustc().input("b.rs").specific_library_search_path("dependency", "crate").run_fail(); |
| 24 | + rustc().input("b.rs").specific_library_search_path("crate", "crate").run(); |
| 25 | + rustc().input("b.rs").specific_library_search_path("all", "crate").run(); |
| 26 | + |
| 27 | + rustc().input("c.rs").specific_library_search_path("native", "crate").run_fail(); |
| 28 | + rustc().input("c.rs").specific_library_search_path("crate", "crate").run_fail(); |
| 29 | + rustc().input("c.rs").specific_library_search_path("dependency", "crate").run(); |
| 30 | + rustc().input("c.rs").specific_library_search_path("all", "crate").run(); |
| 31 | + |
| 32 | + rustc().input("d.rs").specific_library_search_path("dependency", "native").run_fail(); |
| 33 | + rustc().input("d.rs").specific_library_search_path("crate", "native").run_fail(); |
| 34 | + rustc().input("d.rs").specific_library_search_path("native", "native").run(); |
| 35 | + rustc().input("d.rs").specific_library_search_path("all", "native").run(); |
| 36 | + |
| 37 | + // Deduplication tests. |
| 38 | + fs_wrapper::create_dir_all("e1"); |
| 39 | + fs_wrapper::create_dir_all("e2"); |
| 40 | + |
| 41 | + rustc().input("e.rs").output("e1/libe.rlib").run(); |
| 42 | + rustc().input("e.rs").output("e2/libe.rlib").run(); |
| 43 | + // If the library hash is correct, compilation should succeed. |
| 44 | + rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run(); |
| 45 | + rustc() |
| 46 | + .input("f.rs") |
| 47 | + .specific_library_search_path("crate", "e1") |
| 48 | + .library_search_path("e2") |
| 49 | + .run(); |
| 50 | + rustc() |
| 51 | + .input("f.rs") |
| 52 | + .specific_library_search_path("crate", "e1") |
| 53 | + .specific_library_search_path("crate", "e2") |
| 54 | + .run(); |
| 55 | + // If the library has a different hash, errors should occur. |
| 56 | + rustc().input("e2.rs").output("e2/libe.rlib").run(); |
| 57 | + rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run_fail(); |
| 58 | + rustc() |
| 59 | + .input("f.rs") |
| 60 | + .specific_library_search_path("crate", "e1") |
| 61 | + .library_search_path("e2") |
| 62 | + .run_fail(); |
| 63 | + rustc() |
| 64 | + .input("f.rs") |
| 65 | + .specific_library_search_path("crate", "e1") |
| 66 | + .specific_library_search_path("crate", "e2") |
| 67 | + .run_fail(); |
| 68 | + // Native and dependency paths do not cause errors. |
| 69 | + rustc() |
| 70 | + .input("f.rs") |
| 71 | + .specific_library_search_path("native", "e1") |
| 72 | + .library_search_path("e2") |
| 73 | + .run(); |
| 74 | + rustc() |
| 75 | + .input("f.rs") |
| 76 | + .specific_library_search_path("dependency", "e1") |
| 77 | + .library_search_path("e2") |
| 78 | + .run(); |
| 79 | + rustc() |
| 80 | + .input("f.rs") |
| 81 | + .specific_library_search_path("dependency", "e1") |
| 82 | + .specific_library_search_path("crate", "e2") |
| 83 | + .run(); |
| 84 | +} |
0 commit comments