Skip to content

Commit

Permalink
Migrate run-make/c-link-to-rust-dylib to rmake.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 2, 2024
1 parent aa0f8f9 commit ab0fc6e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ run-make/bare-outfile/Makefile
run-make/branch-protection-check-IBT/Makefile
run-make/c-dynamic-dylib/Makefile
run-make/c-dynamic-rlib/Makefile
run-make/c-link-to-rust-dylib/Makefile
run-make/c-static-dylib/Makefile
run-make/c-static-rlib/Makefile
run-make/c-unwind-abi-catch-lib-panic/Makefile
Expand Down
21 changes: 0 additions & 21 deletions tests/run-make/c-link-to-rust-dylib/Makefile

This file was deleted.

44 changes: 44 additions & 0 deletions tests/run-make/c-link-to-rust-dylib/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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");

// We remove the file in case it exists.
let _ = remove_file(&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.starts_with("lib"))
{
remove_file(path).unwrap();
}
});
run_fail("bar");
}

0 comments on commit ab0fc6e

Please sign in to comment.