Sha256: 3a4d48c490e4cb8304af3ed9c3afd867ee0eb7bb27b4756e4315177cd416d81c

Contents?: true

Size: 994 Bytes

Versions: 4

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

require 'rbconfig'

# Utility to load native binaries on Java CLASSPATH
# HACK until jruby returns a more specific 'host_os' than 'linux'
class NativeFolder
  attr_reader :os, :bit

  LINUX_FORMAT = 'linux%<bit>d'
  # ARM64 = '-aarch64'
  WIN_FORMAT = 'windows%<bit>d'
  WIN_PATTERNS = [
    /bccwin/i,
    /cygwin/i,
    /djgpp/i,
    /ming/i,
    /mswin/i,
    /wince/i
  ].freeze

  def initialize
    @os = RbConfig::CONFIG['host_os'].downcase
    @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
  end

  def name
    return macos if /darwin|mac/.match?(os)

    return format(LINUX_FORMAT, bit: bit) if /linux/.match?(os)

    unless WIN_PATTERNS.any? { |pat| pat.match?(os) }
      raise StandardError, 'Unsupported Architecture'
    end

    format(WIN_FORMAT, bit: bit)
  end

  def extension
    return '*.so' if /linux/.match?(os)

    return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }

    '*.dylib' # MacOS
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jruby_art-2.6.1 lib/jruby_art/native_folder.rb
jruby_art-2.6.0 lib/jruby_art/native_folder.rb
jruby_art-2.5.1 lib/jruby_art/native_folder.rb
jruby_art-2.5.0 lib/jruby_art/native_folder.rb