-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
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.21.0"
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", "7485c7e7aac6501b27e353dcbe068e45c61ab51fbaf598d13970dfae669d20bf")
download_official("libonnxruntime.arm64.so", "libonnxruntime.so.#{version}", "onnxruntime-linux-aarch64-#{version}.tgz", "4508084bde1232ee1ab4b6fad2155be0ea2ccab1c1aae9910ddb3fb68a60805e")
end
task :mac do
download_official("libonnxruntime.dylib", "libonnxruntime.#{version}.dylib", "onnxruntime-osx-x86_64-#{version}.tgz", "8305afd2d75ee5702844a23b099d41885af30ad3d1b4cf3d8d795e3d8c1f9396")
download_official("libonnxruntime.arm64.dylib", "libonnxruntime.#{version}.dylib", "onnxruntime-osx-arm64-#{version}.tgz", "5c3f2064ee97eb7774e87f396735c8eada7287734f1bb7847467ad30d4036115")
end
task :windows do
download_official("onnxruntime.dll", "onnxruntime.dll", "onnxruntime-win-x64-#{version}.zip", "5c07bb2805cd666dda75fa9bfa60e75f2f90d478b952298dd9d55c00740d81bf")
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