nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 1 | # -*- ruby -*- |
| 2 | require 'rake/extensiontask' |
| 3 | require 'rspec/core/rake_task' |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 4 | require 'rubocop/rake_task' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 5 | require 'bundler/gem_tasks' |
Nicolas Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 6 | require 'fileutils' |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 7 | |
murgatroid99 | c781f64 | 2017-01-17 11:47:06 -0800 | [diff] [blame] | 8 | require_relative 'build_config.rb' |
| 9 | |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 10 | load 'tools/distrib/docker_for_windows.rb' |
| 11 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 12 | # Add rubocop style checking tasks |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 13 | RuboCop::RakeTask.new(:rubocop) do |task| |
| 14 | task.options = ['-c', 'src/ruby/.rubocop.yml'] |
Alexander Polcyn | 4e60675 | 2017-03-19 23:32:54 -0700 | [diff] [blame] | 15 | # 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'] |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 17 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 18 | |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 19 | spec = Gem::Specification.load('grpc.gemspec') |
| 20 | |
| 21 | Gem::PackageTask.new(spec) do |pkg| |
| 22 | end |
| 23 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 24 | # Add the extension compiler task |
Nicolas "Pixel" Noble | eade6e0 | 2016-01-29 22:53:31 +0100 | [diff] [blame] | 25 | Rake::ExtensionTask.new('grpc_c', spec) do |ext| |
Alexander Polcyn | a803c03 | 2018-03-06 16:16:57 -0800 | [diff] [blame] | 26 | 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 |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 32 | 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" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 35 | ext.cross_compile = true |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame] | 36 | ext.cross_platform = [ |
| 37 | 'x86-mingw32', 'x64-mingw32', |
| 38 | 'x86_64-linux', 'x86-linux', |
Nicolas Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 39 | 'universal-darwin' |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame] | 40 | ] |
Nicolas "Pixel" Noble | d51d121 | 2016-01-31 11:33:19 +0100 | [diff] [blame] | 41 | 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 |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 48 | end |
| 49 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 50 | # Define the test suites |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 51 | SPEC_SUITES = [ |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 52 | { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, |
| 53 | { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 54 | tags: ['~bidi', '~server'] }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 55 | { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 56 | tag: 'bidi' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 57 | { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 58 | tag: 'server' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 59 | { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 60 | ] |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 61 | namespace :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 Emiola | c85c1ae | 2015-04-17 18:12:32 -0700 | [diff] [blame] | 65 | ENV['COVERAGE_NAME'] = suite[:id].to_s |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 66 | spec_files = [] |
| 67 | suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 68 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 69 | if suite[:dir] |
| 70 | suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } |
| 71 | end |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 72 | helper = 'src/ruby/spec/spec_helper.rb' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 73 | spec_files << helper unless spec_files.include?(helper) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 74 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 75 | 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(' ') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 79 | end |
| 80 | end |
| 81 | end |
| 82 | end |
| 83 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 84 | desc 'Build the Windows gRPC DLLs for Ruby' |
| 85 | task 'dlls' do |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 86 | grpc_config = ENV['GRPC_CONFIG'] || 'opt' |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 87 | verbose = ENV['V'] || '0' |
Nicolas "Pixel" Noble | 1723044 | 2016-01-29 01:46:19 +0100 | [diff] [blame] | 88 | |
Yash Tibrewal | c7eaff1 | 2017-10-02 16:07:28 -0700 | [diff] [blame] | 89 | 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" Noble | 0215d90 | 2016-01-31 09:57:07 +0100 | [diff] [blame] | 92 | env += 'LDFLAGS=-static ' |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 93 | env += 'SYSTEM=MINGW32 ' |
| 94 | env += 'EMBED_ZLIB=true ' |
Alexander Polcyn | 5fbc577 | 2017-09-07 10:50:48 -0700 | [diff] [blame] | 95 | env += 'EMBED_OPENSSL=true ' |
Alexander Polcyn | 3a00f79 | 2017-09-07 11:24:43 -0700 | [diff] [blame] | 96 | env += 'EMBED_CARES=true ' |
| 97 | env += 'BUILDDIR=/tmp ' |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 98 | env += "V=#{verbose} " |
murgatroid99 | c781f64 | 2017-01-17 11:47:06 -0800 | [diff] [blame] | 99 | out = GrpcBuildConfig::CORE_WINDOWS_DLL |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 100 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 101 | w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } |
| 102 | w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 103 | |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 104 | [ w64, w32 ].each do |opt| |
| 105 | env_comp = "CC=#{opt[:cross]}-gcc " |
Alexander Polcyn | 7aa184b | 2017-05-21 23:03:11 -0700 | [diff] [blame] | 106 | env_comp += "CXX=#{opt[:cross]}-g++ " |
Nicolas "Pixel" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 107 | env_comp += "LD=#{opt[:cross]}-gcc " |
Muxi Yan | d5696eb | 2018-02-06 17:27:01 -0800 | [diff] [blame] | 108 | 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" Noble | f08399f | 2016-01-31 23:54:38 +0100 | [diff] [blame] | 109 | end |
| 110 | |
| 111 | end |
| 112 | |
Nicolas "Pixel" Noble | 5219c6d | 2016-02-05 22:22:29 +0100 | [diff] [blame] | 113 | desc 'Build the native gem file under rake_compiler_dock' |
| 114 | task 'gem:native' do |
Nicolas "Pixel" Noble | 89d8ed1 | 2016-02-03 01:12:14 +0100 | [diff] [blame] | 115 | verbose = ENV['V'] || '0' |
Nicolas "Pixel" Noble | 09ac0a4 | 2016-01-31 09:24:11 +0100 | [diff] [blame] | 116 | |
Alexander Polcyn | 38ba85c | 2016-08-29 16:59:23 -0700 | [diff] [blame] | 117 | grpc_config = ENV['GRPC_CONFIG'] || 'opt' |
| 118 | |
Nicolas Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 119 | if RUBY_PLATFORM =~ /darwin/ |
| 120 | FileUtils.touch 'grpc_c.32.ruby' |
| 121 | FileUtils.touch 'grpc_c.64.ruby' |
Muxi Yan | d5696eb | 2018-02-06 17:27:01 -0800 | [diff] [blame] | 122 | 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 Polcyn | 8065a5e | 2018-01-03 14:47:26 -0800 | [diff] [blame] | 127 | 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 Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 128 | else |
| 129 | Rake::Task['dlls'].execute |
Muxi Yan | d5696eb | 2018-02-06 17:27:01 -0800 | [diff] [blame] | 130 | 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 Noble | 86cbe30 | 2016-02-05 15:08:12 -0800 | [diff] [blame] | 131 | end |
Nicolas "Pixel" Noble | cb287a1 | 2016-01-28 05:01:01 +0100 | [diff] [blame] | 132 | end |
| 133 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 134 | # Define dependencies between the suites. |
| 135 | task 'suite:wrapper' => [:compile, :rubocop] |
| 136 | task 'suite:idiomatic' => 'suite:wrapper' |
| 137 | task 'suite:bidi' => 'suite:wrapper' |
| 138 | task 'suite:server' => 'suite:wrapper' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 139 | task 'suite:pb' => 'suite:server' |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 140 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 141 | desc 'Compiles the gRPC extension then runs all the tests' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 142 | task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 143 | task default: :all |