blob: 543d79061d6a9a0542a06f691941a3db052ad54d [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
26 ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
nnoble097ef9b2014-12-01 17:06:10 -080027end
28
Tim Emiolaf20d7602015-03-24 08:11:47 -070029# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080030SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080031 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
32 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080033 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080034 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080035 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080036 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070037 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080038 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080039]
Tim Emiolaf20d7602015-03-24 08:11:47 -070040namespace :suite do
41 SPEC_SUITES.each do |suite|
42 desc "Run all specs in the #{suite[:title]} spec suite"
43 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070044 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070045 spec_files = []
46 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080047
Tim Emiolaf20d7602015-03-24 08:11:47 -070048 if suite[:dir]
49 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
50 end
murgatroid99d7e1a102015-12-18 11:16:16 -080051 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070052 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080053
Tim Emiolaf20d7602015-03-24 08:11:47 -070054 t.pattern = spec_files
55 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
56 if suite[:tags]
57 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080058 end
59 end
60 end
61end
62
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010063desc 'Build the gem file under rake_compiler_dock'
64task 'gem:windows' do
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010065 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
66 V = ENV['V'] || '0'
67
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010068 env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE" '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010069 env += 'LDFLAGS=-static '
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010070 env += 'SYSTEM=MINGW32 '
71 env += 'EMBED_ZLIB=true '
72 env += 'BUILDDIR=/tmp '
73 out = '/tmp/libs/opt/grpc-0.dll'
74
75 env_comp = 'CC=x86_64-w64-mingw32-gcc '
76 env_comp += 'LD=x86_64-w64-mingw32-gcc '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010077 docker_for_windows "#{env} #{env_comp} make -j #{out} && x86_64-w64-mingw32-strip -x -S #{out} && cp #{out} grpc_c.64.ruby"
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010078
79 env_comp = 'CC=i686-w64-mingw32-gcc '
80 env_comp += 'LD=i686-w64-mingw32-gcc '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010081 docker_for_windows "#{env} #{env_comp} make -j #{out} && i686-w64-mingw32-strip -x -S #{out} && cp #{out} grpc_c.32.ruby"
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010082
83 docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.6:2.0.0 GRPC_CONFIG=#{grpc_config} V=#{V}"
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010084end
85
Tim Emiolaf20d7602015-03-24 08:11:47 -070086# Define dependencies between the suites.
87task 'suite:wrapper' => [:compile, :rubocop]
88task 'suite:idiomatic' => 'suite:wrapper'
89task 'suite:bidi' => 'suite:wrapper'
90task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -070091task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -080092
Tim Emiolaf20d7602015-03-24 08:11:47 -070093desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -070094task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -080095task default: :all