blob: 704069694773abf429ba8494e7a05138a4640418 [file] [log] [blame]
nnoble097ef9b2014-12-01 17:06:10 -08001# -*- ruby -*-
2require 'rake/extensiontask'
3require 'rspec/core/rake_task'
Tim Emiolae2860c52015-01-16 02:58:41 -08004require 'rubocop/rake_task'
Tim Emiolaf20d7602015-03-24 08:11:47 -07005require 'bundler/gem_tasks'
nnoble097ef9b2014-12-01 17:06:10 -08006
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +01007load 'tools/distrib/docker_for_windows.rb'
8
Tim Emiolaf20d7602015-03-24 08:11:47 -07009# Add rubocop style checking tasks
murgatroid99d7e1a102015-12-18 11:16:16 -080010RuboCop::RakeTask.new(:rubocop) do |task|
11 task.options = ['-c', 'src/ruby/.rubocop.yml']
12 task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
13end
nnoble097ef9b2014-12-01 17:06:10 -080014
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010015spec = Gem::Specification.load('grpc.gemspec')
16
17Gem::PackageTask.new(spec) do |pkg|
18end
19
Tim Emiolaf20d7602015-03-24 08:11:47 -070020# Add the extension compiler task
Nicolas "Pixel" Nobleeade6e02016-01-29 22:53:31 +010021Rake::ExtensionTask.new('grpc_c', spec) do |ext|
murgatroid99d7e1a102015-12-18 11:16:16 -080022 ext.source_pattern = '**/*.{c,h}'
23 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
24 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010025 ext.cross_compile = true
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010026 ext.cross_platform = [
27 'x86-mingw32', 'x64-mingw32',
28 'x86_64-linux', 'x86-linux',
29 'x86_64-darwin-11',
30 'x86_64-darwin-12',
31 'x86_64-darwin-13',
32 'x86_64-darwin-14',
33 'x86_64-darwin-15'
34 ]
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010035 ext.cross_compiling do |spec|
36 spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
37 spec.files += Dir.glob('src/ruby/bin/**/*')
38 spec.files += Dir.glob('src/ruby/ext/**/*')
39 spec.files += Dir.glob('src/ruby/lib/**/*')
40 spec.files += Dir.glob('src/ruby/pb/**/*')
41 end
nnoble097ef9b2014-12-01 17:06:10 -080042end
43
Tim Emiolaf20d7602015-03-24 08:11:47 -070044# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080045SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080046 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
47 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080048 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080049 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080050 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080051 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070052 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080053 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080054]
Tim Emiolaf20d7602015-03-24 08:11:47 -070055namespace :suite do
56 SPEC_SUITES.each do |suite|
57 desc "Run all specs in the #{suite[:title]} spec suite"
58 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070059 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070060 spec_files = []
61 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080062
Tim Emiolaf20d7602015-03-24 08:11:47 -070063 if suite[:dir]
64 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
65 end
murgatroid99d7e1a102015-12-18 11:16:16 -080066 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070067 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080068
Tim Emiolaf20d7602015-03-24 08:11:47 -070069 t.pattern = spec_files
70 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
71 if suite[:tags]
72 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080073 end
74 end
75 end
76end
77
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010078desc 'Build the Windows gRPC DLLs for Ruby'
79task 'dlls' do
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010080 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010081 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010082
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010083 env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE" '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010084 env += 'LDFLAGS=-static '
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010085 env += 'SYSTEM=MINGW32 '
86 env += 'EMBED_ZLIB=true '
87 env += 'BUILDDIR=/tmp '
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010088 env += "V=#{verbose} "
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010089 out = '/tmp/libs/opt/grpc-0.dll'
90
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010091 w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' }
92 w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' }
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010093
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010094 [ w64, w32 ].each do |opt|
95 env_comp = "CC=#{opt[:cross]}-gcc "
96 env_comp += "LD=#{opt[:cross]}-gcc "
97 docker_for_windows "#{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
98 end
99
100end
101
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +0100102desc 'Build the native gem file under rake_compiler_dock'
103task 'gem:native' do
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100104 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100105
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100106 docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose}"
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +0100107end
108
Tim Emiolaf20d7602015-03-24 08:11:47 -0700109# Define dependencies between the suites.
110task 'suite:wrapper' => [:compile, :rubocop]
111task 'suite:idiomatic' => 'suite:wrapper'
112task 'suite:bidi' => 'suite:wrapper'
113task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700114task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -0800115
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +0100116task 'gem:native' => 'dlls'
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100117
Tim Emiolaf20d7602015-03-24 08:11:47 -0700118desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700119task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -0800120task default: :all