|
| 1 | +// When we generate the import library for a dylib or bin crate, we should generate it |
| 2 | +// for the symbols both for the current crate and all upstream crates. This allows for |
| 3 | +// using the link kind `raw-dylib` inside inline functions successfully. This test checks |
| 4 | +// that the import symbols in the object files match this convention, and that execution |
| 5 | +// of the binary results in all function names exported successfully. |
| 6 | +// See https://github.com/rust-lang/rust/pull/102988 |
| 7 | + |
| 8 | +//@ only-windows |
| 9 | + |
| 10 | +use run_make_support::{cc, diff, is_msvc, llvm_objdump, run, rustc}; |
| 11 | + |
| 12 | +fn main() { |
| 13 | + rustc() |
| 14 | + .crate_type("dylib") |
| 15 | + .crate_name("raw_dylib_test") |
| 16 | + .input("lib.rs") |
| 17 | + .arg("-Cprefer-dynamic") |
| 18 | + .run(); |
| 19 | + rustc() |
| 20 | + .crate_type("dylib") |
| 21 | + .crate_name("raw_dylib_test_wrapper") |
| 22 | + .input("lib_wrapper.rs") |
| 23 | + .arg("-Cprefer-dynamic") |
| 24 | + .run(); |
| 25 | + rustc().crate_type("bin").input("driver.rs").arg("-Cprefer-dynamic").run(); |
| 26 | + llvm_objdump() |
| 27 | + .arg("--private-headers") |
| 28 | + .input("driver.exe") |
| 29 | + .run() |
| 30 | + // Make sure we don't find an import to the functions we expect to be inlined. |
| 31 | + .assert_stdout_not_contains("inline_library_function") |
| 32 | + // Make sure we do find an import to the functions we expect to be imported. |
| 33 | + .assert_stdout_contains("library_function"); |
| 34 | + if is_msvc() { |
| 35 | + cc().arg("-c").out_exe("extern_1").input("extern_1.c").run(); |
| 36 | + cc().arg("-c").out_exe("extern_2").input("extern_2.c").run(); |
| 37 | + cc().input("extern_1.obj") |
| 38 | + .arg("-link") |
| 39 | + .arg("-dll") |
| 40 | + .arg("-out:extern_1.dll") |
| 41 | + .arg("-noimplib") |
| 42 | + .run(); |
| 43 | + cc().input("extern_2.obj") |
| 44 | + .arg("-link") |
| 45 | + .arg("-dll") |
| 46 | + .arg("-out:extern_2.dll") |
| 47 | + .arg("-noimplib") |
| 48 | + .run(); |
| 49 | + } else { |
| 50 | + cc().arg("-v").arg("-c").out_exe("extern_1").input("extern_1.c").run(); |
| 51 | + cc().arg("-v").arg("-c").out_exe("extern_2").input("extern_2.c").run(); |
| 52 | + cc().input("extern_1").out_exe("extern_1.dll").arg("-shared").run(); |
| 53 | + cc().input("extern_2").out_exe("extern_2.dll").arg("-shared").run(); |
| 54 | + } |
| 55 | + let out = run("driver").stdout_utf8(); |
| 56 | + diff() |
| 57 | + .expected_file("output.txt") |
| 58 | + .actual_text("actual_output", out) |
| 59 | + .normalize(r#"\r"#, "") |
| 60 | + .run(); |
| 61 | +} |
0 commit comments