Skip to content

Commit

Permalink
port tests/run-make/extern-fn-reachable to rmake
Browse files Browse the repository at this point in the history
uses helper functions added in rust-lang#128147, must not be merged before that
PR.
  • Loading branch information
binarycat committed Aug 6, 2024
1 parent 60d1465 commit f66adb0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl Rustc {
self
}

/// Make `rustc` prefere dynamic linking
pub fn prefer_dynamic(&mut self) -> &mut Self {
self.arg("-Cprefer-dynamic")
}

/// Specify directory path used for profile generation
pub fn profile_generate<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
let mut arg = OsString::new();
Expand Down
26 changes: 26 additions & 0 deletions src/tools/run-make-support/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ pub fn any_symbol_contains(path: impl AsRef<Path>, substrings: &[&str]) -> bool
false
})
}

/// Check if an object file contains *all* of the given symbols.
///
/// The symbol names must match exactly.
///
/// Panics if `path` is not a valid object file readable by the current user.
pub fn contains_exact_symbols(path: impl AsRef<Path>, symbol_names: &[&str]) -> bool {
let mut found = vec![false; symbol_names.len()];
with_symbol_iter(path, |syms| {
for sym in syms {
for (i, symbol_name) in symbol_names.iter().enumerate() {
found[i] |= sym.name_bytes().unwrap() == symbol_name.as_bytes();
}
}
});
let result = found.iter().all(|x| *x);
if !result {
eprintln!("does not contain symbol(s): ");
for i in 0..found.len() {
if !found[i] {
eprintln!("* {}", symbol_names[i]);
}
}
}
result
}
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 @@ -5,7 +5,6 @@ run-make/dep-info-doesnt-run-much/Makefile
run-make/dep-info-spaces/Makefile
run-make/dep-info/Makefile
run-make/emit-to-stdout/Makefile
run-make/extern-fn-reachable/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/jobserver-error/Makefile
Expand Down
26 changes: 0 additions & 26 deletions tests/run-make/extern-fn-reachable/Makefile

This file was deleted.

7 changes: 7 additions & 0 deletions tests/run-make/extern-fn-reachable/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ ignore-cross-compile
use run_make_support::{rustc, symbols::contains_exact_symbols};

fn main() {
rustc().input("dylib.rs").output("dylib.so").prefer_dynamic().run();
assert!(contains_exact_symbols("dylib.so", &["fun1", "fun2", "fun3", "fun4", "fun5"]));
}

0 comments on commit f66adb0

Please sign in to comment.