Module: GRX::CAPI

Extended by:
Fiddle::Importer
Defined in:
lib/grx/c_api.rb

Constant Summary collapse

CANDIDATE_NAMES =
case RUBY_PLATFORM
when /mingw|mswin|windows/i
  ["grx_core.dll", "libgrx_core.dll", "libgrx_core.so", "grx_core.so"]
when /darwin/i
  ["libgrx_core.dylib", "grx_core.bundle", "libgrx_core.so", "grx_core.so"]
else
  ["libgrx_core.so", "grx_core.so", "libgrx_core.dylib", "grx_core.dll"]
end
SEARCH_DIRS =
[
  File.expand_path(__dir__),                     # lib/grx/
  File.expand_path("..", __dir__),              # lib/
  File.expand_path("../../ext/grx", __dir__),    # ext/grx/
  File.expand_path("../../ext/unix", __dir__),   # ext/unix/
  File.expand_path("../../ext/windows", __dir__) # ext/windows/
].freeze
LIB_PATHS =
SEARCH_DIRS.flat_map do |dir|
  CANDIDATE_NAMES.flat_map do |name|
    [
      File.join(dir, name),
      File.join(dir, name).tr("/", "\\")
    ]
  end
end.uniq.freeze
LOADED =
begin
  path = LIB_PATHS.find { |p| File.file?(p) && File.exist?(p) }
  if path
    dlload path
    true
  else
    raise Fiddle::DLError, "Binary library not found (#{CANDIDATE_NAMES.join(', ')}) in #{SEARCH_DIRS.inspect}"
  end
rescue Fiddle::DLError => e
  warn "[GRX] C extension unavailable: #{e.message}\n" \
       "      → Run: make -C ext/unix all (Linux/macOS) or make -C ext/windows -f Makefile.mingw all (Windows)\n" \
       "      → Running in pure Ruby fallback mode (without SIMD)."
  false
end