forked from scientist-labs/parsekit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
199 lines (173 loc) · 4.77 KB
/
Rakefile
File metadata and controls
199 lines (173 loc) · 4.77 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
196
197
198
199
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rake/extensiontask"
require "rspec/core/rake_task"
# RSpec test task
RSpec::Core::RakeTask.new(:spec)
# Load the gemspec
spec = Gem::Specification.load("parsekit.gemspec")
# Extension compilation task
Rake::ExtensionTask.new("parsekit", spec) do |ext|
ext.lib_dir = "lib/parsekit"
ext.source_pattern = "*.{c,cc,cpp,rs}"
ext.cross_compile = true
ext.cross_platform = %w[x86_64-linux arm64-darwin x86_64-darwin aarch64-linux]
end
# Work around rake-compiler trying to stage non-existent build artifacts
# This happens when dependencies generate files during their build process
# Create dummy files for the ones that cause errors to satisfy rake-compiler
task :before_compile do
# Common build artifacts that rake-compiler tries to copy but don't exist after clean
problem_files = [
"ext/parsekit/target/release/build/clang-sys-*/out/common.rs",
"ext/parsekit/target/release/build/mupdf-sys-*/out/bindings.rs",
"ext/parsekit/target/release/build/rb-sys-*/out/*.rs",
"ext/parsekit/target/release/build/typenum-*/out/*.rs",
"ext/parsekit/target/release/build/rav1e-*/out/*.rs"
]
problem_files.each do |pattern|
Dir.glob(pattern).each do |file|
# These files will be regenerated during the actual build
# We just need them to exist to prevent rake errors
unless File.exist?(file)
FileUtils.mkdir_p(File.dirname(file))
FileUtils.touch(file)
end
end
end
end
# Ensure our workaround runs before compilation
task compile: :before_compile
# Default task runs compile then tests
task default: [:compile, :spec]
# Clean task
desc "Remove compiled artifacts"
task :clean do
FileUtils.rm_rf("lib/parsekit/*.bundle")
FileUtils.rm_rf("lib/parsekit/*.so")
FileUtils.rm_rf("lib/parsekit/*.dll")
FileUtils.rm_rf("tmp")
FileUtils.rm_rf("pkg")
Dir.chdir("ext/parsekit") do
sh "cargo clean" if File.exist?("Cargo.toml")
end
end
# Clobber task (more aggressive clean)
desc "Remove all generated files"
task clobber: :clean do
FileUtils.rm_rf("Gemfile.lock")
FileUtils.rm_rf(".rspec_status")
FileUtils.rm_rf("coverage")
end
# Rust-specific tasks
namespace :rust do
desc "Run cargo fmt"
task :fmt do
Dir.chdir("ext/parsekit") do
sh "cargo fmt"
end
end
desc "Run cargo fmt check"
task :fmt_check do
Dir.chdir("ext/parsekit") do
sh "cargo fmt -- --check"
end
end
desc "Run cargo test"
task :test do
Dir.chdir("ext/parsekit") do
sh "cargo test"
end
end
desc "Run cargo clippy"
task :clippy do
Dir.chdir("ext/parsekit") do
sh "cargo clippy -- -D warnings"
end
end
desc "Run cargo check"
task :check do
Dir.chdir("ext/parsekit") do
sh "cargo check"
end
end
desc "Update Rust dependencies"
task :update do
Dir.chdir("ext/parsekit") do
sh "cargo update"
end
end
end
# Development tasks
namespace :dev do
desc "Run tests with coverage"
task :coverage do
ENV["COVERAGE"] = "true"
Rake::Task["spec"].invoke
end
desc "Open coverage report in browser"
task :coverage_open do
system "open coverage/index.html"
end
desc "Open console with gem loaded"
task :console do
require "irb"
require "irb/completion"
require "parsekit"
ARGV.clear
IRB.start
end
desc "Run benchmarks"
task benchmark: :compile do
ruby "benchmark/benchmark.rb"
end
end
# Documentation tasks
begin
require "yard"
YARD::Rake::YardocTask.new do |t|
t.files = ["lib/**/*.rb", "ext/**/*.rs"]
t.options = ["--no-private", "--markup", "markdown"]
end
rescue LoadError
desc "Generate documentation (requires YARD)"
task :yard do
puts "YARD is not available. Install it with: gem install yard"
end
end
# CI-specific tasks
namespace :ci do
desc "Run all CI checks"
task all: [:compile, :spec, "rust:fmt_check", "rust:clippy", "rust:test"]
desc "Setup CI environment"
task :setup do
sh "bundle install"
sh "rustup component add rustfmt clippy"
end
end
# Platform-specific compilation helpers
namespace :compile do
desc "Compile for current platform with debug symbols"
task :debug do
ENV["DEBUG"] = "true"
Rake::Task["compile"].invoke
end
desc "Compile for release (optimized)"
task :release do
ENV["RELEASE"] = "true"
Rake::Task["compile"].invoke
end
end
# Release tasks
namespace :release do
desc "Build native gems for all platforms"
task :native do
# This would be run on CI with proper cross-compilation setup
platforms = %w[x86_64-linux arm64-darwin x86_64-darwin aarch64-linux]
platforms.each do |platform|
puts "Building for #{platform}..."
ENV["RUBY_CC_VERSION"] = "3.0.0:3.1.0:3.2.0:3.3.0:4.0.0"
sh "rake native:#{platform} gem"
end
end
end