Module: Once::Native

Extended by:
FFI::Library
Defined in:
lib/once/native.rb

Class Method Summary collapse

Class Method Details

.library_nameObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/once/native.rb', line 47

def self.library_name
  case platform_key
  when /^darwin-/
    "libonce.dylib"
  when /^win32-/
    "once.dll"
  else
    "libonce.so"
  end
end

.library_pathObject

Raises:

  • (LoadError)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/once/native.rb', line 10

def self.library_path
  return ENV.fetch("ONCE_LIBRARY_PATH") if ENV["ONCE_LIBRARY_PATH"]

  candidate = File.expand_path(
    File.join("..", "..", "prebuilds", platform_key, library_name),
    __dir__,
  )
  return candidate if File.file?(candidate)

  raise LoadError,
        "missing native Once library for #{platform_key}; set ONCE_LIBRARY_PATH or install a gem that includes this platform"
end

.platform_keyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/once/native.rb', line 23

def self.platform_key
  host = RbConfig::CONFIG.fetch("host_os")
  arch = RbConfig::CONFIG.fetch("host_cpu")
  os = case host
       when /darwin/
         "darwin"
       when /mswin|mingw|cygwin/
         "win32"
       when /linux/
         "linux"
       else
         host
       end
  cpu = case arch
        when /arm64|aarch64/
          "arm64"
        when /x86_64|amd64/
          "x64"
        else
          arch
        end
  "#{os}-#{cpu}"
end