blob: f44946fe93739299a051de3fea84caf684e61c04 [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'
Nicolas Noble86cbe302016-02-05 15:08:12 -08006require 'fileutils'
nnoble097ef9b2014-12-01 17:06:10 -08007
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +01008load 'tools/distrib/docker_for_windows.rb'
9
Tim Emiolaf20d7602015-03-24 08:11:47 -070010# Add rubocop style checking tasks
murgatroid99d7e1a102015-12-18 11:16:16 -080011RuboCop::RakeTask.new(:rubocop) do |task|
12 task.options = ['-c', 'src/ruby/.rubocop.yml']
13 task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
14end
nnoble097ef9b2014-12-01 17:06:10 -080015
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010016spec = Gem::Specification.load('grpc.gemspec')
17
18Gem::PackageTask.new(spec) do |pkg|
19end
20
Tim Emiolaf20d7602015-03-24 08:11:47 -070021# Add the extension compiler task
Nicolas "Pixel" Nobleeade6e02016-01-29 22:53:31 +010022Rake::ExtensionTask.new('grpc_c', spec) do |ext|
murgatroid99d7e1a102015-12-18 11:16:16 -080023 ext.source_pattern = '**/*.{c,h}'
24 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
25 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010026 ext.cross_compile = true
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010027 ext.cross_platform = [
28 'x86-mingw32', 'x64-mingw32',
29 'x86_64-linux', 'x86-linux',
Nicolas Noble86cbe302016-02-05 15:08:12 -080030 'universal-darwin'
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010031 ]
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010032 ext.cross_compiling do |spec|
33 spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
34 spec.files += Dir.glob('src/ruby/bin/**/*')
35 spec.files += Dir.glob('src/ruby/ext/**/*')
36 spec.files += Dir.glob('src/ruby/lib/**/*')
37 spec.files += Dir.glob('src/ruby/pb/**/*')
38 end
nnoble097ef9b2014-12-01 17:06:10 -080039end
40
Tim Emiolaf20d7602015-03-24 08:11:47 -070041# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080042SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080043 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
44 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080045 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080046 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080047 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080048 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070049 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080050 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080051]
Tim Emiolaf20d7602015-03-24 08:11:47 -070052namespace :suite do
53 SPEC_SUITES.each do |suite|
54 desc "Run all specs in the #{suite[:title]} spec suite"
55 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070056 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070057 spec_files = []
58 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080059
Tim Emiolaf20d7602015-03-24 08:11:47 -070060 if suite[:dir]
61 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
62 end
murgatroid99d7e1a102015-12-18 11:16:16 -080063 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070064 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080065
Tim Emiolaf20d7602015-03-24 08:11:47 -070066 t.pattern = spec_files
67 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
68 if suite[:tags]
69 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080070 end
71 end
72 end
73end
74
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010075desc 'Build the Windows gRPC DLLs for Ruby'
76task 'dlls' do
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010077 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010078 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010079
Ken Payson17233ce2016-06-22 17:16:15 -070080 env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE -Wno-unused-variable -Wno-unused-result" '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010081 env += 'LDFLAGS=-static '
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010082 env += 'SYSTEM=MINGW32 '
83 env += 'EMBED_ZLIB=true '
84 env += 'BUILDDIR=/tmp '
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010085 env += "V=#{verbose} "
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010086 out = '/tmp/libs/opt/grpc-0.dll'
87
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010088 w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' }
89 w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' }
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010090
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010091 [ w64, w32 ].each do |opt|
92 env_comp = "CC=#{opt[:cross]}-gcc "
93 env_comp += "LD=#{opt[:cross]}-gcc "
94 docker_for_windows "#{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
95 end
96
97end
98
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010099desc 'Build the native gem file under rake_compiler_dock'
100task 'gem:native' do
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100101 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100102
Nicolas Noble86cbe302016-02-05 15:08:12 -0800103 if RUBY_PLATFORM =~ /darwin/
104 FileUtils.touch 'grpc_c.32.ruby'
105 FileUtils.touch 'grpc_c.64.ruby'
Nicolas "Pixel" Nobleda46a702016-02-06 01:52:02 +0100106 system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800107 else
108 Rake::Task['dlls'].execute
Nicolas "Pixel" Nobleda46a702016-02-06 01:52:02 +0100109 docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800110 end
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +0100111end
112
Tim Emiolaf20d7602015-03-24 08:11:47 -0700113# Define dependencies between the suites.
114task 'suite:wrapper' => [:compile, :rubocop]
115task 'suite:idiomatic' => 'suite:wrapper'
116task 'suite:bidi' => 'suite:wrapper'
117task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700118task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -0800119
Tim Emiolaf20d7602015-03-24 08:11:47 -0700120desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700121task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -0800122task default: :all