Skip to content

Commit 1240fec

Browse files
committed
Add TruffleRuby support and add it in CI
1 parent 806add6 commit 1240fec

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ jobs:
66
ruby-versions:
77
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
88
with:
9-
engine: cruby-jruby
109
min_version: 2.5
1110
test:
1211
needs: ruby-versions
@@ -22,6 +21,8 @@ jobs:
2221
- { os: windows-latest, ruby: jruby }
2322
- { os: macos-latest, ruby: jruby-head }
2423
- { os: windows-latest, ruby: jruby-head }
24+
- { os: windows-latest, ruby: truffleruby }
25+
- { os: windows-latest, ruby: truffleruby-head }
2526
include:
2627
- { os: windows-latest, ruby: mingw }
2728
- { os: windows-latest, ruby: mswin }

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Rake::JavaExtensionTask.new("escape") do |ext|
1111
task :build => :compile
1212
end
1313

14-
unless RUBY_ENGINE == 'jruby'
14+
if RUBY_ENGINE == 'ruby'
1515
require 'rake/extensiontask'
1616
extask = Rake::ExtensionTask.new("cgi/escape") do |x|
1717
x.lib_dir.sub!(%r[(?=/|\z)], "/#{RUBY_VERSION}/#{x.platform}")
@@ -22,7 +22,7 @@ Rake::TestTask.new(:test) do |t|
2222
t.libs << "test/lib"
2323
if RUBY_ENGINE == 'jruby'
2424
t.libs << "ext/java/org/jruby/ext/cgi/escape/lib"
25-
else
25+
elsif RUBY_ENGINE == 'ruby'
2626
t.libs << "lib/#{RUBY_VERSION}/#{extask.platform}"
2727
end
2828
t.ruby_opts << "-rhelper"

ext/cgi/escape/extconf.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
require 'mkmf'
22

3-
create_makefile 'cgi/escape'
3+
if RUBY_ENGINE == 'truffleruby'
4+
File.write("Makefile", dummy_makefile($srcdir).join(""))
5+
else
6+
create_makefile 'cgi/escape'
7+
end

lib/cgi/util.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ def escapeHTML(string)
9090
end
9191
end
9292

93-
begin
94-
require 'cgi/escape'
95-
rescue LoadError
93+
# TruffleRuby runs the pure-Ruby variant faster, do not use the C extension there
94+
unless RUBY_ENGINE == 'truffleruby'
95+
begin
96+
require 'cgi/escape'
97+
rescue LoadError
98+
end
9699
end
97100

98101
# Unescape a string that has been HTML-escaped

test/cgi/test_cgi_util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def setup
262262
remove_method :escapeHTML
263263
alias _unescapeHTML unescapeHTML
264264
remove_method :unescapeHTML
265-
end
265+
end if defined?(CGI::Escape)
266266
end
267267

268268
def teardown
@@ -271,7 +271,7 @@ def teardown
271271
remove_method :_escapeHTML
272272
alias unescapeHTML _unescapeHTML
273273
remove_method :_unescapeHTML
274-
end
274+
end if defined?(CGI::Escape)
275275
end
276276

277277
def test_cgi_escapeHTML_with_invalid_byte_sequence

0 commit comments

Comments
 (0)