Skip to content

Add TruffleRuby support by replacing Magnus with rb-sys#37

Open
ollym wants to merge 2 commits into
hardpixel:masterfrom
ollym:truffleruby
Open

Add TruffleRuby support by replacing Magnus with rb-sys#37
ollym wants to merge 2 commits into
hardpixel:masterfrom
ollym:truffleruby

Conversation

@ollym

@ollym ollym commented Jun 7, 2026

Copy link
Copy Markdown

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

ollym added 2 commits June 7, 2026 14:45
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant