Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 608b322

Browse files
committedAug 6, 2024
rewrite staticlib-dylib-linkage to rmake
1 parent 2b78d92 commit 608b322

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed
 

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ run-make/reproducible-build/Makefile
3131
run-make/rlib-format-packed-bundled-libs/Makefile
3232
run-make/simd-ffi/Makefile
3333
run-make/split-debuginfo/Makefile
34-
run-make/staticlib-dylib-linkage/Makefile
3534
run-make/symbol-mangling-hashed/Makefile
3635
run-make/sysroot-crates-are-unstable/Makefile
3736
run-make/thumb-none-cortex-m/Makefile

‎tests/run-make/staticlib-dylib-linkage/Makefile

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

Comments
 (0)
Failed to load comments.