Sha256: 67dbd28b57e664a19fa59d05073cc0a1f0943be92083248678053d7fcb696dc5

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

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%s'.freeze
  ARM32 = '-armv6hf'.freeze
  # ARM64 = '-aarch64'.freeze
  WIN_FORMAT = 'windows%d'.freeze
  WIN_PATTERNS = [
    /bccwin/i,
    /cygwin/i,
    /djgpp/i,
    /ming/i,
    /mswin/i,
    /wince/i
  ].freeze

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

  def name
    return 'macosx' if /darwin|mac/.match?(os)
    if /linux/.match?(os)
      return format(LINUX_FORMAT, '64') if /amd64/.match?(bit)
      return format(LINUX_FORMAT, ARM32) if /arm/.match?(bit)
    end
    if WIN_PATTERNS.any? { |pat| pat =~ os }
      return format(WINDOWS_FORMAT, '64') if /64/.match?(bit)
      return format(WINDOWS_FORMAT, '32') if /32/.match?(bit)
    end
    raise 'Unsupported Architecture'
  end

  def extension
    return '*.so' if /linux/.match?(os)
    return '*.dll' if WIN_PATTERNS.any? { |pat| pat =~ os }
    '*.dylib' # MacOS
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
jruby_art-2.2.1 lib/jruby_art/native_folder.rb
jruby_art-2.2.0 lib/jruby_art/native_folder.rb
jruby_art-1.7.0 lib/jruby_art/native_folder.rb
jruby_art-2.1.0.pre lib/jruby_art/native_folder.rb
jruby_art-2.0.0.pre lib/jruby_art/native_folder.rb
jruby_art-1.6.4 lib/jruby_art/native_folder.rb
jruby_art-1.6.3 lib/jruby_art/native_folder.rb
jruby_art-1.6.2 lib/jruby_art/native_folder.rb
jruby_art-1.6.1 lib/jruby_art/native_folder.rb
jruby_art-1.6.0 lib/jruby_art/native_folder.rb
jruby_art-1.5.2 lib/jruby_art/native_folder.rb