rewrite obey-crate-type-flag to rmake

This commit is contained in:
Oneirical 2024-06-14 11:41:54 -04:00
parent cf9e7a975d
commit 2c7afc114d
4 changed files with 53 additions and 15 deletions

View File

@ -23,6 +23,7 @@
pub use bstr; pub use bstr;
pub use gimli; pub use gimli;
pub use glob;
pub use object; pub use object;
pub use regex; pub use regex;
pub use wasmparser; pub use wasmparser;
@ -223,6 +224,42 @@ pub fn bin_name(name: &str) -> String {
if is_windows() { format!("{name}.exe") } else { name.to_string() } if is_windows() { format!("{name}.exe") } else { name.to_string() }
} }
/// Remove all dynamic libraries possessing a name starting with `paths`.
#[track_caller]
pub fn remove_dylibs(paths: &str) {
let paths = format!(r"{paths}*");
remove_glob(dynamic_lib_name(&paths).as_str());
}
/// Remove all rust libraries possessing a name starting with `paths`.
#[track_caller]
pub fn remove_rlibs(paths: &str) {
let paths = format!(r"{paths}*");
remove_glob(rust_lib_name(&paths).as_str());
}
#[track_caller]
fn remove_glob(paths: &str) {
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
paths
.filter_map(|entry| entry.ok())
.filter(|entry| entry.as_path().is_file())
.for_each(|file| fs_wrapper::remove_file(&file));
}
#[track_caller]
fn count_glob(paths: &str) -> usize {
let paths = glob::glob(paths).expect(format!("Glob expression {paths} is not valid.").as_str());
paths.filter_map(|entry| entry.ok()).filter(|entry| entry.as_path().is_file()).count()
}
/// Count the number of rust libraries possessing a name starting with `paths`.
#[track_caller]
pub fn count_rlibs(paths: &str) -> usize {
let paths = format!(r"{paths}*");
count_glob(rust_lib_name(&paths).as_str())
}
/// Return the current working directory. /// Return the current working directory.
#[must_use] #[must_use]
pub fn cwd() -> PathBuf { pub fn cwd() -> PathBuf {

View File

@ -97,7 +97,6 @@ run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile run-make/no-builtins-attribute/Makefile
run-make/no-duplicate-libs/Makefile run-make/no-duplicate-libs/Makefile
run-make/obey-crate-type-flag/Makefile
run-make/panic-abort-eh_frame/Makefile run-make/panic-abort-eh_frame/Makefile
run-make/pass-linker-flags-flavor/Makefile run-make/pass-linker-flags-flavor/Makefile
run-make/pass-linker-flags-from-dep/Makefile run-make/pass-linker-flags-from-dep/Makefile

View File

@ -1,14 +0,0 @@
# ignore-cross-compile
include ../tools.mk
# check that rustc builds all crate_type attributes
# delete rlib
# delete whatever dylib is made for this system
# check that rustc only builds --crate-type flags, ignoring attributes
# fail if an rlib was built
all:
$(RUSTC) test.rs
$(call REMOVE_RLIBS,test)
$(call REMOVE_DYLIBS,test)
$(RUSTC) --crate-type dylib test.rs
$(call REMOVE_RLIBS,test) && exit 1 || exit 0

View File

@ -0,0 +1,16 @@
// test.rs should produce both an rlib and a dylib
// by default. When the crate_type flag is passed and
// forced to dylib, no rlibs should be produced.
// See https://github.com/rust-lang/rust/issues/11573
//@ ignore-cross-compile
use run_make_support::{count_rlibs, remove_dylibs, remove_rlibs, rustc};
fn main() {
rustc().input("test.rs").run();
remove_rlibs("test");
remove_dylibs("test");
rustc().crate_type("dylib").input("test.rs").run();
assert_eq!(count_rlibs("test"), 0);
}