Debian Codegraph @

vendor/download.rb

raw
1 #!/usr/bin/env ruby
2
3 require "fileutils"
4 require "open-uri"
5 require "openssl"
6
7 @debug = (ENV["DEBUG"] == "true" or ARGV.include?("--debug"))
8
9 def download(url, output_path=nil)
10 ssl_verify_mode = nil
11 if /mingw/ =~ RUBY_PLATFORM
12 ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
13 end
14
15 output_path ||= File.basename(url)
16 URI(url).open(:ssl_verify_mode => ssl_verify_mode) do |input|
17 File.open(output_path, "wb") do |output|
18 IO.copy_stream(input, output)
19 end
20 end
21
22 if block_given?
23 base_dir = output_path.sub(/\.tar\..*\z/, "")
24 FileUtils.rm_rf(base_dir)
25 system("tar", "xf", output_path)
26 Dir.chdir(base_dir) do
27 yield
28 end
29 system("tar", "czf", output_path, base_dir)
30 FileUtils.rm_rf(base_dir)
31 end
32 end
33
34 def git_clone_archive(url, tag, archive_path)
35 clone_dir = File.basename(archive_path, ".tar.gz")
36 FileUtils.rm_rf(clone_dir)
37 system("git", "clone", url, "--branch", tag, "--recursive", clone_dir)
38 # Use `tar` instead of `git archive` to include submodules.
39 system("tar", "--exclude-vcs", "--exclude-vcs-ignores",
40 "-czf", archive_path, clone_dir)
41 FileUtils.rm_rf(clone_dir)
42 end
43
44 all_targets = [
45 "base64",
46 "blosc",
47 "croaring",
48 "faiss",
49 "h3",
50 "jsoncons",
51 "llama.cpp",
52 "message-pack",
53 "openzl",
54 "simdjson",
55 "simsimd",
56 "usearch",
57 "xsimd",
58 "zstd",
59 ]
60
61 if ARGV.empty?
62 targets = all_targets
63 else
64 targets = ARGV
65 end
66
67 cmakelists = File.read(File.join(__dir__, "..", "CMakeLists.txt"))
68 targets.each do |target|
69 case target
70 when "base64"
71 version = cmakelists[/set\(GRN_BASE64_BUNDLED_VERSION \"(.+)"\)/, 1]
72 url = "https://github.com/aklomp/base64/archive/refs/tags/"
73 url << "v#{version}.tar.gz"
74 download(url, "base64-#{version}.tar.gz")
75 when "blosc"
76 version = cmakelists[/set\(GRN_BLOSC_BUNDLED_VERSION \"(.+)"\)/, 1]
77 url = "https://github.com/Blosc/c-blosc2/archive/refs/tags/"
78 url << "v#{version}.tar.gz"
79 download(url, "c-blosc2-#{version}.tar.gz")
80 when "croaring"
81 version = cmakelists[/set\(GRN_CROARING_EP_VERSION \"(.+)"\)/, 1]
82 url = "https://github.com/RoaringBitmap/CRoaring/archive/refs/tags/"
83 url << "v#{version}.tar.gz"
84 download(url, "CRoaring-#{version}.tar.gz") do
85 FileUtils.rm_rf("benchmarks/realdata/")
86 end
87 when "faiss"
88 version = cmakelists[/set\(GRN_FAISS_BUNDLED_VERSION \"(.+)"\)/, 1]
89 url = "https://github.com/facebookresearch/faiss/archive/refs/tags/"
90 url << "v#{version}.tar.gz"
91 download(url, "faiss-#{version}.tar.gz")
92 when "h3"
93 version = cmakelists[/set\(GRN_H3_BUNDLED_VERSION \"(.+)"\)/, 1]
94 url = "https://github.com/uber/h3/archive/refs/tags/"
95 url << "v#{version}.tar.gz"
96 download(url, "h3-#{version}.tar.gz")
97 when "jsoncons"
98 version = cmakelists[/set\(GRN_JSONCONS_BUNDLED_VERSION \"(.+)"\)/, 1]
99 url = "https://github.com/danielaparker/jsoncons/archive/refs/tags/"
100 url << "v#{version}.tar.gz"
101 download(url, "jsoncons-#{version}.tar.gz")
102 when "llama.cpp"
103 version = cmakelists[/set\(GRN_LLAMA_CPP_BUNDLED_VERSION \"(.+)"\)/, 1]
104 url = "https://github.com/ggerganov/llama.cpp/archive/refs/tags/"
105 url << "#{version}.tar.gz"
106 download(url, "llama.cpp-#{version}.tar.gz")
107 when "message-pack"
108 version = cmakelists[/set\(GRN_MESSAGE_PACK_BUNDLED_VERSION \"(.+)"\)/, 1]
109 url = "https://github.com/msgpack/msgpack-c/releases/download/"
110 url << "c-#{version}/"
111 url << "msgpack-c-#{version}.tar.gz"
112 download(url, "msgpack-c-#{version}.tar.gz")
113 when "openzl"
114 version = cmakelists[/set\(GRN_OPENZL_BUNDLED_VERSION \"(.+)"\)/, 1]
115 url = "https://github.com/facebook/openzl/archive/refs/tags/"
116 url << "v#{version}.tar.gz"
117 download(url, "openzl-#{version}.tar.gz") do
118 # TODO: Remove this when OpenZL supports system zstd
119 # https://github.com/facebook/openzl/issues/105
120 openzl_deps = File.read("build/cmake/openzl-deps.cmake")
121 zstd_version = openzl_deps[/set\(ZSTD_VERSION "(.+)"\)/, 1]
122 zstd_url = "https://github.com/facebook/zstd/releases/download/"
123 zstd_url << "v#{zstd_version}/zstd-#{zstd_version}.tar.gz"
124 download(zstd_url, "zstd-#{zstd_version}.tar.gz")
125 FileUtils.mkdir_p("deps/zstd")
126 system("tar", "xf", "zstd-#{zstd_version}.tar.gz", "-C", "deps/zstd",
127 "--strip-components=1")
128 FileUtils.rm("zstd-#{zstd_version}.tar.gz")
129 end
130 when "simdjson"
131 version = cmakelists[/set\(GRN_SIMDJSON_BUNDLED_VERSION \"(.+)"\)/, 1]
132 url = "https://github.com/simdjson/simdjson/archive/refs/tags/"
133 url << "v#{version}.tar.gz"
134 download(url, "simdjson-#{version}.tar.gz")
135 when "simsimd"
136 version = cmakelists[/set\(GRN_SIMSIMD_BUNDLED_VERSION \"(.+)"\)/, 1]
137 url = "https://github.com/ashvardanian/SimSIMD/archive/refs/tags/"
138 url << "v#{version}.tar.gz"
139 download(url, "simsimd-#{version}.tar.gz")
140 when "usearch"
141 version = cmakelists[/set\(GRN_USEARCH_BUNDLED_VERSION \"(.+)"\)/, 1]
142 url = "https://github.com/unum-cloud/usearch.git"
143 git_clone_archive(url, "v#{version}", "usearch-#{version}.tar.gz")
144 when "xsimd"
145 version = cmakelists[/set\(GRN_XSIMD_BUNDLED_VERSION \"(.+)"\)/, 1]
146 url = "https://github.com/xtensor-stack/xsimd/archive/refs/tags/"
147 url << "#{version}.tar.gz"
148 download(url, "xsimd-#{version}.tar.gz")
149 when "zstd"
150 version = cmakelists[/set\(GRN_ZSTD_BUNDLED_VERSION \"(.+)"\)/, 1]
151 url = "https://github.com/facebook/zstd/releases/download/"
152 url << "v#{version}/zstd-#{version}.tar.gz"
153 download(url)
154 else
155 $stderr.puts("Unsupported target #{target}")
156 exit(false)
157 end
158 end