forked from ruby-concurrency/concurrent-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
144 lines (117 loc) · 3.63 KB
/
Rakefile
File metadata and controls
144 lines (117 loc) · 3.63 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
#!/usr/bin/env rake
require_relative './lib/extension_helper'
## load the two gemspec files
CORE_GEMSPEC = Gem::Specification.load('concurrent-ruby.gemspec')
EXT_GEMSPEC = Gem::Specification.load('concurrent-ruby-ext.gemspec')
## constants used for compile/build tasks
GEM_NAME = 'concurrent-ruby'
EXTENSION_NAME = 'extension'
JAVA_EXT_NAME = 'concurrent_ruby_ext'
if Concurrent.jruby?
CORE_GEM = "#{GEM_NAME}-#{Concurrent::VERSION}-java.gem"
else
CORE_GEM = "#{GEM_NAME}-#{Concurrent::VERSION}.gem"
EXTENSION_GEM = "#{GEM_NAME}-ext-#{Concurrent::VERSION}.gem"
NATIVE_GEM = "#{GEM_NAME}-ext-#{Concurrent::VERSION}-#{Gem::Platform.new(RUBY_PLATFORM)}.gem"
end
## safely load all the rake tasks in the `tasks` directory
def safe_load(file)
begin
load file
rescue LoadError => ex
puts "Error loading rake tasks from '#{file}' but will continue..."
puts ex.message
end
end
Dir.glob('tasks/**/*.rake').each do |rakefile|
safe_load rakefile
end
if Concurrent.jruby?
## create the compile task for the JRuby-specific gem
require 'rake/javaextensiontask'
Rake::JavaExtensionTask.new(JAVA_EXT_NAME, CORE_GEMSPEC) do |ext|
ext.ext_dir = 'ext'
end
elsif Concurrent.allow_c_extensions?
## create the compile tasks for the extension gem
require 'rake/extensiontask'
Rake::ExtensionTask.new(EXTENSION_NAME, EXT_GEMSPEC) do |ext|
ext.ext_dir = 'ext/concurrent'
ext.lib_dir = 'lib/concurrent'
ext.source_pattern = '*.{c,h}'
ext.cross_compile = true
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
end
ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
platforms = {
'x86-mingw32' => 'i686-w64-mingw32',
'x64-mingw32' => 'x86_64-w64-mingw32'
}
platforms.each do |platform, prefix|
task "copy:#{EXTENSION_NAME}:#{platform}:#{ruby_version}" do |t|
%w[lib tmp/#{platform}/stage/lib].each do |dir|
so_file = "#{dir}/#{ruby_version[/^\d+\.\d+/]}/#{EXTENSION_NAME}.so"
if File.exists?(so_file)
sh "#{prefix}-strip -S #{so_file}"
end
end
end
end
end
else
## create an empty compile task
task :compile
end
task :clean do
rm_rf 'pkg/classes'
rm_rf 'tmp'
rm_rf 'lib/concurrent/1.9'
rm_rf 'lib/concurrent/2.0'
rm_rf 'lib/concurrent/2.1'
rm_f Dir.glob('./**/*.so')
rm_f Dir.glob('./**/*.bundle')
rm_f Dir.glob('./lib/*.jar')
mkdir_p 'pkg'
end
## create build tasks tailored to current platform
namespace :build do
build_deps = [:clean]
build_deps << :compile if Concurrent.jruby?
desc "Build #{CORE_GEM} into the pkg directory"
task :core => build_deps do
sh "gem build #{CORE_GEMSPEC.name}.gemspec"
sh 'mv *.gem pkg/'
end
unless Concurrent.jruby?
desc "Build #{EXTENSION_GEM} into the pkg directory"
task :ext => [:clean] do
sh "gem build #{EXT_GEMSPEC.name}.gemspec"
sh 'mv *.gem pkg/'
end
end
if Concurrent.allow_c_extensions?
desc "Build #{NATIVE_GEM} into the pkg directory"
task :native do
sh "gem compile pkg/#{EXTENSION_GEM}"
sh 'mv *.gem pkg/'
end
end
end
if Concurrent.jruby?
desc 'Build JRuby-specific core gem (alias for `build:core`)'
task :build => ['build:core']
else
desc 'Build core and extension gems'
task :build => ['build:core', 'build:ext']
end
## the RSpec task that compiles extensions when available
begin
require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = '--color --backtrace --format documentation'
end
task :default => [:clean, :compile, :spec]
rescue LoadError
puts 'Error loading Rspec rake tasks, probably building the gem...'
end