|
| 1 | +// `raw-dylib` is a Windows-specific attribute which emits idata sections for the items in the |
| 2 | +// attached extern block, |
| 3 | +// so they may be linked against without linking against an import library. |
| 4 | +// To learn more, read https://github.com/rust-lang/rfcs/blob/master/text/2627-raw-dylib-kind.md |
| 5 | +// `#[link_ordinal(n)]` allows Rust to link against DLLs that export symbols by ordinal rather |
| 6 | +// than by name. As long as the ordinal matches, the name of the function in Rust is not |
| 7 | +// required to match the name of the corresponding function in the exporting DLL. |
| 8 | +// This test checks the correctness of this feature by comparing its output against expected |
| 9 | +// output. |
| 10 | +// See https://github.com/rust-lang/rust/pull/89025 |
| 11 | + |
| 12 | +//@ only-windows |
| 13 | + |
| 14 | +use run_make_support::{cc, diff, is_msvc, run, rustc}; |
| 15 | + |
| 16 | +// NOTE: build_native_dynamic lib is not used, as the special `def` files |
| 17 | +// must be passed to the CC compiler. |
| 18 | + |
| 19 | +fn main() { |
| 20 | + rustc().crate_type("lib").crate_name("raw_dylib_test").input("lib.rs").run(); |
| 21 | + rustc().crate_type("bin").input("driver.rs").run(); |
| 22 | + if is_msvc() { |
| 23 | + cc().arg("-c").out_exe("exporter").input("exporter.c").run(); |
| 24 | + cc().input("exporter.obj") |
| 25 | + .arg("exporter.msvc.def") |
| 26 | + .args(&["-link", "-dll", "-noimplib", "-out:exporter.dll"]) |
| 27 | + .run(); |
| 28 | + } else { |
| 29 | + cc().arg("-v").arg("-c").out_exe("exporter.obj").input("exporter.c").run(); |
| 30 | + cc().input("exporter.obj") |
| 31 | + .arg("exporter.gnu.def") |
| 32 | + .args(&["--no-leading-underscore", "-shared"]) |
| 33 | + .output("exporter.dll") |
| 34 | + .run(); |
| 35 | + }; |
| 36 | + let out = run("driver").stdout_utf8(); |
| 37 | + diff().expected_file("output.txt").actual_text("actual", out).normalize(r#"\r"#, "").run(); |
| 38 | +} |
0 commit comments