Add TruffleRuby support by replacing Magnus with rb-sys#37
Open
ollym wants to merge 2 commits into
Open
Conversation
This refactors the native Rust extension to use direct rb-sys bindings instead of Magnus, allowing the gem to compile and run on TruffleRuby while preserving MRI support. Magnus depends on CRuby internals that are not available on TruffleRuby, so the native boundary now uses public Ruby C-API-compatible rb-sys calls only. Changes - Replace magnus with rb-sys in the native extension. - Implement MRML::Template wrapping with Ruby typed data. - Add explicit Ruby callback error handling to avoid raising across Rust stack frames. - Use zero-copy string reads for Ruby input strings. - Return UTF-8 tagged Ruby strings from native output. - Implement clone / dup using Rust-side AST cloning instead of serialize-and-reparse. - Add TruffleRuby to the GitHub Actions Ruby matrix. - Add tests for TruffleRuby-relevant type handling, invalid UTF-8 input, UTF-8 output encoding, and clone behavior. - Document TruffleRuby source-install support. Verification Tested successfully on both engines: RBENV_VERSION=truffleruby-34.0.1 bundle exec rake clobber compile test RBENV_VERSION=3.4.9 bundle exec rake clobber compile test Both passed with: 14 runs, 28 assertions, 0 failures, 0 errors, 0 skips
Fixes a compatibility regression where string-like Ruby objects, including ActionView::OutputBuffer, were rejected by the native extension after switching to strict String type checks. This updates the rb-sys input bridge to use Ruby’s to_str coercion path via rb_check_string_type, wrapped in rb_protect so Ruby exceptions are still handled safely at the FFI boundary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactors the native Rust extension to use direct rb-sys bindings instead of Magnus, allowing the gem to compile and run on TruffleRuby while preserving MRI support.
Magnus depends on CRuby internals that are not available on TruffleRuby, so the native boundary now uses public Ruby C-API-compatible rb-sys calls only.
Changes
Verification
Tested successfully on both engines:
RBENV_VERSION=truffleruby-34.0.1 bundle exec rake clobber compile test RBENV_VERSION=3.4.9 bundle exec rake clobber compile test
Both passed with:
14 runs, 28 assertions, 0 failures, 0 errors, 0 skips