Sha256: d29b93ecd66d7a55bbdb9fd39dd9c674d07d9ac73ecd480cdf76c15389996ac7

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Bootsnap
  module CompileCache
    UNCOMPILABLE = BasicObject.new
    def UNCOMPILABLE.inspect
      "<Bootsnap::UNCOMPILABLE>"
    end

    Error = Class.new(StandardError)

    def self.setup(cache_dir:, iseq:, yaml:, json:, readonly: 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
      end
    end

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bootsnap-1.18.1 lib/bootsnap/compile_cache.rb
bootsnap-1.18.0 lib/bootsnap/compile_cache.rb
bootsnap-1.17.1 lib/bootsnap/compile_cache.rb