rutis_dylib/lib.rs
1//! Optional in-process loader for trusted, first-party Rust dylib plugins.
2//!
3//! The dynamic loader is available on Linux, macOS and Windows (x64, MSVC);
4//! other targets retain the static host build without compiling
5//! platform-specific loader code. The checks before a library is opened, the
6//! cache, retention and the plugin factory are shared (`loader`); each
7//! platform module only opens libraries, finds symbols and locates the loaded
8//! SDK. See docs/dylib-sdk-implementation.md for platform differences.
9//!
10//! On Windows, plugins are opened with `LoadLibraryExW` by full path and
11//! `LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32`, and the
12//! cached file is held with read-only sharing from the hash check until it is
13//! mapped. Static initializers of a plugin (`.CRT$XCU`, e.g. the `ctor`
14//! crate) run under the loader lock and must not wait for other threads.
15
16#[cfg(any(target_os = "linux", target_os = "macos"))]
17#[path = "unix.rs"]
18mod platform;
19#[cfg(windows)]
20#[path = "windows.rs"]
21mod platform;
22
23#[cfg(any(target_os = "linux", target_os = "macos", windows))]
24mod loader;
25#[cfg(any(target_os = "linux", target_os = "macos", windows))]
26pub use loader::*;
27
28#[cfg(target_os = "macos")]
29mod macos;
30
31#[cfg(all(
32 any(target_os = "linux", target_os = "macos", windows),
33 feature = "loader"
34))]
35mod resolver;
36#[cfg(all(
37 any(target_os = "linux", target_os = "macos", windows),
38 feature = "loader"
39))]
40pub use resolver::DylibResolver;
41
42/// The message of the last failed `dlopen`, or that it left none. Not API:
43/// the test `tests/dlerror.rs` reaches the null check `open_library` uses.
44#[cfg(any(target_os = "linux", target_os = "macos"))]
45#[doc(hidden)]
46pub fn take_dl_error() -> String {
47 platform::take_dl_error()
48}