Skip to content

Commit

Permalink
Add ruby-2.7 to build process of binary gems for Windows and Linux
Browse files Browse the repository at this point in the history
With rake-compiler-dock-1.0.1 there's no need to use a derived Dockerfile.
The standard RCD image can be used instead.
The only issue is with conflicting declarations of gettimeofday(), which can be easily worked around by patching win32.h before the build.

Fixes #21514
  • Loading branch information
larskanis committed Feb 16, 2020
1 parent 64fb7d4 commit 4c66747
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 117 deletions.
31 changes: 25 additions & 6 deletions Rakefile
Expand Up @@ -7,8 +7,6 @@ require 'fileutils'

require_relative 'build_config.rb'

load 'tools/distrib/docker_for_windows.rb'

# Add rubocop style checking tasks
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['-c', 'src/ruby/.rubocop.yml']
Expand Down Expand Up @@ -83,6 +81,8 @@ end

desc 'Build the Windows gRPC DLLs for Ruby'
task 'dlls' do
require 'rake_compiler_dock'

grpc_config = ENV['GRPC_CONFIG'] || 'opt'
verbose = ENV['V'] || '0'

Expand All @@ -98,15 +98,20 @@ task 'dlls' do
env += "V=#{verbose} "
out = GrpcBuildConfig::CORE_WINDOWS_DLL

w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' }
w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' }
w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby', platform: 'x64-mingw32' }
w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby', platform: 'x86-mingw32' }

[ w64, w32 ].each do |opt|
env_comp = "CC=#{opt[:cross]}-gcc "
env_comp += "CXX=#{opt[:cross]}-g++ "
env_comp += "LD=#{opt[:cross]}-gcc "
env_comp += "LDXX=#{opt[:cross]}-g++ "
docker_for_windows "gem update --system --no-document && #{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
RakeCompilerDock.sh <<-EOT, platform: opt[:platform]
gem update --system --no-document && \
#{env} #{env_comp} make -j`nproc` #{out} && \
#{opt[:cross]}-strip -x -S #{out} && \
cp #{out} #{opt[:out]}
EOT
end

end
Expand All @@ -127,8 +132,22 @@ task 'gem:native' do
end
system "rake cross native gem RUBY_CC_VERSION=2.6.0:2.5.0:2.4.0:2.3.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
else
require 'rake_compiler_dock'

Rake::Task['dlls'].execute
docker_for_windows "gem update --system --no-document && bundle && rake cross native gem RUBY_CC_VERSION=2.6.0:2.5.0:2.4.0:2.3.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}"
['x86-mingw32', 'x64-mingw32', 'x86_64-linux', 'x86-linux'].each do |plat|
RakeCompilerDock.sh <<-EOT, platform: plat
# Avoid conflicting declarations of gettimeofday: https://github.com/rake-compiler/rake-compiler-dock/issues/32
find /usr/local/rake-compiler -name win32.h | while read f ; do sudo sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done && \
gem update --system --no-document && \
bundle && \
rake native:#{plat} pkg/#{spec.full_name}-#{plat}.gem \
RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0:2.3.0 \
V=#{verbose} \
GRPC_CONFIG=#{grpc_config}
EOT
end
end
end

Expand Down
11 changes: 7 additions & 4 deletions grpc.gemspec
Expand Up @@ -19,7 +19,10 @@ Gem::Specification.new do |s|
s.files += %w( etc/roots.pem )
s.files += Dir.glob('src/ruby/bin/**/*')
s.files += Dir.glob('src/ruby/ext/**/*')
s.files += Dir.glob('src/ruby/lib/**/*')
s.files += Dir.glob('src/ruby/lib/**/*').reject do |f|
# Binaries are included by rake-compiler and would lead to circular dependencies here
File.fnmatch("**/?.?/grpc_c.so", f)
end
s.files += Dir.glob('src/ruby/pb/**/*').reject do |f|
f.match(%r{^src/ruby/pb/test})
end
Expand All @@ -36,9 +39,9 @@ Gem::Specification.new do |s|
s.add_development_dependency 'facter', '~> 2.4'
s.add_development_dependency 'logging', '~> 2.0'
s.add_development_dependency 'simplecov', '~> 0.14.1'
s.add_development_dependency 'rake', '~> 12.0'
s.add_development_dependency 'rake-compiler', '~> 1.0'
s.add_development_dependency 'rake-compiler-dock', '~> 0.5.1'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rake-compiler', '~> 1.1'
s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
s.add_development_dependency 'rspec', '~> 3.6'
s.add_development_dependency 'rubocop', '~> 0.49.1'
s.add_development_dependency 'signet', '~> 0.7'
Expand Down
11 changes: 7 additions & 4 deletions templates/grpc.gemspec.template
Expand Up @@ -21,7 +21,10 @@
s.files += %w( etc/roots.pem )
s.files += Dir.glob('src/ruby/bin/**/*')
s.files += Dir.glob('src/ruby/ext/**/*')
s.files += Dir.glob('src/ruby/lib/**/*')
s.files += Dir.glob('src/ruby/lib/**/*').reject do |f|
# Binaries are included by rake-compiler and would lead to circular dependencies here
File.fnmatch("**/?.?/grpc_c.so", f)
end
s.files += Dir.glob('src/ruby/pb/**/*').reject do |f|
f.match(%r{^src/ruby/pb/test})
end
Expand All @@ -38,9 +41,9 @@
s.add_development_dependency 'facter', '~> 2.4'
s.add_development_dependency 'logging', '~> 2.0'
s.add_development_dependency 'simplecov', '~> 0.14.1'
s.add_development_dependency 'rake', '~> 12.0'
s.add_development_dependency 'rake-compiler', '~> 1.0'
s.add_development_dependency 'rake-compiler-dock', '~> 0.5.1'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rake-compiler', '~> 1.1'
s.add_development_dependency 'rake-compiler-dock', '~> 1.0'
s.add_development_dependency 'rspec', '~> 3.6'
s.add_development_dependency 'rubocop', '~> 0.49.1'
s.add_development_dependency 'signet', '~> 0.7'
Expand Down
22 changes: 0 additions & 22 deletions third_party/rake-compiler-dock/Dockerfile

This file was deleted.

22 changes: 0 additions & 22 deletions third_party/rake-compiler-dock/LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion third_party/rake-compiler-dock/README.md

This file was deleted.

56 changes: 0 additions & 56 deletions tools/distrib/docker_for_windows.rb

This file was deleted.

2 changes: 1 addition & 1 deletion tools/dockerfile/push_testing_images.sh
Expand Up @@ -29,7 +29,7 @@ cd -

DOCKERHUB_ORGANIZATION=grpctesting

for DOCKERFILE_DIR in tools/dockerfile/test/* tools/dockerfile/grpc_artifact_* tools/dockerfile/interoptest/* tools/dockerfile/distribtest/* third_party/rake-compiler-dock
for DOCKERFILE_DIR in tools/dockerfile/test/* tools/dockerfile/grpc_artifact_* tools/dockerfile/interoptest/* tools/dockerfile/distribtest/*
do
# Generate image name based on Dockerfile checksum. That works well as long
# as can count on dockerfiles being written in a way that changing the logical
Expand Down
2 changes: 1 addition & 1 deletion tools/run_tests/artifacts/distribtest_targets.py
Expand Up @@ -340,7 +340,7 @@ def targets():
RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_4'),
RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_5'),
RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_6'),
# RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_7'),
RubyDistribTest('linux', 'x64', 'jessie', ruby_version='ruby_2_7'),
RubyDistribTest('linux', 'x64', 'centos6'),
RubyDistribTest('linux', 'x64', 'centos7'),
RubyDistribTest('linux', 'x64', 'fedora23'),
Expand Down

0 comments on commit 4c66747

Please sign in to comment.