-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathRakefile
More file actions
97 lines (74 loc) · 2.51 KB
/
Rakefile
File metadata and controls
97 lines (74 loc) · 2.51 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
# frozen_string_literal: true
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'digest/sha2'
require 'ffi'
require 'ffi-compiler/compile_task'
require 'fileutils'
require 'rake'
require 'rake/clean'
require 'rdoc/task'
require 'rspec/core/rake_task'
require 'rubygems'
require 'rubygems/package_task'
require './lib/scrypt/version'
task default: %i[clean compile_ffi spec]
desc 'Run all specs'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--color', '--backtrace', '--format', 'documentation']
end
desc 'Generate checksum for built gem'
task :checksum do
built_gem_path = "pkg/scrypt-#{SCrypt::VERSION}.gem"
unless File.exist?(built_gem_path)
puts "Gem file not found: #{built_gem_path}"
puts "Run 'rake build' first to create the gem."
exit 1
end
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
checksum_path = "checksum/scrypt-#{SCrypt::VERSION}.gem.sha512"
# Ensure checksum directory exists
FileUtils.mkdir_p(File.dirname(checksum_path))
File.write(checksum_path, checksum)
puts "Checksum written to: #{checksum_path}"
end
desc 'Compile FFI extension'
namespace :ffi_compiler do
FFI::Compiler::CompileTask.new('ext/scrypt/scrypt_ext') do |t|
target_cpu = RbConfig::CONFIG['target_cpu']
t.cflags << '-Wall -std=c99'
t.cflags << '-msse -msse2' if t.platform.arch.include?('86')
t.cflags << '-D_GNU_SOURCE=1' if RbConfig::CONFIG['host_os'].downcase =~ /mingw/
t.cflags << '-D_POSIX_C_SOURCE=200809L' if RbConfig::CONFIG['host_os'].downcase =~ /linux/
if 1.size == 4 && target_cpu =~ /i386|x86_32/ && t.platform.mac?
t.cflags << '-arch i386'
t.ldflags << '-arch i386'
elsif 1.size == 8 && target_cpu =~ /i686|x86_64/ && t.platform.mac?
t.cflags << '-arch x86_64'
t.ldflags << '-arch x86_64'
end
t.add_define 'WINDOWS_OS' if FFI::Platform.windows?
end
end
task compile_ffi: ['ffi_compiler:default']
CLEAN.include('ext/scrypt/*{.o,.log,.so,.bundle}')
CLEAN.include('lib/**/*{.o,.log,.so,.bundle}')
desc 'Generate RDoc documentation'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc/rdoc'
rdoc.options << '--force-update'
rdoc.options << '-V'
rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE']
end
desc 'Run all specs'
RSpec::Core::RakeTask.new do |_t|
# Task automatically runs specs based on RSpec defaults
end
def gem_spec
@gem_spec ||= Gem::Specification.load('scrypt.gemspec')
end
Gem::PackageTask.new(gem_spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
pkg.package_dir = 'pkg'
end