Module: FFI::Platform
- 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 collapse
- OS =
FFI.make_shareable(case RbConfig::CONFIG['host_os'].downcase when /linux/ "linux" when /darwin/ "darwin" when /freebsd/ "freebsd" when /netbsd/ "netbsd" when /openbsd/ "openbsd" when /dragonfly/ "dragonflybsd" when /sunos|solaris/ "solaris" when /mingw|mswin/ "windows" else RbConfig::CONFIG['host_os'].downcase end)
- OSVERSION =
RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i
- CPU =
FFI.make_shareable(RbConfig::CONFIG['host_cpu'])
- ARCH =
FFI.make_shareable(case CPU.downcase when /amd64|x86_64|x64/ "x86_64" when /i\d86|x86|i86pc/ "i386" 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 RbConfig::CONFIG['host_cpu'] end)
- IS_GNU =
defined?(GNU_LIBC)
- IS_LINUX =
is_os("linux")
- IS_MAC =
is_os("darwin")
- IS_FREEBSD =
is_os("freebsd")
- IS_NETBSD =
is_os("netbsd")
- IS_OPENBSD =
is_os("openbsd")
- IS_DRAGONFLYBSD =
is_os("dragonfly")
- IS_SOLARIS =
is_os("solaris")
- IS_WINDOWS =
is_os("windows")
- IS_BSD =
IS_MAC || IS_FREEBSD || IS_NETBSD || IS_OPENBSD || IS_DRAGONFLYBSD
- NAME =
64-bit inodes
FFI.make_shareable("#{ARCH}-#{OS}#{name_version}")
- CONF_DIR =
FFI.make_shareable(File.join(File.dirname(__FILE__), 'platform', NAME))
- LIBPREFIX =
FFI.make_shareable(case OS when /windows|msys/ '' when /cygwin/ 'cyg' else 'lib' end)
- LIBSUFFIX =
FFI.make_shareable(case OS when /darwin/ 'dylib' when /linux|bsd|solaris/ 'so' when /windows|cygwin|msys/ 'dll' else # Punt and just assume a sane unix (i.e. anything but AIX) 'so' end)
- LIBC =
FFI.make_shareable(if IS_WINDOWS crtname = RbConfig::CONFIG["RUBY_SO_NAME"][/msvc\w+/] || 'ucrtbase' "#{crtname}.dll" elsif IS_GNU GNU_LIBC elsif OS == 'cygwin' "cygwin1.dll" elsif OS == 'msys' # Not sure how msys 1.0 behaves, tested on MSYS2. "msys-2.0.dll" else "#{LIBPREFIX}c.#{LIBSUFFIX}" end)
- LITTLE_ENDIAN =
INT2FIX(LITTLE_ENDIAN)
- BIG_ENDIAN =
INT2FIX(BIG_ENDIAN)
- BYTE_ORDER =
INT2FIX(BYTE_ORDER)
- GNU_LIBC =
rb_str_new2(LIBC_SO)
Class Method Summary collapse
-
.bsd? ⇒ Boolean
Test if current OS is a *BSD (include MAC).
-
.is_os(os) ⇒ Boolean
private
Test if current OS is
os
. -
.mac? ⇒ Boolean
Test if current OS is Mac OS.
-
.solaris? ⇒ Boolean
Test if current OS is Solaris (Sun OS).
-
.unix? ⇒ Boolean
Test if current OS is a unix OS.
-
.windows? ⇒ Boolean
Test if current OS is Windows.
Class Method Details
.bsd? ⇒ Boolean
Test if current OS is a *BSD (include MAC)
158 159 160 |
# File 'lib/ffi/platform.rb', line 158 def self.bsd? IS_BSD end |
.is_os(os) ⇒ Boolean (private)
Test if current OS is os
.
92 93 94 |
# File 'lib/ffi/platform.rb', line 92 def self.is_os(os) OS == os end |
.mac? ⇒ Boolean
Test if current OS is Mac OS
170 171 172 |
# File 'lib/ffi/platform.rb', line 170 def self.mac? IS_MAC end |
.solaris? ⇒ Boolean
Test if current OS is Solaris (Sun OS)
176 177 178 |
# File 'lib/ffi/platform.rb', line 176 def self.solaris? IS_SOLARIS end |
.unix? ⇒ Boolean
Test if current OS is a unix OS
182 183 184 |
# File 'lib/ffi/platform.rb', line 182 def self.unix? !IS_WINDOWS end |
.windows? ⇒ Boolean
Test if current OS is Windows
164 165 166 |
# File 'lib/ffi/platform.rb', line 164 def self.windows? IS_WINDOWS end |