Module: TBClient::SharedLib

Defined in:
lib/tb_client/shared_lib.rb

Constant Summary collapse

NATIVE_DIR =
File.expand_path('native', __dir__).freeze
PKG_DIR =
File.expand_path('../../ext/tb_client/pkg', __dir__).freeze

Class Method Summary collapse

Class Method Details

.pathObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tb_client/shared_lib.rb', line 7

def path
  prefix = ''
  linux_libc = ''
  suffix = ''

  arch, os = RUBY_PLATFORM.split('-')

  arch =
    case arch
    when 'x86_64', 'amd64' then 'x86_64'
    when 'aarch64', 'arm64' then 'aarch64'
    else
      raise "Unsupported architecture: #{arch}"
    end

  case os
  when /darwin/
    prefix = 'lib'
    system = 'macos'
    suffix = '.dylib'
  when 'linux'
    prefix = 'lib'
    system = 'linux'
    linux_libc = detect_libc
    suffix = '.so'
  when 'windows'
    system = 'windows'
    suffix = '.dll'
  else
    raise "Unsupported system: #{os}"
  end

  target_dir = "#{arch}-#{system}#{linux_libc}"
  filename = "#{prefix}tb_client#{suffix}"

  native_path = File.join(NATIVE_DIR, target_dir, filename)
  return native_path if File.exist?(native_path)

  pkg_path = File.join(PKG_DIR, target_dir, filename)
  return pkg_path if File.exist?(pkg_path)

  raise "tb_client library not found. Searched:\n  #{native_path}\n  #{pkg_path}"
end