Module: Valkey::Bindings

Extended by:
FFI::Library
Defined in:
lib/valkey/bindings.rb

Defined Under Namespace

Classes: AsyncClientData, BatchInfo, BatchOptionsInfo, ClientData, ClientType, CmdInfo, CommandError, CommandResponse, CommandResult, ConnectionResponse, OpenTelemetryConfig, OpenTelemetryMetricsConfig, OpenTelemetryTracesConfig, ScriptHashBuffer, Statistics

Class Method Summary collapse

Class Method Details

.musl_libc?Boolean

Detect whether the current Linux system uses musl libc (e.g., Alpine Linux). Uses a three-check cascade — any single match is sufficient.

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/valkey/bindings.rb', line 9

def self.musl_libc?
  return false unless FFI::Platform::OS == "linux"

  # Check 1: RUBY_PLATFORM contains 'musl' (e.g., Alpine-built Ruby)
  return true if RUBY_PLATFORM.include?("musl")

  # Check 2: /etc/alpine-release exists (Alpine Linux indicator)
  return true if File.exist?("/etc/alpine-release")

  # Check 3: RbConfig target_os contains 'musl'
  return true if RbConfig::CONFIG["target_os"].to_s.include?("musl")

  false
end

.platform_infoObject

Determine platform-specific library extension and directory name



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/valkey/bindings.rb', line 25

def self.platform_info
  os = if FFI::Platform.mac?
         "darwin"
       elsif FFI::Platform.windows?
         "windows"
       else
         "linux"
       end

  # Detect architecture
  arch = case RbConfig::CONFIG["host_cpu"]
         when /x86_64|amd64/i
           "x86_64"
         when /aarch64|arm64/i
           "aarch64"
         when /i[3-6]86/i
           "x86"
         else
           RbConfig::CONFIG["host_cpu"]
         end

  lib_ext = case os
            when "darwin"
              "dylib"
            when "windows"
              "dll"
            else
              "so"
            end

  # Platform directory name matches Rust target triple convention
  platform_dir = case os
                 when "darwin"
                   "#{arch}-apple-darwin"
                 when "linux"
                   musl_libc? ? "#{arch}-unknown-linux-musl" : "#{arch}-unknown-linux-gnu"
                 when "windows"
                   "#{arch}-pc-windows-msvc"
                 end

  { os: os, arch: arch, lib_ext: lib_ext, platform_dir: platform_dir }
end