Skip to content

Commit

Permalink
rewrite linkage-attr-on-static to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 17, 2024
1 parent 862e782 commit 2f31447
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 39 deletions.
30 changes: 5 additions & 25 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,6 @@ pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
}

/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
#[track_caller]
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
let src = format!("{lib_name}.c");
let lib_path = static_lib_name(lib_name);
if is_msvc() {
cc().arg("-c").out_exe(&obj_file).input(src).run();
} else {
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
};
let obj_file = if is_msvc() {
PathBuf::from(format!("{lib_name}.obj"))
} else {
PathBuf::from(format!("{lib_name}.o"))
};
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
path(lib_path)
}

/// Returns true if the filename at `path` is not in `expected`.
pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, expected: V) -> bool {
let expected = expected.as_ref();
Expand Down Expand Up @@ -339,11 +319,11 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
} else {
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
};
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
if is_msvc() {
obj_file.set_extension("");
obj_file.set_extension("obj");
}
let obj_file = if is_msvc() {
PathBuf::from(format!("{lib_name}.obj"))
} else {
PathBuf::from(format!("{lib_name}.o"))
};
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
path(lib_path)
}
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ run-make/libtest-thread-limit/Makefile
run-make/link-cfg/Makefile
run-make/link-framework/Makefile
run-make/link-path-order/Makefile
run-make/linkage-attr-on-static/Makefile
run-make/long-linker-command-lines-cmd-exe/Makefile
run-make/long-linker-command-lines/Makefile
run-make/longjmp-across-rust/Makefile
Expand Down Expand Up @@ -93,7 +92,6 @@ run-make/redundant-libs/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/return-non-c-like-enum-from-c/Makefile
run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
Expand Down
6 changes: 0 additions & 6 deletions tests/run-make/linkage-attr-on-static/Makefile

This file was deleted.

15 changes: 15 additions & 0 deletions tests/run-make/linkage-attr-on-static/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// #[linkage] is a useful attribute which can be applied to statics to allow
// external linkage, something which was not possible before #18890. This test
// checks that using this new feature results in successful compilation and execution.
// See https://github.com/rust-lang/rust/pull/18890

//@ ignore-cross-compile
// Reason: the compiled binary is executed

use run_make_support::{build_native_static_lib, run, rustc};

fn main() {
build_native_static_lib("foo");
rustc().input("bar.rs").run();
run("bar");
}
6 changes: 0 additions & 6 deletions tests/run-make/pass-non-c-like-enum-to-c/Makefile

This file was deleted.

0 comments on commit 2f31447

Please sign in to comment.