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. Intentionally empty: bootsnap 1.18+ requires its native extension unconditionally; skipping the build produces a broken install.

%w[].freeze

Class Method Summary collapse

Class Method Details

.libruby_available?Boolean

Returns:

  • (Boolean)


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

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)


24
25
26
# File 'lib/prebake/static_ruby.rb', line 24

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

.optional_native_extensionsObject



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

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



36
37
38
39
# File 'lib/prebake/static_ruby.rb', line 36

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