Sha256: d7dd65ed6090a54faf0978081329e9f432952bcb1eb4137a144a3af803fdec30

Contents?: true

Size: 1.72 KB

Versions: 42

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

# Maps OS name to crt binary name.
OS_BINARIES = {
  'darwin' => 'libaws-crt-ffi.dylib',
  'linux' => 'libaws-crt-ffi.so',
  'mingw32' => 'aws-crt-ffi.dll'
}.freeze

DEFAULT_BINARY = 'libaws-crt-ffi.so'

# @return [Gem::Platform] similar to Gem::Platform.local but will return
# host os/cpu for Jruby
def local_platform
  Gem::Platform.new(host_string)
end

# @return [Gem::Platform] return Gem::Platform for host os with target cpu
def target_platform(cpu)
  Gem::Platform.new(target_string(cpu))
end

# @return [String] return the file name for the CRT library for the platform
def crt_bin_name(platform)
  OS_BINARIES[platform.os] || DEFAULT_BINARY
end

# @return [String] return the directory of the CRT library for the platform
def crt_bin_dir(platform)
  ENV['AWS_CRT_RUBY_BIN_DIR'] ||
    File.expand_path("../../bin/#{platform.cpu}",
                     File.dirname(__FILE__))
end

# @return [String] return the path to the CRT library for the platform
def crt_bin_path(platform)
  File.expand_path(crt_bin_name(platform), crt_bin_dir(platform))
end

# @return [String] generate a string that can be used with Gem::Platform
def host_string
  target_string(host_cpu)
end

# @return [String] generate a string that can be used with Gem::Platform
def target_string(cpu)
  "#{cpu}-#{host_os}"
end

# @return [String] host cpu, even on jruby
def host_cpu
  case RbConfig::CONFIG['host_cpu']
  when /86_64/
    'x86_64'
  when /86/
    'x86'
  else
    RbConfig::CONFIG['host_cpu']
  end
end

# @return [String] host os, even on jruby
def host_os
  case RbConfig::CONFIG['host_os']
  when /darwin/
    'darwin'
  when /linux/
    'linux'
  when /mingw|mswin/
    'mingw32'
  else
    RbConfig::CONFIG['host_os']
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
aws-crt-0.4.0-x86_64-linux lib/aws-crt/platforms.rb
aws-crt-0.4.0-x86_64-darwin lib/aws-crt/platforms.rb
aws-crt-0.4.0-universal-java lib/aws-crt/platforms.rb
aws-crt-0.4.0-arm64-darwin lib/aws-crt/platforms.rb
aws-crt-0.4.0-aarch64-linux lib/aws-crt/platforms.rb
aws-crt-0.4.0 lib/aws-crt/platforms.rb
aws-crt-0.3.0 lib/aws-crt/platforms.rb
aws-crt-0.3.0-x86_64-linux lib/aws-crt/platforms.rb
aws-crt-0.3.0-x86_64-darwin lib/aws-crt/platforms.rb
aws-crt-0.3.0-universal-java lib/aws-crt/platforms.rb
aws-crt-0.3.0-arm64-darwin lib/aws-crt/platforms.rb
aws-crt-0.3.0-aarch64-linux lib/aws-crt/platforms.rb
aws-crt-0.2.1-aarch64-linux lib/aws-crt/platforms.rb
aws-crt-0.2.1-arm64-darwin lib/aws-crt/platforms.rb
aws-crt-0.2.1-universal-java lib/aws-crt/platforms.rb
aws-crt-0.2.1-x86_64-darwin lib/aws-crt/platforms.rb
aws-crt-0.2.1-x86_64-linux lib/aws-crt/platforms.rb
aws-crt-0.2.1 lib/aws-crt/platforms.rb
aws-crt-0.2.0-x86_64-linux lib/aws-crt/platforms.rb
aws-crt-0.2.0-x86_64-darwin lib/aws-crt/platforms.rb