{"id":29066898,"url":"https://github.com/rhaiscript/rhai-dylib","last_synced_at":"2026-01-24T18:03:55.777Z","repository":{"id":61374848,"uuid":"539962032","full_name":"rhaiscript/rhai-dylib","owner":"rhaiscript","description":"A plugin system for the Rhai embedded scripting language.","archived":false,"fork":false,"pushed_at":"2025-11-29T12:22:04.000Z","size":99,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-25T14:42:26.010Z","etag":null,"topics":["rhai","rhai-dylib","scripting-language"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhaiscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE.txt","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-09-22T12:08:13.000Z","updated_at":"2025-11-29T12:22:08.000Z","dependencies_parsed_at":"2023-02-17T19:00:44.397Z","dependency_job_id":"770b8edb-66c0-46ec-944b-cb860f82dc09","html_url":"https://github.com/rhaiscript/rhai-dylib","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/rhaiscript/rhai-dylib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-dylib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-dylib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-dylib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-dylib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhaiscript","download_url":"https://codeload.github.com/rhaiscript/rhai-dylib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-dylib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28733372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T17:51:25.893Z","status":"ssl_error","status_checked_at":"2026-01-24T17:50:48.377Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["rhai","rhai-dylib","scripting-language"],"created_at":"2025-06-27T10:08:53.170Z","updated_at":"2026-01-24T18:03:55.761Z","avatar_url":"https://github.com/rhaiscript.png","language":"Rust","readme":"# Rhai Dylib\n\nThis crate exposes a simple API to load `dylib` Rust crates in a [Rhai](https://rhai.rs/) engine using [Rhai modules](https://rhai.rs/book/rust/modules/index.html).\nYou can generate your own library project for [Rhai](https://rhai.rs/) using [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) with [`this template`](https://github.com/ltabis/rhai-dylib-template).\n\n## Loader\n\n`Loader` is a trait that is used to build objects that load rhai modules from dynamic libraries in memory. A [libloading](https://github.com/nagisa/rust_libloading) implementation is available, which enables you to load modules via a `cdylib` or `dylib` rust crate.\n\nCheck the `simple` example for more details.\n\n## Module Resolver\n\nThis crate also expose a [Rhai Module Resolver](https://rhai.rs/book/rust/modules/resolvers.html) that loads dynamic libraries at the given path.\n\n```rust,ignore\nuse rhai_dylib::module_resolvers::libloading::DylibModuleResolver;\n\nlet mut engine = rhai::Engine::new();\n\n// use `rhai::module_resolvers::ModuleResolversCollection` if you need to resolve using\n// other resolvers.\n// Check out https://docs.rs/rhai/latest/rhai/module_resolvers/struct.ModuleResolversCollection.html\nengine.set_module_resolver(DylibModuleResolver::new());\n\nengine.run(r#\"\nimport \"/usr/lib/libmy\" as my; // Import your dynamic library.\n\nmy::my_function(); // Use exported items !\n\"#).expect(\"failed to run script\");\n```\n\nCheck the `module_resolver` example for more details.\n\n## Pitfalls\n\nThere are multiple limitations with this implementation.\n\n\u003e TL;DR\n\u003e To use this crate, you need to:\n\u003e - Compile **EVERYTHING**, plugins and program that will load them, inside the **SAME** workspace or **WITHOUT** a workspace.\n\u003e - Use the `rhai::config::hashing::set_hashing_seed` function with the **SAME** four u64 array when building your plugins and the program that will load them. (i.e. `rhai::config::hashing::set_hashing_seed(Some([1, 2, 3, 4]))`)\n\n### TypeId\n\nRust [`TypeId`](https://doc.rust-lang.org/std/any/struct.TypeId.html) is an object used to compare types at compile time. Rhai uses those to check which type a [`Dynamic`](https://docs.rs/rhai/1.10.1/rhai/struct.Dynamic.html) object is. This is a problem for dynamic libraries because `TypeIds` sometime change between compilations.\n\nThat means that in certain situations, Rhai cannot compare two types, even though they are the same, because the `TypeId` of said types is different between the plugin and the binary.\n\nTo fix this, you will need to compile your main binary **AND** plugins inside the **SAME** workspace, or compile everything **OUTSIDE** of a workspace. Compiling, for example, a binary in a workspace, and a plugin outside will probably result in `TypeIds` mismatch.\n\n\u003e You can use\n\u003e ```rust,ignore\n\u003e println!(\"{:?}\", std::any::TypeId::of::\u003crhai::Map\u003e());\n\u003e ```\n\u003e In your binary \u0026 plugins to check the type id value.\n\nIf you have any idea of how the compiler generates those typeids between workspaces and single crates, please help us complete this readme !\n\n### Hashing\n\nRhai uses the [`ahash`](https://github.com/tkaitchuck/ahash) crate under the hood to create identifiers for function calls. For each compilation of your code, a new seed is generated when hashing the types. Therefore, compiling your main program and your plugin different times will result in a hash mismatch, meaning that you won't be able to call the API of your plugin.\n\nTo bypass that, you need to use the `rhai::config::hashing::set_hashing_seed` function with an array of four `u64`.\n\n### Others\n\nIf your plugin is still not working after you read the sections above, you could check those points too:\n\n- Use the same toolchain version for all crates.\n- Use the same rhai-dylib dependency version in all crates.\n- Try to build the crates with the same target type. (both debug or both release)\n- Enable/Disable link time optimization flag (-C lto) for all crates.\n\nIf none of those solutions works, do not hesitate to open an issue !\n\n## Rust ABI\n\nYou also can implement a plugin using the Rust ABI, which is unstable and will change between compiler versions.\n\nThis means that all of the plugins that you will use in your main program need to be compiled with the **EXACT** same\ncompiler version.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai-dylib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhaiscript%2Frhai-dylib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai-dylib/lists"}