Module: Bootsnap::CompileCache

Defined in:
lib/bootsnap/compile_cache.rb,
lib/bootsnap/compile_cache/iseq.rb,
lib/bootsnap/compile_cache/json.rb,
lib/bootsnap/compile_cache/yaml.rb,
ext/bootsnap/bootsnap.c

Defined Under Namespace

Modules: ISeq, JSON, Native, YAML

Constant Summary collapse

UNCOMPILABLE =
BasicObject.new
Error =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.setup(cache_dir:, iseq:, yaml:, json:, readonly: false, revalidation: false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bootsnap/compile_cache.rb', line 12

def self.setup(cache_dir:, iseq:, yaml:, json:, readonly: false, revalidation: false)
  if iseq
    if supported?
      require_relative "compile_cache/iseq"
      Bootsnap::CompileCache::ISeq.install!(cache_dir)
    elsif $VERBOSE
      warn("[bootsnap/setup] bytecode caching is not supported on this implementation of Ruby")
    end
  end

  if yaml
    if supported?
      require_relative "compile_cache/yaml"
      Bootsnap::CompileCache::YAML.install!(cache_dir)
    elsif $VERBOSE
      warn("[bootsnap/setup] YAML parsing caching is not supported on this implementation of Ruby")
    end
  end

  if json
    if supported?
      require_relative "compile_cache/json"
      Bootsnap::CompileCache::JSON.install!(cache_dir)
    elsif $VERBOSE
      warn("[bootsnap/setup] JSON parsing caching is not supported on this implementation of Ruby")
    end
  end

  if supported? && defined?(Bootsnap::CompileCache::Native)
    Bootsnap::CompileCache::Native.readonly = readonly
    Bootsnap::CompileCache::Native.revalidation = revalidation
  end
end

.supported?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/bootsnap/compile_cache.rb', line 46

def self.supported?
  # only enable on 'ruby' (MRI) and TruffleRuby for POSIX (darwin, linux, *bsd), Windows (RubyInstaller2)
  %w[ruby truffleruby].include?(RUBY_ENGINE) &&
    RUBY_PLATFORM.match?(/darwin|linux|bsd|mswin|mingw|cygwin/)
end