Module: Prebake::StaticRuby

Defined in:
lib/prebake/static_ruby.rb

Overview

Detection and configuration for static Ruby builds (e.g. Paketo MRI buildpack), where libruby.so is absent and native extensions dynamically linked against it would crash at load time.

Constant Summary collapse

OPTIONAL_NATIVE_EXTENSIONS_DEFAULT =

Gems whose native extensions are entirely optional — the gem runs correctly in pure Ruby mode when the extension can’t be loaded. Prebake skips the extension for these gems instead of installing a broken .so. Extend via PREBAKE_OPTIONAL_NATIVE_EXTENSIONS=gem1,gem2.

%w[bootsnap].freeze

Class Method Summary collapse

Class Method Details

.libruby_available?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/prebake/static_ruby.rb', line 26

def libruby_available?
  return @libruby_available if defined?(@libruby_available)

  libruby_so = RbConfig::CONFIG["LIBRUBY_SO"]
  @libruby_available = !libruby_so.nil? && !libruby_so.empty? &&
                       File.exist?(File.join(RbConfig::CONFIG["libdir"], libruby_so))
end

.optional_native_extension?(gem_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/prebake/static_ruby.rb', line 22

def optional_native_extension?(gem_name)
  optional_native_extensions.include?(gem_name)
end

.optional_native_extensionsObject



14
15
16
17
18
19
20
# File 'lib/prebake/static_ruby.rb', line 14

def optional_native_extensions
  @optional_native_extensions ||= begin
    extra = ENV.fetch("PREBAKE_OPTIONAL_NATIVE_EXTENSIONS", "")
               .split(",").map(&:strip).reject(&:empty?)
    (OPTIONAL_NATIVE_EXTENSIONS_DEFAULT + extra).uniq
  end
end

.reset!Object



34
35
36
37
# File 'lib/prebake/static_ruby.rb', line 34

def reset!
  remove_instance_variable(:@optional_native_extensions) if defined?(@optional_native_extensions)
  remove_instance_variable(:@libruby_available) if defined?(@libruby_available)
end