Skip to content

Commit 640c126

Browse files
authored
Merge pull request #447 from Shopify/rwstauner/enable-yaml
Enable YAML and JSON CompileCache on TruffleRuby and run the full test suite
2 parents cd15951 + acffd63 commit 640c126

23 files changed

+100
-13
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
fail-fast: false
4444
matrix:
4545
os: [ubuntu]
46-
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', 'ruby-head', 'debug']
46+
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', 'ruby-head', 'debug', 'truffleruby']
4747
runs-on: ${{ matrix.os }}-latest
4848
steps:
4949
- uses: actions/checkout@v2
@@ -75,7 +75,7 @@ jobs:
7575
fail-fast: false
7676
matrix:
7777
os: [ubuntu]
78-
ruby: ['jruby', 'truffleruby']
78+
ruby: ['jruby']
7979
runs-on: ${{ matrix.os }}-latest
8080
steps:
8181
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
* Support YAML and JSON CompileCache on TruffleRuby.
4+
35
# 1.16.0
46

57
* Use `RbConfig::CONFIG["rubylibdir"]` instead of `RbConfig::CONFIG["libdir"]` to check for stdlib files. See #431.

ext/bootsnap/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require("mkmf")
44

5-
if RUBY_ENGINE == "ruby"
5+
if %w[ruby truffleruby].include?(RUBY_ENGINE)
66
$CFLAGS << " -O3 "
77
$CFLAGS << " -std=c99"
88

lib/bootsnap/compile_cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.permission_error(path)
5454

5555
def self.supported?
5656
# only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), Windows (RubyInstaller2) and >= 2.3.0
57-
RUBY_ENGINE == "ruby" && RUBY_PLATFORM.match?(/darwin|linux|bsd|mswin|mingw|cygwin/)
57+
%w[ruby truffleruby].include?(RUBY_ENGINE) && RUBY_PLATFORM.match?(/darwin|linux|bsd|mswin|mingw|cygwin/)
5858
end
5959
end
6060
end

lib/bootsnap/compile_cache/iseq.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class << self
1212
def cache_dir=(cache_dir)
1313
@cache_dir = cache_dir.end_with?("/") ? "#{cache_dir}iseq" : "#{cache_dir}-iseq"
1414
end
15+
16+
def supported?
17+
CompileCache.supported? && defined?(RubyVM)
18+
end
1519
end
1620

1721
has_ruby_bug_18250 = begin # https://bugs.ruby-lang.org/issues/18250
@@ -103,11 +107,15 @@ def self.compile_option_updated
103107
crc = Zlib.crc32(option.inspect)
104108
Bootsnap::CompileCache::Native.compile_option_crc32 = crc
105109
end
106-
compile_option_updated
110+
compile_option_updated if supported?
107111

108112
def self.install!(cache_dir)
109113
Bootsnap::CompileCache::ISeq.cache_dir = cache_dir
114+
115+
return unless supported?
116+
110117
Bootsnap::CompileCache::ISeq.compile_option_updated
118+
111119
class << RubyVM::InstructionSequence
112120
prepend(InstructionSequenceMixin)
113121
end

lib/bootsnap/load_path_cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def unload!
5050
@loaded_features_index = nil
5151
@realpath_cache = nil
5252
@load_path_cache = nil
53-
ChangeObserver.unregister($LOAD_PATH)
53+
ChangeObserver.unregister($LOAD_PATH) if supported?
5454
end
5555

5656
def supported?

test/cli_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,35 @@ def setup
1313
end
1414

1515
def test_precompile_single_file
16+
skip_unless_iseq
1617
path = Help.set_file("a.rb", "a = a = 3", 100)
1718
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path))
1819
assert_equal 0, CLI.new(["precompile", "-j", "0", path]).run
1920
end
2021

2122
def test_precompile_rake_files
23+
skip_unless_iseq
2224
path = Help.set_file("a.rake", "a = a = 3", 100)
2325
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path))
2426
assert_equal 0, CLI.new(["precompile", "-j", "0", path]).run
2527
end
2628

2729
def test_precompile_rakefile
30+
skip_unless_iseq
2831
path = Help.set_file("Rakefile", "a = a = 3", 100)
2932
CompileCache::ISeq.expects(:precompile).with(File.expand_path(path))
3033
assert_equal 0, CLI.new(["precompile", "-j", "0", path]).run
3134
end
3235

3336
def test_no_iseq
37+
skip_unless_iseq
3438
path = Help.set_file("a.rb", "a = a = 3", 100)
3539
CompileCache::ISeq.expects(:precompile).never
3640
assert_equal 0, CLI.new(["precompile", "-j", "0", "--no-iseq", path]).run
3741
end
3842

3943
def test_precompile_directory
44+
skip_unless_iseq
4045
path_a = Help.set_file("foo/a.rb", "a = a = 3", 100)
4146
path_b = Help.set_file("foo/b.rb", "b = b = 3", 100)
4247

@@ -46,6 +51,7 @@ def test_precompile_directory
4651
end
4752

4853
def test_precompile_exclude
54+
skip_unless_iseq
4955
path_a = Help.set_file("foo/a.rb", "a = a = 3", 100)
5056
Help.set_file("foo/b.rb", "b = b = 3", 100)
5157

@@ -68,5 +74,11 @@ def test_no_yaml
6874
CompileCache::YAML.expects(:precompile).never
6975
assert_equal 0, CLI.new(["precompile", "-j", "0", "--no-yaml", path]).run
7076
end
77+
78+
private
79+
80+
def skip_unless_iseq
81+
skip("Unsupported platform") unless defined?(CompileCache::ISeq) && CompileCache::ISeq.supported?
82+
end
7183
end
7284
end

test/compile_cache/iseq_cache_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require("test_helper")
44

55
class CompileCacheISeqTest < Minitest::Test
6+
include(CompileCacheISeqHelper)
67
include(TmpdirHelper)
78

89
def test_ruby_bug_18250

test/compile_cache/json_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def load_file(_path, symbolize_names: false, freeze: false, fallback: nil)
1515
end
1616

1717
def setup
18+
skip("Unsupported platform") unless Bootsnap::CompileCache.supported?
1819
super
1920
Bootsnap::CompileCache::JSON.init!
2021
FakeJson.singleton_class.prepend(Bootsnap::CompileCache::JSON::Patch)

test/compile_cache/yaml_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def unsafe_load_file(_path, symbolize_names: false, freeze: false, fallback: nil
1919
end
2020

2121
def setup
22+
skip("Unsupported platform") unless Bootsnap::CompileCache.supported?
2223
super
2324
Bootsnap::CompileCache::YAML.init!
2425
FakeYaml.singleton_class.prepend(Bootsnap::CompileCache::YAML.patch)

0 commit comments

Comments
 (0)