Module: AsherahFetchNative

Defined in:
ext/asherah/fetch_native.rb

Overview

Downloads the prebuilt native library for the current platform from GitHub Releases during ‘gem install` (fallback gem only — platform gems ship the binary directly and never run this).

Constant Summary collapse

REPO =
"godaddy/asherah-ffi"
MAX_ATTEMPTS =
3
RETRY_DELAY =

seconds, doubles each retry

5
ROOT_DIR =
File.expand_path("../../", __dir__)
NATIVE_DIR =
File.join(ROOT_DIR, "lib", "asherah", "native")
PLATFORM_MAP =

Map Ruby platform identifiers to our release asset names. Keys: [os, cpu] from RbConfig. Values: [asset_name, local_name].

{
  ["linux", "x86_64"]        => ["libasherah-x64.so",         "libasherah_ffi.so"],
  ["linux", "aarch64"]       => ["libasherah-arm64.so",       "libasherah_ffi.so"],
  ["linux-musl", "x86_64"]   => ["libasherah-x64-musl.so",    "libasherah_ffi.so"],
  ["linux-musl", "aarch64"]  => ["libasherah-arm64-musl.so",  "libasherah_ffi.so"],
  ["darwin", "x86_64"]       => ["libasherah-x64.dylib",      "libasherah_ffi.dylib"],
  ["darwin", "arm64"]        => ["libasherah-arm64.dylib",    "libasherah_ffi.dylib"],
  ["mingw", "x86_64"]        => ["libasherah-x64.dll",        "asherah_ffi.dll"],
  ["mingw", "aarch64"]       => ["libasherah-arm64.dll",      "asherah_ffi.dll"],
}.freeze

Class Method Summary collapse

Class Method Details

.downloadObject



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
# File 'ext/asherah/fetch_native.rb', line 32

def download
  asset_name, local_name = resolve_platform
  dest = File.join(NATIVE_DIR, local_name)

  if File.exist?(dest)
    puts "#{dest} already exists, skipping download"
    return
  end

  version = resolve_version
  url = "https://github.com/#{REPO}/releases/download/#{version}/#{asset_name}"

  puts "Downloading native library: #{url}"
  content = download_with_retry(url)

  if content.bytesize < 1024
    abort "ERROR: Downloaded file is too small (#{content.bytesize} bytes) — likely a 404 or error page"
  end

  verify_checksum(content, asset_name, version)

  FileUtils.mkdir_p(NATIVE_DIR)
  File.binwrite(dest, content)
  File.chmod(0o755, dest) unless Gem.win_platform?
  puts "Installed native library: #{dest} (#{content.bytesize} bytes)"
end