-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
129 lines (105 loc) · 3.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'ffi'
require 'rake'
require 'rake/testtask'
require 'rb_sys/extensiontask'
require 'rspec/core/rake_task'
require 'rubygems'
require 'rubygems/package_task'
GEM_SPEC = Gem::Specification.load('bytebuffer.gemspec')
namespace :gem do
desc 'Clean up the Gem build environment. Note: This command indiscriminately removes all .so, and .bundle files in subdirectories.'
task :clean do
FileUtils.rm_rf(%w(./tmp ./pkg ./target))
case FFI::Platform::OS
when 'linux' then FileUtils.rm_r(Dir['./**/*.so'])
when 'darwin' then FileUtils.rm_r(Dir['./**/*.bundle'])
else system("rm -r ./**/*.so")
end
end
desc 'Compile and install the native extension'
task compile: %i(clean) do
RbSys::ExtensionTask.new('bytebuffer', GEM_SPEC) do |ext|
ext.source_pattern = "*.{rs,toml,lock,rb}"
ext.ext_dir = "#{File.dirname(__FILE__)}/ext/bytebuffer"
ext.cross_platform = %w[
aarch64-linux
arm64-darwin
x86_64-darwin
x86_64-linux
x86_64-linux-musl
]
ext.cross_compile = true
ext.lib_dir = "lib"
end
Rake::Task["compile"].invoke
end
desc 'Apply platform patches'
task :patch do
working_dir = File.dirname(__FILE__)
target = case RUBY_PLATFORM
when /darwin/ then 'darwin'
when /linux/ then 'linux'
end
patch_dir = "#{working_dir}/lib/bytebuffer/patch/#{target}"
unless !File.directory?(patch_dir) || Dir.empty?(patch_dir)
puts "Applying platform patches for #{target}"
FileUtils.chdir(patch_dir) do |dir|
Dir["#{dir}/*.patch"].sort.each do |patch|
puts "Applying patch: #{patch}"
system("patch #{working_dir}/lib/bytebuffer.rb #{patch}")
end
end
end
end
desc 'Revert platform patches'
task :revert do
working_dir = File.dirname(__FILE__)
target = case RUBY_PLATFORM
when /darwin/ then 'darwin'
when /linux/ then 'linux'
end
FileUtils.chdir("#{working_dir}/lib/bytebuffer/patch/#{target}") do |dir|
Dir["#{dir}/*.patch"].sort.each do |patch|
puts "Applying patch: #{patch}"
system("patch -R #{working_dir}/lib/bytebuffer.rb #{patch}")
end
end
end
desc 'Package the Gem package'
task package: %i(compile gem:patch) do
Gem::PackageTask.new(GEM_SPEC) do |pkg|
pkg.need_tar_bz2 = true
end
Rake::Task['package'].invoke
end
end
namespace :docs do
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.name = 'generate'
t.files = %w(lib/**/*.rb)
end
task serve: %i[docs:generate] do
Kernel.system('yard server')
end
task :clean do
require 'fileutils'
FileUtils.rm_rf('doc')
FileUtils.rm_rf('.yardoc')
end
end
namespace :test do
desc 'Runs all specs in the "spec/" folder using RSpec.'
RSpec::Core::RakeTask.new(:rspec)
task :clean do
require 'fileutils'
FileUtils.rm_rf('coverage')
end
desc 'Runs extension tests using cargo test.'
task :ext do
raise "Install rustc along with Cargo before running this rake task." if !system('cargo --version') || !system('rustc --version')
system("cargo test")
end
end