From 4c667476a096f1f248d5cca0c3b510ea6040c984 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sun, 16 Feb 2020 21:12:09 +0100 Subject: [PATCH] Add ruby-2.7 to build process of binary gems for Windows and Linux 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 --- Rakefile | 31 ++++++++-- grpc.gemspec | 11 ++-- templates/grpc.gemspec.template | 11 ++-- third_party/rake-compiler-dock/Dockerfile | 22 -------- third_party/rake-compiler-dock/LICENSE.txt | 22 -------- third_party/rake-compiler-dock/README.md | 1 - tools/distrib/docker_for_windows.rb | 56 ------------------- tools/dockerfile/push_testing_images.sh | 2 +- .../artifacts/distribtest_targets.py | 2 +- 9 files changed, 41 insertions(+), 117 deletions(-) delete mode 100644 third_party/rake-compiler-dock/Dockerfile delete mode 100644 third_party/rake-compiler-dock/LICENSE.txt delete mode 100644 third_party/rake-compiler-dock/README.md delete mode 100755 tools/distrib/docker_for_windows.rb diff --git a/Rakefile b/Rakefile index f791d7e1c85..c8457c75549 100755 --- a/Rakefile +++ b/Rakefile @@ -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'] @@ -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' @@ -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 @@ -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 diff --git a/grpc.gemspec b/grpc.gemspec index 3cd9dcb4b58..8854858575a 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -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 @@ -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' diff --git a/templates/grpc.gemspec.template b/templates/grpc.gemspec.template index d3f3b9175a3..ba6ea179c5c 100644 --- a/templates/grpc.gemspec.template +++ b/templates/grpc.gemspec.template @@ -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 @@ -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' diff --git a/third_party/rake-compiler-dock/Dockerfile b/third_party/rake-compiler-dock/Dockerfile deleted file mode 100644 index dfc4f2ec7ea..00000000000 --- a/third_party/rake-compiler-dock/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM larskanis/rake-compiler-dock-mri:0.7.2 - -RUN find / -name rbconfig.rb | while read f ; do sed -i 's/0x0501/0x0600/' $f ; done -RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done -RUN find / -name libwinpthread.dll.a | xargs rm -RUN find / -name libwinpthread-1.dll | xargs rm -RUN find / -name *msvcrt-ruby*.dll.a | while read f ; do n=`echo $f | sed s/.dll//` ; mv $f $n ; done -RUN apt-get install -y g++-multilib - -# Make the system to have GLIBC 2.12 instead of 2.23 so that -# generated ruby package can run on CentOS 6 with GLIBC 2.12 -RUN sed -i 's/__GLIBC_MINOR__\t23/__GLIBC_MINOR__\t12/' /usr/include/features.h - -# Use posix pthread for mingw so that C++ standard library for thread could be -# available such as std::thread, std::mutex, so on. -# https://sourceware.org/pthreads-win32/ -RUN printf "1\n" | update-alternatives --config x86_64-w64-mingw32-gcc && \ - printf "1\n" | update-alternatives --config x86_64-w64-mingw32-g++ && \ - printf "1\n" | update-alternatives --config i686-w64-mingw32-gcc && \ - printf "1\n" | update-alternatives --config i686-w64-mingw32-g++ - -CMD bash diff --git a/third_party/rake-compiler-dock/LICENSE.txt b/third_party/rake-compiler-dock/LICENSE.txt deleted file mode 100644 index b884ba5396d..00000000000 --- a/third_party/rake-compiler-dock/LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015 Lars Kanis - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/third_party/rake-compiler-dock/README.md b/third_party/rake-compiler-dock/README.md deleted file mode 100644 index 0a9aa8ba78f..00000000000 --- a/third_party/rake-compiler-dock/README.md +++ /dev/null @@ -1 +0,0 @@ -This is a modified Dockerfile taken from [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) for the purpose of building gRPC's ruby gem. diff --git a/tools/distrib/docker_for_windows.rb b/tools/distrib/docker_for_windows.rb deleted file mode 100755 index 010e2067b81..00000000000 --- a/tools/distrib/docker_for_windows.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env ruby -# Copyright 2016 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -def grpc_root() - File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) -end - -def docker_for_windows_image() - require 'digest' - - dockerfile = File.join(grpc_root, 'third_party', 'rake-compiler-dock', 'Dockerfile') - dockerpath = File.dirname(dockerfile) - version = Digest::SHA1.file(dockerfile).hexdigest - image_name = 'rake-compiler-dock_' + version - # if "DOCKERHUB_ORGANIZATION" env is set, we try to pull the pre-built - # rake-compiler-dock image from dockerhub rather then building from scratch. - if ENV.has_key?('DOCKERHUB_ORGANIZATION') - image_name = ENV['DOCKERHUB_ORGANIZATION'] + '/' + image_name - cmd = "docker pull #{image_name}" - puts cmd - system cmd - raise "Failed to pull the docker image." unless $? == 0 - else - cmd = "docker build -t #{image_name} --file #{dockerfile} #{dockerpath}" - puts cmd - system cmd - raise "Failed to build the docker image." unless $? == 0 - end - image_name -end - -def docker_for_windows(args) - require 'rake_compiler_dock' - - args = 'bash -l' if args.empty? - - ENV['RAKE_COMPILER_DOCK_IMAGE'] = docker_for_windows_image - - RakeCompilerDock.sh args -end - -if __FILE__ == $0 - docker_for_windows $*.join(' ') -end diff --git a/tools/dockerfile/push_testing_images.sh b/tools/dockerfile/push_testing_images.sh index 2831e8ad0ca..2e0841a4db5 100755 --- a/tools/dockerfile/push_testing_images.sh +++ b/tools/dockerfile/push_testing_images.sh @@ -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 diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index e50b446eac6..7147f46d307 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -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'),