blob: 12ac12710fb8876d8d5f77edd7d17174d0c6d7a0 [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
murgatroid99c781f642017-01-17 11:47:06 -08008require_relative 'build_config.rb'
9
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010010load 'tools/distrib/docker_for_windows.rb'
11
Tim Emiolaf20d7602015-03-24 08:11:47 -070012# Add rubocop style checking tasks
murgatroid99d7e1a102015-12-18 11:16:16 -080013RuboCop::RakeTask.new(:rubocop) do |task|
14 task.options = ['-c', 'src/ruby/.rubocop.yml']
15 task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
16end
nnoble097ef9b2014-12-01 17:06:10 -080017
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010018spec = Gem::Specification.load('grpc.gemspec')
19
20Gem::PackageTask.new(spec) do |pkg|
21end
22
Tim Emiolaf20d7602015-03-24 08:11:47 -070023# Add the extension compiler task
Nicolas "Pixel" Nobleeade6e02016-01-29 22:53:31 +010024Rake::ExtensionTask.new('grpc_c', spec) do |ext|
murgatroid99d7e1a102015-12-18 11:16:16 -080025 ext.source_pattern = '**/*.{c,h}'
26 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
27 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010028 ext.cross_compile = true
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010029 ext.cross_platform = [
30 'x86-mingw32', 'x64-mingw32',
31 'x86_64-linux', 'x86-linux',
Nicolas Noble86cbe302016-02-05 15:08:12 -080032 'universal-darwin'
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010033 ]
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010034 ext.cross_compiling do |spec|
35 spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
36 spec.files += Dir.glob('src/ruby/bin/**/*')
37 spec.files += Dir.glob('src/ruby/ext/**/*')
38 spec.files += Dir.glob('src/ruby/lib/**/*')
39 spec.files += Dir.glob('src/ruby/pb/**/*')
40 end
nnoble097ef9b2014-12-01 17:06:10 -080041end
42
Tim Emiolaf20d7602015-03-24 08:11:47 -070043# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080044SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080045 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
46 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080047 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080048 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080049 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080050 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070051 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080052 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080053]
Tim Emiolaf20d7602015-03-24 08:11:47 -070054namespace :suite do
55 SPEC_SUITES.each do |suite|
56 desc "Run all specs in the #{suite[:title]} spec suite"
57 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070058 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070059 spec_files = []
60 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080061
Tim Emiolaf20d7602015-03-24 08:11:47 -070062 if suite[:dir]
63 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
64 end
murgatroid99d7e1a102015-12-18 11:16:16 -080065 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070066 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080067
Tim Emiolaf20d7602015-03-24 08:11:47 -070068 t.pattern = spec_files
69 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
70 if suite[:tags]
71 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080072 end
73 end
74 end
75end
76
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010077desc 'Build the Windows gRPC DLLs for Ruby'
78task 'dlls' do
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010079 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010080 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010081
Ken Payson17233ce2016-06-22 17:16:15 -070082 env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE -Wno-unused-variable -Wno-unused-result" '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010083 env += 'LDFLAGS=-static '
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010084 env += 'SYSTEM=MINGW32 '
85 env += 'EMBED_ZLIB=true '
86 env += 'BUILDDIR=/tmp '
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010087 env += "V=#{verbose} "
murgatroid99c781f642017-01-17 11:47:06 -080088 out = GrpcBuildConfig::CORE_WINDOWS_DLL
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010089
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010090 w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' }
91 w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' }
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010092
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010093 [ w64, w32 ].each do |opt|
94 env_comp = "CC=#{opt[:cross]}-gcc "
95 env_comp += "LD=#{opt[:cross]}-gcc "
Nicolas "Pixel" Noblea9fb1112017-02-01 19:38:58 +010096 docker_for_windows "gem update --system && #{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010097 end
98
99end
100
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +0100101desc 'Build the native gem file under rake_compiler_dock'
102task 'gem:native' do
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100103 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100104
Alexander Polcyn38ba85c2016-08-29 16:59:23 -0700105 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
106
Nicolas Noble86cbe302016-02-05 15:08:12 -0800107 if RUBY_PLATFORM =~ /darwin/
108 FileUtils.touch 'grpc_c.32.ruby'
109 FileUtils.touch 'grpc_c.64.ruby'
Nicolas "Pixel" Nobleb230ba82017-01-30 19:27:19 +0100110 system "rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800111 else
112 Rake::Task['dlls'].execute
Nicolas "Pixel" Noblea9fb1112017-02-01 19:38:58 +0100113 docker_for_windows "gem update --system && bundle && rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800114 end
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +0100115end
116
Tim Emiolaf20d7602015-03-24 08:11:47 -0700117# Define dependencies between the suites.
118task 'suite:wrapper' => [:compile, :rubocop]
119task 'suite:idiomatic' => 'suite:wrapper'
120task 'suite:bidi' => 'suite:wrapper'
121task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700122task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -0800123
Tim Emiolaf20d7602015-03-24 08:11:47 -0700124desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700125task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -0800126task default: :all