Auto merge of #90716 - euclio:libloading, r=cjgillot
replace dynamic library module with libloading This PR deletes the `rustc_metadata::dynamic_lib` module in favor of the popular and better tested [`libloading` crate](https://github.com/nagisa/rust_libloading/). We don't benefit from `libloading`'s symbol lifetimes since we end up leaking the loaded library in all cases, but the call-sites look much nicer by improving error handling and abstracting away some transmutes. We also can remove `rustc_metadata`'s direct dependencies on `libc` and `winapi`. This PR also adds an exception for `libloading` (and its license) to tidy, so this will need sign-off from the compiler team.
This commit is contained in:
commit
6bda5b331c
15 changed files with 91 additions and 313 deletions
|
|
@ -1,9 +1,25 @@
|
|||
-include ../tools.mk
|
||||
|
||||
# ignore-windows-msvc
|
||||
|
||||
NM=nm -D
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
NM=nm -gU
|
||||
endif
|
||||
|
||||
ifdef IS_WINDOWS
|
||||
NM=nm -g
|
||||
endif
|
||||
|
||||
# This overrides the LD_LIBRARY_PATH for RUN
|
||||
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
|
||||
|
||||
all:
|
||||
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so -C prefer-dynamic
|
||||
$(RUSTC) main.rs -C prefer-dynamic
|
||||
$(call RUN,main)
|
||||
|
||||
[ "$$($(NM) $(TMPDIR)/libdylib.so | grep -v __imp_ | grep -c fun1)" -eq "1" ]
|
||||
[ "$$($(NM) $(TMPDIR)/libdylib.so | grep -v __imp_ | grep -c fun2)" -eq "1" ]
|
||||
[ "$$($(NM) $(TMPDIR)/libdylib.so | grep -v __imp_ | grep -c fun3)" -eq "1" ]
|
||||
[ "$$($(NM) $(TMPDIR)/libdylib.so | grep -v __imp_ | grep -c fun4)" -eq "1" ]
|
||||
[ "$$($(NM) $(TMPDIR)/libdylib.so | grep -v __imp_ | grep -c fun5)" -eq "1" ]
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
#![feature(rustc_private)]
|
||||
|
||||
extern crate rustc_metadata;
|
||||
|
||||
use rustc_metadata::dynamic_lib::DynamicLibrary;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
let path = Path::new("libdylib.so");
|
||||
let a = DynamicLibrary::open(&path).unwrap();
|
||||
assert!(a.symbol::<isize>("fun1").is_ok());
|
||||
assert!(a.symbol::<isize>("fun2").is_ok());
|
||||
assert!(a.symbol::<isize>("fun3").is_ok());
|
||||
assert!(a.symbol::<isize>("fun4").is_ok());
|
||||
assert!(a.symbol::<isize>("fun5").is_ok());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue