about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-02 21:54:30 +0000
committerbors <bors@rust-lang.org>2024-06-02 21:54:30 +0000
commit032af18af578f4283a2927fb43b90df2bbb72b67 (patch)
tree8321cf7ce119ba648ac3c6d220e73db8bb93afa7 /tests
parenta6416d8907bc94ef1a032d54cb0443cde963e455 (diff)
parent72ea7e92206cf2857c6eaa65d7fb6d043e29258f (diff)
downloadrust-032af18af578f4283a2927fb43b90df2bbb72b67.tar.gz
rust-032af18af578f4283a2927fb43b90df2bbb72b67.zip
Auto merge of #125902 - workingjubilee:rollup-f8x6iif, r=workingjubilee
Rollup of 6 pull requests

Successful merges:

 - #121062 (Change f32::midpoint to upcast to f64)
 - #125808 (Migrate `run-make/c-link-to-rust-dylib` to `rmake.rs`)
 - #125884 (Implement feature `integer_sign_cast`)
 - #125890 (Improve compiletest expected/not found formatting)
 - #125896 (compiletest: fix outdated rmake.rs comment)
 - #125898 (typo: depending from -> on)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/c-link-to-rust-dylib/Makefile21
-rw-r--r--tests/run-make/c-link-to-rust-dylib/rmake.rs41
2 files changed, 41 insertions, 21 deletions
diff --git a/tests/run-make/c-link-to-rust-dylib/Makefile b/tests/run-make/c-link-to-rust-dylib/Makefile
deleted file mode 100644
index 201f717ece4..00000000000
--- a/tests/run-make/c-link-to-rust-dylib/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-# This test checks that C linking with Rust does not encounter any errors, with dynamic libraries.
-# See https://github.com/rust-lang/rust/issues/10434
-
-# ignore-cross-compile
-include ../tools.mk
-
-all: $(TMPDIR)/$(call BIN,bar)
-	$(call RUN,bar)
-	$(call REMOVE_DYLIBS,foo)
-	$(call FAIL,bar)
-
-ifdef IS_MSVC
-$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
-	$(CC) bar.c $(TMPDIR)/foo.dll.lib $(call OUT_EXE,bar)
-else
-$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
-	$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -L $(TMPDIR)
-endif
-
-$(call DYLIB,foo): foo.rs
-	$(RUSTC) foo.rs
diff --git a/tests/run-make/c-link-to-rust-dylib/rmake.rs b/tests/run-make/c-link-to-rust-dylib/rmake.rs
new file mode 100644
index 00000000000..5c4b6d78649
--- /dev/null
+++ b/tests/run-make/c-link-to-rust-dylib/rmake.rs
@@ -0,0 +1,41 @@
+// This test checks that C linking with Rust does not encounter any errors, with dynamic libraries.
+// See <https://github.com/rust-lang/rust/issues/10434>.
+
+//@ ignore-cross-compile
+
+use std::fs::remove_file;
+
+use run_make_support::{
+    cc, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc, tmp_dir,
+};
+
+fn main() {
+    rustc().input("foo.rs").run();
+
+    if is_msvc() {
+        let lib = tmp_dir().join("foo.dll.lib");
+
+        cc().input("bar.c").arg(lib).out_exe("bar").run();
+    } else {
+        cc().input("bar.c")
+            .arg("-lfoo")
+            .output(tmp_dir().join("bar"))
+            .library_search_path(tmp_dir())
+            .run();
+    }
+
+    run("bar");
+
+    let expected_extension = dynamic_lib_extension();
+    read_dir(tmp_dir(), |path| {
+        if path.is_file()
+            && path.extension().is_some_and(|ext| ext == expected_extension)
+            && path.file_name().and_then(|name| name.to_str()).is_some_and(|name| {
+                name.ends_with(".so") || name.ends_with(".dll") || name.ends_with(".dylib")
+            })
+        {
+            remove_file(path).unwrap();
+        }
+    });
+    run_fail("bar");
+}