Module: SurrealDB::Native::Platform

Defined in:
lib/surrealdb/native/platform.rb

Overview

Resolves the platform-specific path to the libsurrealdb_c shared library.

Class Method Summary collapse

Class Method Details

.host_cpuSymbol

Returns :x86_64 or :aarch64.

Returns:

  • (Symbol)

    :x86_64 or :aarch64



42
43
44
45
46
47
48
# File 'lib/surrealdb/native/platform.rb', line 42

def host_cpu
  case RbConfig::CONFIG['host_cpu']
  when /x86_64|amd64/i then :x86_64
  when /aarch64|arm64/i then :aarch64
  else RbConfig::CONFIG['host_cpu'].to_sym
  end
end

.host_osSymbol

Returns :linux, :macos, or :windows.

Returns:

  • (Symbol)

    :linux, :macos, or :windows



33
34
35
36
37
38
39
# File 'lib/surrealdb/native/platform.rb', line 33

def host_os
  case RbConfig::CONFIG['host_os']
  when /darwin/i then :macos
  when /mingw|mswin|cygwin/i then :windows
  else :linux
  end
end

.library_extensionString

Returns shared library file extension for the current OS.

Returns:

  • (String)

    shared library file extension for the current OS



16
17
18
19
20
21
22
# File 'lib/surrealdb/native/platform.rb', line 16

def library_extension
  case host_os
  when :macos   then 'dylib'
  when :windows then 'dll'
  else 'so'
  end
end

.library_nameString

Returns expected library filename.

Returns:

  • (String)

    expected library filename



25
26
27
28
29
30
# File 'lib/surrealdb/native/platform.rb', line 25

def library_name
  case host_os
  when :windows then 'surrealdb_c.dll'
  else "libsurrealdb_c.#{library_extension}"
  end
end

.library_pathString

Returns absolute path or library name for FFI.ffi_lib.

Returns:

  • (String)

    absolute path or library name for FFI.ffi_lib

Raises:

  • (LoadError)

    if the library cannot be found



11
12
13
# File 'lib/surrealdb/native/platform.rb', line 11

def library_path
  from_env || from_system
end