Skip to content

Commit

Permalink
Add TruffleRuby support and add it in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed May 29, 2023
1 parent 806add6 commit 4830cf5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ jobs:
ruby-versions:
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
with:
engine: cruby-jruby
min_version: 2.5
test:
needs: ruby-versions
Expand All @@ -22,6 +21,8 @@ jobs:
- { os: windows-latest, ruby: jruby }
- { os: macos-latest, ruby: jruby-head }
- { os: windows-latest, ruby: jruby-head }
- { os: windows-latest, ruby: truffleruby }
- { os: windows-latest, ruby: truffleruby-head }
include:
- { os: windows-latest, ruby: mingw }
- { os: windows-latest, ruby: mswin }
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Rake::JavaExtensionTask.new("escape") do |ext|
task :build => :compile
end

unless RUBY_ENGINE == 'jruby'
if RUBY_ENGINE == 'ruby'
require 'rake/extensiontask'
extask = Rake::ExtensionTask.new("cgi/escape") do |x|
x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}")
Expand All @@ -22,7 +22,7 @@ Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
if RUBY_ENGINE == 'jruby'
t.libs << "ext/java/org/jruby/ext/cgi/escape/lib"
else
elsif RUBY_ENGINE == 'ruby'
t.libs << "lib/#{RUBY_VERSION}/#{extask.platform}"
end
t.ruby_opts << "-rhelper"
Expand Down
6 changes: 5 additions & 1 deletion ext/cgi/escape/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require 'mkmf'

create_makefile 'cgi/escape'
if RUBY_ENGINE == 'truffleruby'
File.write("Makefile", dummy_makefile($srcdir).join(""))
else
create_makefile 'cgi/escape'
end
9 changes: 6 additions & 3 deletions lib/cgi/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ def escapeHTML(string)
end
end

begin
require 'cgi/escape'
rescue LoadError
# TruffleRuby runs the pure-Ruby variant faster, do not use the C extension there
unless RUBY_ENGINE == 'truffleruby'
begin
require 'cgi/escape'
rescue LoadError
end
end

# Unescape a string that has been HTML-escaped
Expand Down
4 changes: 2 additions & 2 deletions test/cgi/test_cgi_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def setup
remove_method :escapeHTML
alias _unescapeHTML unescapeHTML
remove_method :unescapeHTML
end
end if defined?(CGI::Escape)
end

def teardown
Expand All @@ -271,7 +271,7 @@ def teardown
remove_method :_escapeHTML
alias unescapeHTML _unescapeHTML
remove_method :_unescapeHTML
end
end if defined?(CGI::Escape)
end

def test_cgi_escapeHTML_with_invalid_byte_sequence
Expand Down

0 comments on commit 4830cf5

Please sign in to comment.