Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
195 lines (173 loc) · 6.8 KB
/
Copy pathRakefile
File metadata and controls
195 lines (173 loc) · 6.8 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# frozen_string_literal: true
# Only load bundler gem tasks when not testing installed gem
# bundler/gem_tasks can interfere with load path when testing installed gems
require 'bundler/gem_tasks' unless ENV["TEST_INSTALLED_GEM"]
require 'rake/testtask'
YARD_PUBLIC_API_FILES = %w[
lib/valkey.rb
lib/valkey/commands.rb
lib/valkey/commands/bitmap_commands.rb
lib/valkey/commands/cluster_commands.rb
lib/valkey/commands/connection_commands.rb
lib/valkey/commands/function_commands.rb
lib/valkey/commands/generic_commands.rb
lib/valkey/commands/geo_commands.rb
lib/valkey/commands/hash_commands.rb
lib/valkey/commands/hyper_log_log_commands.rb
lib/valkey/commands/json_commands.rb
lib/valkey/commands/list_commands.rb
lib/valkey/commands/module_commands.rb
lib/valkey/commands/pubsub_commands.rb
lib/valkey/commands/scripting_commands.rb
lib/valkey/commands/server_commands.rb
lib/valkey/commands/set_commands.rb
lib/valkey/commands/sorted_set_commands.rb
lib/valkey/commands/stream_commands.rb
lib/valkey/commands/string_commands.rb
lib/valkey/commands/transaction_commands.rb
lib/valkey/commands/vector_search_commands.rb
lib/valkey/pubsub/pubsub_message.rb
lib/valkey/pubsub/pubsub_state.rb
lib/valkey/search.rb
lib/valkey/search/aggregate.rb
lib/valkey/search/create_options.rb
lib/valkey/search/fields.rb
lib/valkey/search/info.rb
lib/valkey/search/query.rb
].freeze
namespace :lint do
desc "Lint YARD documentation for public APIs"
task :yard do
missing_files = YARD_PUBLIC_API_FILES.reject { |file| File.file?(file) }
abort "YARD public API files not found:\n#{missing_files.join("\n")}" unless missing_files.empty?
failed_files = YARD_PUBLIC_API_FILES.reject { |file| system("yard-lint", file) }
abort "YARD lint failed for:\n#{failed_files.join("\n")}" unless failed_files.empty?
end
end
# =============================================================================
# Native Library Build Tasks
# =============================================================================
def native_lib_ext
case RbConfig::CONFIG['host_os']
when /darwin/
'dylib'
else
'so'
end
end
namespace :native do
desc "Initialize the valkey-glide submodule"
task :submodule do
puts "Initializing valkey-glide submodule..."
sh "git submodule update --init --recursive"
end
desc "Build the native FFI library (release mode)"
task build: :submodule do
puts "Building native FFI library..."
Dir.chdir("valkey-glide/ffi") do
# Set GLIDE_NAME to identify this as the Ruby client in CLIENT SETINFO
# GLIDE_VERSION is set from lib/valkey/version.rb
version = File.read("../../lib/valkey/version.rb")[/VERSION = "([^"]+)"/, 1] ||
abort("Could not determine VERSION from lib/valkey/version.rb")
sh({ "GLIDE_NAME" => "GlideRuby", "GLIDE_VERSION" => version }, "cargo build --release")
end
puts "Native library built successfully!"
puts "Location: valkey-glide/ffi/target/release/libglide_ffi.#{native_lib_ext}"
end
desc "Build the native FFI library (debug mode)"
task build_debug: :submodule do
puts "Building native FFI library (debug)..."
Dir.chdir("valkey-glide/ffi") do
# Set GLIDE_NAME to identify this as the Ruby client in CLIENT SETINFO
version = File.read("../../lib/valkey/version.rb")[/VERSION = "([^"]+)"/, 1] ||
abort("Could not determine VERSION from lib/valkey/version.rb")
sh({ "GLIDE_NAME" => "GlideRuby", "GLIDE_VERSION" => version }, "cargo build")
end
puts "Native library built successfully!"
puts "Location: valkey-glide/ffi/target/debug/libglide_ffi.#{native_lib_ext}"
end
desc "Clean native build artifacts"
task :clean do
puts "Cleaning native build artifacts..."
if Dir.exist?("valkey-glide/ffi")
Dir.chdir("valkey-glide/ffi") do
sh "cargo clean"
end
end
puts "Clean complete!"
end
desc "Copy built library to lib/valkey/native/{platform}/ for gem packaging"
task package: :build do
require 'fileutils'
require 'rbconfig'
# Determine platform directory name (matches Rust target triple)
os = case RbConfig::CONFIG['host_os']
when /darwin/
'apple-darwin'
when /linux/
'unknown-linux-gnu'
when /mswin|mingw/
'pc-windows-msvc'
else
abort "Unsupported OS: #{RbConfig::CONFIG['host_os']}"
end
arch = case RbConfig::CONFIG['host_cpu']
when /x86_64|amd64/i
'x86_64'
when /aarch64|arm64/i
'aarch64'
else
abort "Unsupported architecture: #{RbConfig::CONFIG['host_cpu']}"
end
platform_dir = "#{arch}-#{os}"
src = "valkey-glide/ffi/target/release/libglide_ffi.#{native_lib_ext}"
dest_dir = "lib/valkey/native/#{platform_dir}"
dest = "#{dest_dir}/libglide_ffi.#{native_lib_ext}"
if File.exist?(src)
FileUtils.mkdir_p(dest_dir)
FileUtils.cp(src, dest)
puts "Copied #{src} to #{dest}"
puts "Platform: #{platform_dir}"
else
abort "Native library not found at #{src}. Run 'rake native:build' first."
end
end
end
desc "Build the native FFI library"
task native: "native:build"
# =============================================================================
# Test Tasks
# =============================================================================
namespace :test do
groups = {
unit: "unit",
standalone: "integration/standalone",
cluster: "integration/cluster",
modules: "integration/modules"
}
groups.each do |group, dir|
Rake::TestTask.new(group) do |t|
t.libs << "test"
# Only add local lib to load path when not testing installed gem
t.libs << "lib" unless ENV["TEST_INSTALLED_GEM"]
t.test_files = FileList["test/#{dir}/**/*_test.rb"]
t.options = '-v' if ENV['CI'] || ENV['VERBOSE']
end
end
# Exclude module directories (integration/valkey/, lint/) from lost_tests check
# These contain reusable test modules, not standalone test files
module_dirs = %w[integration/valkey lint]
# Scripts run directly rather than via a test group — see ci.yml and cd.yml.
# test/isolated/ holds tests that must not share a process with any other test.
standalone_scripts = %w[test/smoke_test.rb] +
Dir["test/isolated/**/*_test.rb"]
lost_tests = Dir["test/**/*_test.rb"] -
groups.values.map { |d| Dir["test/#{d}/**/*_test.rb"] }.flatten -
module_dirs.map { |d| Dir["test/#{d}/**/*_test.rb"] }.flatten -
standalone_scripts
abort "The following test files are in no group:\n#{lost_tests.join("\n")}" unless lost_tests.empty?
desc "Run integration tests (standalone + cluster)"
task integration: %w[standalone cluster]
end
task test: ["test:unit", "test:integration"]
task default: :test