matsadler / magnus

Ruby bindings for Rust. Write Ruby extension gems in Rust, or call Ruby from Rust.
https://docs.rs/magnus/latest/magnus/
MIT License
617 stars 31 forks source link

How well does the embed feature work? #89

Closed Speak2Erase closed 5 months ago

Speak2Erase commented 10 months ago

There's a project called mkxp that is a open source implementation of RGSS. (the engine used by early RPG Maker) RGSS embeds Ruby, so mkxp needs to do the same. This has historically been a sore spot in mkxp, with Ruby often causing crashes, segfaults, and other weird behavior because it's been embedded. Generally people compile a custom build of Ruby to ensure everything works, and even then, it's still pretty messy.

Does Magnus behave the same way? Is there anything I need to be concerned about?

matsadler commented 10 months ago

Magnus is just (an attempt at) a nice-to-use Rust layer on top of Ruby's C API. In a lot of cases this makes it much harder to make mistakes, but it's fundamentally the same Ruby C API under the hood, so embedding Ruby via Magnus will work about as well as embedding it via the Ruby C API.

But, all the tests (mostly doctests) in Magnus are run via the embed feature, so everything exposed in Magnus will work when embedded.

Embedding and statically linking Ruby with Magnus is something that technically works, but I've put basically no time into and seems fairly broken if you try to use it. I get the impression that you'd find Ruby's C API itself is in pretty much the same state with static linking.