-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
106 lines (84 loc) · 3.31 KB
/
Rakefile
1
2
3
4
5
6
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require "bundler/gem_tasks"
require "rake/testtask"
task default: :test
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
end
shared_libraries = %w(libonnxruntime.so libonnxruntime.arm64.so libonnxruntime.dylib libonnxruntime.arm64.dylib onnxruntime.dll)
# ensure vendor files exist
task :ensure_vendor do
shared_libraries.each do |file|
raise "Missing file: #{file}" unless File.exist?("vendor/#{file}")
end
end
Rake::Task["build"].enhance [:ensure_vendor]
platforms = ["x86_64-linux", "aarch64-linux", "x86_64-darwin", "arm64-darwin", "x64-mingw"]
task :build_platform do
require "fileutils"
platforms.each do |platform|
sh "gem", "build", "--platform", platform
end
FileUtils.mkdir_p("pkg")
Dir["*.gem"].each do |file|
FileUtils.move(file, "pkg")
end
end
task :release_platform do
require_relative "lib/onnxruntime/version"
Dir["pkg/onnxruntime-#{OnnxRuntime::VERSION}-*.gem"].each do |file|
sh "gem", "push", file
end
end
def version
"1.19.2"
end
def download_official(library, remote_lib, file, sha256)
require "fileutils"
require "open-uri"
require "tmpdir"
url = "https://github.com/microsoft/onnxruntime/releases/download/v#{version}/#{file}"
puts "Downloading #{file}..."
contents = URI.parse(url).read
computed_sha256 = Digest::SHA256.hexdigest(contents)
raise "Bad hash: #{computed_sha256}" if computed_sha256 != sha256
Dir.chdir(Dir.mktmpdir) do
File.binwrite(file, contents)
command = file.end_with?(".zip") ? "unzip -q" : "tar xf"
system "#{command} #{file}"
src = file[0..-5]
dest = File.expand_path("vendor", __dir__)
FileUtils.cp("#{src}/lib/#{remote_lib}", "#{dest}/#{library}")
puts "Saved vendor/#{library}"
if library.end_with?(".so")
FileUtils.cp("#{src}/LICENSE", "#{dest}/LICENSE")
puts "Saved vendor/LICENSE"
FileUtils.cp("#{src}/ThirdPartyNotices.txt", "#{dest}/ThirdPartyNotices.txt")
puts "Saved vendor/ThirdPartyNotices.txt"
end
end
end
# https://github.com/microsoft/onnxruntime/releases
namespace :vendor do
task :linux do
download_official("libonnxruntime.so", "libonnxruntime.so.#{version}", "onnxruntime-linux-x64-#{version}.tgz", "eb00c64e0041f719913c4080e0fed7d9963dc3aa9b54664df6036d8308dbcd33")
download_official("libonnxruntime.arm64.so", "libonnxruntime.so.#{version}", "onnxruntime-linux-aarch64-#{version}.tgz", "5e30145277d6d6fcb0e8f14f0d0ab5048af7b13ffd608023bb1e2875621fab07")
end
task :mac do
download_official("libonnxruntime.dylib", "libonnxruntime.#{version}.dylib", "onnxruntime-osx-x86_64-#{version}.tgz", "6536e36d7ea92e32d53dad7ddd0fdf10be5b62d1dace85a13e1295ff81e9b5d4")
download_official("libonnxruntime.arm64.dylib", "libonnxruntime.#{version}.dylib", "onnxruntime-osx-arm64-#{version}.tgz", "370c49770e2e1f243e17c7b227bb7f4b3da793b847d02f38016dc0e46c30fbe1")
end
task :windows do
download_official("onnxruntime.dll", "onnxruntime.dll", "onnxruntime-win-x64-#{version}.zip", "dc4f841e511977c0a4f02e5066c3d9a58427644010ab4f89b918614a1cd4c2b0")
end
task all: [:linux, :mac, :windows]
task :platform do
if Gem.win_platform?
Rake::Task["vendor:windows"].invoke
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
Rake::Task["vendor:mac"].invoke
else
Rake::Task["vendor:linux"].invoke
end
end
end