|
| 1 | +// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler |
| 2 | +// only require a native library and no supplementary object files to compile. |
| 3 | +// Output files compiled with this flag should still contain all expected symbols - |
| 4 | +// that is what this test checks. |
| 5 | +// See https://github.com/rust-lang/rust/pull/100101 |
| 6 | + |
| 7 | +// FIXME(Oneirical): MSVC and cross-compile |
| 8 | + |
| 9 | +use run_make_support::{ |
| 10 | + bin_name, build_native_static_lib, cwd, filename_contains, llvm_ar, llvm_nm, rfs, |
| 11 | + rust_lib_name, rustc, shallow_find_files, |
| 12 | +}; |
| 13 | + |
| 14 | +fn main() { |
| 15 | + build_native_static_lib("native_dep_1"); |
| 16 | + build_native_static_lib("native_dep_2"); |
| 17 | + build_native_static_lib("native_dep_3"); |
| 18 | + rustc().input("rust_dep_up.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run(); |
| 19 | + llvm_nm() |
| 20 | + .input(rust_lib_name("rust_dep_up")) |
| 21 | + .run() |
| 22 | + .assert_stdout_contains_regex("U.*native_f2"); |
| 23 | + llvm_nm() |
| 24 | + .input(rust_lib_name("rust_dep_up")) |
| 25 | + .run() |
| 26 | + .assert_stdout_contains_regex("U.*native_f3"); |
| 27 | + llvm_nm() |
| 28 | + .input(rust_lib_name("rust_dep_up")) |
| 29 | + .run() |
| 30 | + .assert_stdout_contains_regex("T.*rust_dep_up"); |
| 31 | + llvm_ar() |
| 32 | + .table_of_contents() |
| 33 | + .arg(rust_lib_name("rust_dep_up")) |
| 34 | + .run() |
| 35 | + .assert_stdout_contains("native_dep_2"); |
| 36 | + llvm_ar() |
| 37 | + .table_of_contents() |
| 38 | + .arg(rust_lib_name("rust_dep_up")) |
| 39 | + .run() |
| 40 | + .assert_stdout_contains("native_dep_3"); |
| 41 | + rustc() |
| 42 | + .input("rust_dep_local.rs") |
| 43 | + .extern_("rlib", rust_lib_name("rust_dep_up")) |
| 44 | + .arg("-Zpacked_bundled_libs") |
| 45 | + .crate_type("rlib") |
| 46 | + .run(); |
| 47 | + llvm_nm() |
| 48 | + .input(rust_lib_name("rust_dep_local")) |
| 49 | + .run() |
| 50 | + .assert_stdout_contains_regex("U.*native_f1"); |
| 51 | + llvm_nm() |
| 52 | + .input(rust_lib_name("rust_dep_local")) |
| 53 | + .run() |
| 54 | + .assert_stdout_contains_regex("T.*rust_dep_local"); |
| 55 | + llvm_ar() |
| 56 | + .table_of_contents() |
| 57 | + .arg(rust_lib_name("rust_dep_local")) |
| 58 | + .run() |
| 59 | + .assert_stdout_contains("native_dep_1"); |
| 60 | + |
| 61 | + // Ensure the compiler will not use files it should not know about. |
| 62 | + for file in shallow_find_files(cwd(), |path| filename_contains(path, "native_dep_")) { |
| 63 | + rfs::remove_file(file); |
| 64 | + } |
| 65 | + |
| 66 | + rustc() |
| 67 | + .input("main.rs") |
| 68 | + .extern_("lib", rust_lib_name("rust_dep_local")) |
| 69 | + .output(bin_name("main")) |
| 70 | + .arg("-Zpacked_bundled_libs") |
| 71 | + .print("link-args") |
| 72 | + .run() |
| 73 | + .assert_stdout_contains_regex("native_dep_1.*native_dep_2.*native_dep_3"); |
| 74 | + |
| 75 | + //FIXME(Oneirical): This part will apparently fail on MSVC |
| 76 | + llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f1"); |
| 77 | + llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f2"); |
| 78 | + llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f3"); |
| 79 | + llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_local"); |
| 80 | + llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_up"); |
| 81 | +} |
0 commit comments