|
| 1 | +// A basic smoke test to check that rustc supports linking to a rust dylib with |
| 2 | +// --crate-type staticlib. bar is a dylib, on which foo is dependent - the native |
| 3 | +// static lib search paths are collected and used to compile foo.c, the final executable |
| 4 | +// which depends on both foo and bar. |
| 5 | +// See https://github.com/rust-lang/rust/pull/106560 |
| 6 | + |
| 7 | +//@ ignore-cross-compile |
| 8 | +// Reason: the compiled binary is executed. |
| 9 | +//@ ignore-wasm |
| 10 | +// Reason: WASM does not support dynamic libraries |
| 11 | +//@ ignore-msvc |
| 12 | +//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC, |
| 13 | +// which is not trivial to do. |
| 14 | +// Tracking issue: https://github.com/rust-lang/rust/issues/128602 |
| 15 | +// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172 |
| 16 | + |
| 17 | +use run_make_support::{cc, regex, run, rustc}; |
| 18 | + |
| 19 | +fn main() { |
| 20 | + rustc().arg("-Cprefer-dynamic").input("bar.rs").run(); |
| 21 | + let libs = rustc() |
| 22 | + .input("foo.rs") |
| 23 | + .crate_type("staticlib") |
| 24 | + .print("native-static-libs") |
| 25 | + .arg("-Zstaticlib-allow-rdylib-deps") |
| 26 | + .run() |
| 27 | + .assert_stderr_contains("note: native-static-libs: ") |
| 28 | + .stderr_utf8(); |
| 29 | + let re = regex::Regex::new(r#"note: native-static-libs:\s*(.+)"#).unwrap(); |
| 30 | + let libs = re.find(&libs).unwrap().as_str().trim(); |
| 31 | + // remove the note |
| 32 | + let (_, library_search_paths) = libs.split_once("note: native-static-libs: ").unwrap(); |
| 33 | + // divide the command-line arguments in a vec |
| 34 | + let library_search_paths = library_search_paths.split(' ').collect::<Vec<&str>>(); |
| 35 | + cc().input("foo.c").arg("-lfoo").args(library_search_paths).out_exe("foo").run(); |
| 36 | + run("foo"); |
| 37 | +} |
0 commit comments