123456789_123456789_123456789_123456789_123456789_

Module: FFI::Platform

Relationships & Source Files
Defined in: lib/ffi/platform.rb,
ext/ffi_c/Platform.c

Overview

This module defines different constants and class methods to play with various platforms.

Constant Summary

Class Attribute Summary

Class Method Summary

Class Attribute Details

.bsd? ⇒ Boolean (readonly)

Test if current OS is a *BSD (include MAC)

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 168

def self.bsd?
  IS_BSD
end

.mac? ⇒ Boolean (readonly)

Test if current OS is Mac OS

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 180

def self.mac?
  IS_MAC
end

.solaris? ⇒ Boolean (readonly)

Test if current OS is Solaris (Sun OS)

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 186

def self.solaris?
  IS_SOLARIS
end

.unix? ⇒ Boolean (readonly)

Test if current OS is a unix OS

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 192

def self.unix?
  !IS_WINDOWS
end

.windows? ⇒ Boolean (readonly)

Test if current OS is Windows

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 174

def self.windows?
  IS_WINDOWS
end

Class Method Details

.arch_for_cpu(cpu) ⇒ String

Extracted from the ARCH assignment below so the mapping can be exercised directly in specs without needing to run on every architecture it handles.

Parameters:

  • cpu (String) —

    +RbConfig::CONFIG+-style string to map to an ARCH value

[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 69

def self.arch_for_cpu(cpu)
  case cpu.downcase
  when /amd64|x86_64|x64/
    "x86_64"
  when /i\d86|x86|i86pc/
    "i386"
  when /ppc64le|powerpc64le/
    "powerpc64le"
  when /ppc64|powerpc64/
    "powerpc64"
  when /ppc|powerpc/
    "powerpc"
  when /sparcv9|sparc64/
    "sparcv9"
  when /arm64|aarch64/  # MacOS calls it "arm64", other operating systems "aarch64"
    "aarch64"
  when /^arm/
    if OS == "darwin"   # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
      "aarch64"
    else
      "arm"
    end
  else
    cpu
  end
end

.is_os(os) ⇒ Boolean (private)

Test if current OS is os.

Parameters:

  • os (String)
[ GitHub ]

  
# File 'lib/ffi/platform.rb', line 102

def self.is_os(os)
  OS == os
end