Top Level Namespace

Defined Under Namespace

Modules: OnnxRuby

Constant Summary collapse

ORT_VERSION =
"1.24.3"

Instance Method Summary collapse

Instance Method Details

#detect_platformObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'ext/onnx_ruby/extconf.rb', line 7

def detect_platform
  os = RbConfig::CONFIG["host_os"]
  cpu = RbConfig::CONFIG["host_cpu"]

  case os
  when /darwin/
    cpu =~ /arm64|aarch64/ ? "osx-arm64" : "osx-x86_64"
  when /linux/
    cpu =~ /aarch64|arm64/ ? "linux-aarch64" : "linux-x64"
  else
    abort "Unsupported OS: #{os}"
  end
end

#download_onnxruntime(dest_dir) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'ext/onnx_ruby/extconf.rb', line 21

def download_onnxruntime(dest_dir)
  platform = detect_platform
  filename = "onnxruntime-#{platform}-#{ORT_VERSION}.tgz"
  url = "https://github.com/microsoft/onnxruntime/releases/download/v#{ORT_VERSION}/#{filename}"
  tmp_file = File.join(Dir.tmpdir, filename)

  unless File.exist?(tmp_file)
    puts "Downloading ONNX Runtime v#{ORT_VERSION} for #{platform}..."
    system("curl", "-fSL", url, "-o", tmp_file) or
      abort "Failed to download ONNX Runtime from #{url}"
  end

  FileUtils.mkdir_p(dest_dir)
  puts "Extracting to #{dest_dir}..."
  system("tar", "xzf", tmp_file, "-C", dest_dir, "--strip-components=1") or
    abort "Failed to extract ONNX Runtime"

  dest_dir
end