Open ball-hayden opened 3 years ago
I'm not aware of any issues in doing it that way as long as require
will call it. As long as it is initialized I believe that's all it needs.
Just saw that this; might be related to #151 @ball-hayden did you encounter any issues with MRI crashes in the context of Spring reloading?
@milgner this definitely looks related.
After making the changes above (and dropping Rutie#init
calls) we've been able to use Rutie with Spring.
We didn't have any further issues - we've been running quite happily in production since mid-April 2021.
@ball-hayden I just gave it a try and it seems to have resolved the problem, too! Many thanks, really great tip! I just had to require_relative
the .so
file and everything worked as expected.
Thank you for the project, and apologies for the Q&A/Discussion issue. Rutie's really interesting, and has helped myself and @saty9 get a Ruby/Rust integration going pretty quickly.
An issue we've come across is that Rails becomes very upset when loading a gem that has a call out to
Rutie#init
(specifically, we get Bus Errors). I suspect the issue is with Spring's forking, but it could also be an issue with Zeitwerk, or some of Rails' other loading "magic".This has led us to investigate a bit further about Ruby's initialisation of native extensions. What we've found is that Ruby will call an initialisation function when
require
ing a shared library, removing the need forRutie#init
[source].For example, we can adapt the example in https://github.com/danielpclark/rutie/tree/master/examples/rutie_ruby_example slightly and get the correct behaviour:
This seems to play more nicely with Rails. My question is: is this safe, or are we missing something?
I'm happy to open a PR if it is safe and you'd like to adopt this pattern.