{"id":16162412,"url":"https://github.com/sunsided/rust-dynamic-loading-plugins","last_synced_at":"2025-10-07T01:36:49.903Z","repository":{"id":209300421,"uuid":"723696432","full_name":"sunsided/rust-dynamic-loading-plugins","owner":"sunsided","description":"Dynamically loading libraries / plugins at runtime in Rust","archived":false,"fork":false,"pushed_at":"2023-11-26T16:40:34.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-20T06:48:28.144Z","etag":null,"topics":["dynamic-loading","libloading","plugins","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunsided.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-26T13:48:48.000Z","updated_at":"2024-11-29T05:10:49.000Z","dependencies_parsed_at":"2023-11-26T15:06:36.107Z","dependency_job_id":"69ca61f3-edd5-4d7e-8fd2-0fe9a72d34f5","html_url":"https://github.com/sunsided/rust-dynamic-loading-plugins","commit_stats":null,"previous_names":["sunsided/rust-dynamic-loading","sunsided/rust-dynamic-loading-plugins"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sunsided/rust-dynamic-loading-plugins","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Frust-dynamic-loading-plugins","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Frust-dynamic-loading-plugins/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Frust-dynamic-loading-plugins/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Frust-dynamic-loading-plugins/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/rust-dynamic-loading-plugins/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Frust-dynamic-loading-plugins/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278708073,"owners_count":26031932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-loading","libloading","plugins","rust"],"created_at":"2024-10-10T02:30:02.650Z","updated_at":"2025-10-07T01:36:49.885Z","avatar_url":"https://github.com/sunsided.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamic Loading: Plugins in Rust\n\nEnsure both the application and the plugin are built:\n\n```shell\ncargo build -p app -p example-plugin\n```\n\nThen run the application from the repository root\n\n```shell\ncargo run\n```\n\nThis should print output like the following:\n\n```\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Loading plugin from \"target/debug/deps/libexample_plugin.so\"\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Initializing logger for loaded library\n[2023-11-26T16:30:06Z DEBUG example_plugin] Logger initialized\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Loaded plugin: TestPlugin 0.1.0+integration-test\n[2023-11-26T16:30:06Z INFO  example_plugin] Plugin loaded\n[2023-11-26T16:30:06Z INFO  app] Data before applying plugins: 21\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Firing pre_operation hooks\n[2023-11-26T16:30:06Z TRACE app::plugin_manager] Firing pre_operation for TestPlugin 0.1.0+integration-test\n[2023-11-26T16:30:06Z INFO  example_plugin] Added 1 to input\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Firing operation hooks\n[2023-11-26T16:30:06Z TRACE app::plugin_manager] Firing operation for TestPlugin 0.1.0+integration-test\n[2023-11-26T16:30:06Z INFO  example_plugin] Multiplied input by 2\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Firing post_operation hooks\n[2023-11-26T16:30:06Z TRACE app::plugin_manager] Firing post_operation for TestPlugin 0.1.0+integration-test\n[2023-11-26T16:30:06Z INFO  example_plugin] Subtracted 2 from input\n[2023-11-26T16:30:06Z INFO  app] Data after applying plugins: 42\n[2023-11-26T16:30:06Z DEBUG app::plugin_manager] Unloading plugins\n[2023-11-26T16:30:06Z TRACE app::plugin_manager] Firing on_plugin_unload for TestPlugin 0.1.0+integration-test\n[2023-11-26T16:30:06Z INFO  example_plugin] Plugin unloaded\n[2023-11-26T16:30:06Z TRACE app::plugin_manager] Unloading logger\n```\n\nThis assumes the environment provided in the [.env](.env) file:\n\n```.dotenv\nRUST_LOG=app=trace,example_plugin=debug\n```\n\n## Logging in the Plugins\n\nIn order to achieve logging in the dynamically loaded libraries, a `declare_logger_plugin!`\nmacro is provided. It exports the `_logger_create` used to initialize the logger.\nIf this symbol is found, an instance to the logger and the lowest log level is passed,\nwhich is then set up as the global logger within the shared library.\n\nFor this to work, a `\u0026'static dyn Log` reference needs to be available, which is a bit\nof a hackery in `main`: A `StaticLogger` type takes ownership of the `Box\u003cenv_logger::Logger\u003e`\nand _pretends_ to be able to provide a `\u0026'static dyn Log` instance. This assumes that this logger\nis always created first and destroyed last.\n\n## Further reading\n\nThis toy project is inspired by Michael F. Bryan's [Dynamic Loading \u0026 Plugins] post.\n\n[Dynamic Loading \u0026 Plugins]: https://michael-f-bryan.github.io/rust-ffi-guide/dynamic_loading.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Frust-dynamic-loading-plugins","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Frust-dynamic-loading-plugins","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Frust-dynamic-loading-plugins/lists"}