Skip to content

Altair-Bueno/poc-dynamic-loading-plugin-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC: Dynamically loading Rust plugins

This POC showcases how a Rust application can (re)load plugins by using Dynamic Link Libraries (DLL).

Running the example

Requirements

  • Rust
  • An operating system with support for DLL (e.g. macOS, Windows, Linux, ...)

Executing the example

  1. Compile all the plugins and the application. Because the application does not depend on any plugins directly, we need to manually build those.
cargo build --release
  1. Run the aplication. We are using cargo to simplify the execution, but it can be done without it. See packaging and distribution for more information.
# Change the extension to match your operating system
# macOS: .dylib
# Windows: .dll
# Linux: .so
cargo run --release -- libhello_world.dylib

FAQs

Sharing libraries between the application and plugins

Take a look to cargo-dynamic. Please note that some dependencies might be tricky to set up, particuarly those that use global variables. Some examples include tracing and log.

Packaging and distribution

Because all the code is dynamically linked, all dynamic dependencies must be included with the resulting application binary. These include all generated under the target directory, plus some other that live within the Rust installation. you can find these files by running rustc --print sysroot.

For example, on a macOS x86_64 system, we can run the application without cargo by using the following command:

DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib/rustlib/x86_64-apple-darwin/lib:$PWD/target/release" target/release/app libhello_world.dylib

And we can list the exact dependencies of our project requires by running the following command:

dyld_info -dependents target/release/{app,lib{hello-world,app_core}.dylib}

Usefull links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages