|
| 1 | +// Previously, rustc mandated that cdylibs could only link against rlibs as dependencies, |
| 2 | +// making linkage between cdylibs and dylibs impossible. After this was changed in #68448, |
| 3 | +// this test attempts to link both `foo` (a cdylib) and `bar` (a dylib) and checks that |
| 4 | +// both compilation and execution are successful. |
| 5 | +// See https://github.com/rust-lang/rust/pull/68448 |
| 6 | + |
| 7 | +//@ ignore-cross-compile |
| 8 | +// Reason: the compiled binary is executed |
| 9 | + |
| 10 | +use run_make_support::{ |
| 11 | + bin_name, cc, dynamic_lib_extension, dynamic_lib_name, has_extension, has_prefix, has_suffix, |
| 12 | + is_msvc, name_contains, path, run, rustc, shallow_find_files, target, |
| 13 | +}; |
| 14 | + |
| 15 | +fn main() { |
| 16 | + rustc().arg("-Cprefer-dynamic").input("bar.rs").run(); |
| 17 | + rustc().input("foo.rs").run(); |
| 18 | + let sysroot = rustc().print("sysroot").run().stdout_utf8(); |
| 19 | + let sysroot = sysroot.trim(); |
| 20 | + let target_sysroot = path(sysroot).join("lib/rustlib").join(target()).join("lib"); |
| 21 | + if is_msvc() { |
| 22 | + let mut libs = shallow_find_files(&target_sysroot, |path| { |
| 23 | + has_prefix(path, "libstd-") && has_suffix(path, ".dll.lib") |
| 24 | + }); |
| 25 | + libs.push(path("foo.dll.lib")); |
| 26 | + libs.push(path("bar.dll.lib")); |
| 27 | + cc().input("foo.c").args(&libs).out_exe("foo").run(); |
| 28 | + } else { |
| 29 | + let stdlibs = shallow_find_files(&target_sysroot, |path| { |
| 30 | + has_extension(path, dynamic_lib_extension()) && name_contains(path, "std") |
| 31 | + }); |
| 32 | + cc().input("foo.c") |
| 33 | + .args(&[dynamic_lib_name("foo"), dynamic_lib_name("bar")]) |
| 34 | + .arg(stdlibs.get(0).unwrap()) |
| 35 | + .library_search_path(&target_sysroot) |
| 36 | + .output(bin_name("foo")) |
| 37 | + .run(); |
| 38 | + } |
| 39 | + run("foo"); |
| 40 | +} |
0 commit comments