blob: 0068a3b8e4fe206d05e41cb78224eb773800faae [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']
Alexander Polcyn4e606752017-03-19 23:32:54 -070015 # add end2end tests to formatter but don't add generated proto _pb.rb's
16 task.patterns = ['src/ruby/{lib,spec}/**/*.rb', 'src/ruby/end2end/*.rb']
murgatroid99d7e1a102015-12-18 11:16:16 -080017end
nnoble097ef9b2014-12-01 17:06:10 -080018
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010019spec = Gem::Specification.load('grpc.gemspec')
20
21Gem::PackageTask.new(spec) do |pkg|
22end
23
Tim Emiolaf20d7602015-03-24 08:11:47 -070024# Add the extension compiler task
Nicolas "Pixel" Nobleeade6e02016-01-29 22:53:31 +010025Rake::ExtensionTask.new('grpc_c', spec) do |ext|
Alexander Polcyna803c032018-03-06 16:16:57 -080026 unless RUBY_PLATFORM =~ /darwin/
27 # TODO: also set "no_native to true" for mac if possible. As is,
28 # "no_native" can only be set if the RUBY_PLATFORM doing
29 # cross-compilation is contained in the "ext.cross_platform" array.
30 ext.no_native = true
31 end
murgatroid99d7e1a102015-12-18 11:16:16 -080032 ext.source_pattern = '**/*.{c,h}'
33 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
34 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +010035 ext.cross_compile = true
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010036 ext.cross_platform = [
37 'x86-mingw32', 'x64-mingw32',
38 'x86_64-linux', 'x86-linux',
Nicolas Noble86cbe302016-02-05 15:08:12 -080039 'universal-darwin'
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +010040 ]
Nicolas "Pixel" Nobled51d1212016-01-31 11:33:19 +010041 ext.cross_compiling do |spec|
42 spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
43 spec.files += Dir.glob('src/ruby/bin/**/*')
44 spec.files += Dir.glob('src/ruby/ext/**/*')
45 spec.files += Dir.glob('src/ruby/lib/**/*')
46 spec.files += Dir.glob('src/ruby/pb/**/*')
47 end
nnoble097ef9b2014-12-01 17:06:10 -080048end
49
Tim Emiolaf20d7602015-03-24 08:11:47 -070050# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080051SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080052 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
53 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080054 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080055 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080056 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080057 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070058 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080059 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080060]
Tim Emiolaf20d7602015-03-24 08:11:47 -070061namespace :suite do
62 SPEC_SUITES.each do |suite|
63 desc "Run all specs in the #{suite[:title]} spec suite"
64 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070065 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070066 spec_files = []
67 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080068
Tim Emiolaf20d7602015-03-24 08:11:47 -070069 if suite[:dir]
70 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
71 end
murgatroid99d7e1a102015-12-18 11:16:16 -080072 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070073 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080074
Tim Emiolaf20d7602015-03-24 08:11:47 -070075 t.pattern = spec_files
76 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
77 if suite[:tags]
78 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080079 end
80 end
81 end
82end
83
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +010084desc 'Build the Windows gRPC DLLs for Ruby'
85task 'dlls' do
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010086 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010087 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble17230442016-01-29 01:46:19 +010088
Yash Tibrewalc7eaff12017-10-02 16:07:28 -070089 env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DNTDDI_VERSION=0x06000000 -DUNICODE -D_UNICODE -Wno-unused-variable -Wno-unused-result -DCARES_STATICLIB -Wno-error=conversion -Wno-sign-compare -Wno-parentheses -Wno-format -DWIN32_LEAN_AND_MEAN" '
90 env += 'CFLAGS="-Wno-incompatible-pointer-types" '
91 env += 'CXXFLAGS="-std=c++11" '
Nicolas "Pixel" Noble0215d902016-01-31 09:57:07 +010092 env += 'LDFLAGS=-static '
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +010093 env += 'SYSTEM=MINGW32 '
94 env += 'EMBED_ZLIB=true '
Alexander Polcyn5fbc5772017-09-07 10:50:48 -070095 env += 'EMBED_OPENSSL=true '
Alexander Polcyn3a00f792017-09-07 11:24:43 -070096 env += 'EMBED_CARES=true '
97 env += 'BUILDDIR=/tmp '
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +010098 env += "V=#{verbose} "
murgatroid99c781f642017-01-17 11:47:06 -080099 out = GrpcBuildConfig::CORE_WINDOWS_DLL
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100100
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +0100101 w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' }
102 w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' }
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100103
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +0100104 [ w64, w32 ].each do |opt|
105 env_comp = "CC=#{opt[:cross]}-gcc "
Alexander Polcyn7aa184b2017-05-21 23:03:11 -0700106 env_comp += "CXX=#{opt[:cross]}-g++ "
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +0100107 env_comp += "LD=#{opt[:cross]}-gcc "
Muxi Yand5696eb2018-02-06 17:27:01 -0800108 docker_for_windows "gem update --system --no-ri --no-doc && #{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
Nicolas "Pixel" Noblef08399f2016-01-31 23:54:38 +0100109 end
110
111end
112
Nicolas "Pixel" Noble5219c6d2016-02-05 22:22:29 +0100113desc 'Build the native gem file under rake_compiler_dock'
114task 'gem:native' do
Nicolas "Pixel" Noble89d8ed12016-02-03 01:12:14 +0100115 verbose = ENV['V'] || '0'
Nicolas "Pixel" Noble09ac0a42016-01-31 09:24:11 +0100116
Alexander Polcyn38ba85c2016-08-29 16:59:23 -0700117 grpc_config = ENV['GRPC_CONFIG'] || 'opt'
118
Nicolas Noble86cbe302016-02-05 15:08:12 -0800119 if RUBY_PLATFORM =~ /darwin/
120 FileUtils.touch 'grpc_c.32.ruby'
121 FileUtils.touch 'grpc_c.64.ruby'
Muxi Yand5696eb2018-02-06 17:27:01 -0800122 unless '2.5' == /(\d+\.\d+)/.match(RUBY_VERSION).to_s
123 fail "rake gem:native (the rake task to build the binary packages) is being " \
124 "invoked on macos with ruby #{RUBY_VERSION}. The ruby macos artifact " \
125 "build should be running on ruby 2.5."
126 end
Alexander Polcyn8065a5e2018-01-03 14:47:26 -0800127 system "rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800128 else
129 Rake::Task['dlls'].execute
Muxi Yand5696eb2018-02-06 17:27:01 -0800130 docker_for_windows "gem update --system --no-ri --no-doc && bundle && rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
Nicolas Noble86cbe302016-02-05 15:08:12 -0800131 end
Nicolas "Pixel" Noblecb287a12016-01-28 05:01:01 +0100132end
133
Tim Emiolaf20d7602015-03-24 08:11:47 -0700134# Define dependencies between the suites.
135task 'suite:wrapper' => [:compile, :rubocop]
136task 'suite:idiomatic' => 'suite:wrapper'
137task 'suite:bidi' => 'suite:wrapper'
138task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700139task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -0800140
Tim Emiolaf20d7602015-03-24 08:11:47 -0700141desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -0700142task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -0800143task default: :all