From 34a66d94966eae3f5f9d2912c4a147b099846ed1 Mon Sep 17 00:00:00 2001 From: Johnny Shields Date: Fri, 15 Jul 2022 04:45:40 +0900 Subject: [PATCH] Ruby: Fixes for x64-mingw-ucrt (PR to master) (#30081) * Fix Ruby Windows 3.1 (x64-mingw-ucrt) build: - Pass-in CPPFLAG "GPR_WINDOWS_UCRT" to pickup correct shared object file. - Rename intermediate legacy SO file from 'grpc_c.64.ruby' to 'grpc_c.64-msvcrt.ruby' for clarity. - Add artifact target for Ruby x64-mingw-ucrt * Change CPP flag name --- Rakefile | 26 ++++++++++--------- src/ruby/ext/grpc/extconf.rb | 2 ++ src/ruby/ext/grpc/rb_loader.c | 8 ++++-- .../rake_arm64-darwin/Dockerfile | 2 +- .../rake_x64-mingw-ucrt/Dockerfile | 2 +- .../rake_x64-mingw32/Dockerfile | 2 +- .../rake_x86-linux/Dockerfile | 2 +- .../rake_x86-mingw32/Dockerfile | 2 +- .../rake_x86_64-darwin/Dockerfile | 2 +- .../rake_x86_64-linux/Dockerfile | 2 +- tools/run_tests/artifacts/artifact_targets.py | 1 + 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Rakefile b/Rakefile index 18bade5b805..07a9ecdffc3 100755 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext| |file| file.start_with?( "src/ruby/bin/", "src/ruby/ext/", "src/ruby/lib/", "src/ruby/pb/") } - spec.files += %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby grpc_c.64-ucrt.ruby ) + spec.files += %w( etc/roots.pem grpc_c.32-msvcrt.ruby grpc_c.64-msvcrt.ruby grpc_c.64-ucrt.ruby ) end end @@ -86,14 +86,16 @@ task 'dlls', [:plat] do |t, args| nproc_override = ENV['GRPC_RUBY_BUILD_PROCS'] || `nproc`.strip plat_list = args[:plat] - build_configs = [] - w64_ucrt = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-ucrt.ruby', platform: 'x64-mingw-ucrt' } - 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_ucrt, w64, w32].each do |config| + build_configs = [ + { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-ucrt.ruby', platform: 'x64-mingw-ucrt' }, + { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-msvcrt.ruby', platform: 'x64-mingw32' }, + { cross: 'i686-w64-mingw32', out: 'grpc_c.32-msvcrt.ruby', platform: 'x86-mingw32' } + ] + selected_build_configs = [] + build_configs.each do |config| if plat_list.include?(config[:platform]) # build the DLL (as grpc_c.*.ruby) - build_configs.append(config) + selected_build_configs.append(config) else # create an empty grpc_c.*.ruby file as a placeholder FileUtils.touch config[:out] @@ -122,7 +124,7 @@ task 'dlls', [:plat] do |t, args| prepare_ccache_cmd += "export PATH=\"$PATH:/usr/local/bin\" && " prepare_ccache_cmd += "source tools/internal_ci/helper_scripts/prepare_ccache_symlinks_rc " - build_configs.each do |opt| + selected_build_configs.each do |opt| env_comp = "CC=#{opt[:cross]}-gcc " env_comp += "CXX=#{opt[:cross]}-g++ " env_comp += "LD=#{opt[:cross]}-gcc " @@ -150,8 +152,8 @@ task 'gem:native', [:plat] do |t, args| fail "Cannot pass platform as an argument when on Darwin." end - FileUtils.touch 'grpc_c.32.ruby' - FileUtils.touch 'grpc_c.64.ruby' + FileUtils.touch 'grpc_c.32-msvcrt.ruby' + FileUtils.touch 'grpc_c.64-msvcrt.ruby' FileUtils.touch 'grpc_c.64-ucrt.ruby' unless '2.5' == /(\d+\.\d+)/.match(RUBY_VERSION).to_s fail "rake gem:native (the rake task to build the binary packages) is being " \ @@ -210,8 +212,8 @@ task 'gem:native', [:plat] do |t, args| # Truncate grpc_c.*.ruby files because they're for Windows only and we don't want # them to take up space in the gems that don't target windows. - File.truncate('grpc_c.32.ruby', 0) - File.truncate('grpc_c.64.ruby', 0) + File.truncate('grpc_c.32-msvcrt.ruby', 0) + File.truncate('grpc_c.64-msvcrt.ruby', 0) File.truncate('grpc_c.64-ucrt.ruby', 0) unix_platforms.each do |plat| diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 70979826dcf..a78d8b58b6d 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -16,6 +16,7 @@ require 'etc' require 'mkmf' windows = RUBY_PLATFORM =~ /mingw|mswin/ +windows_ucrt = RUBY_PLATFORM =~ /(mingw|mswin).*ucrt/ bsd = RUBY_PLATFORM =~ /bsd/ darwin = RUBY_PLATFORM =~ /darwin/ linux = RUBY_PLATFORM =~ /linux/ @@ -85,6 +86,7 @@ end env_append 'CPPFLAGS', '-DGPR_BACKWARDS_COMPATIBILITY_MODE' env_append 'CPPFLAGS', '-DGRPC_XDS_USER_AGENT_NAME_SUFFIX="\"RUBY\""' +env_append 'CPPFLAGS', '-DGRPC_RUBY_WINDOWS_UCRT' if windows_ucrt require_relative '../../lib/grpc/version' env_append 'CPPFLAGS', '-DGRPC_XDS_USER_AGENT_VERSION_SUFFIX="\"' + GRPC::VERSION + '\""' diff --git a/src/ruby/ext/grpc/rb_loader.c b/src/ruby/ext/grpc/rb_loader.c index dbca30bb643..1c698033fcb 100644 --- a/src/ruby/ext/grpc/rb_loader.c +++ b/src/ruby/ext/grpc/rb_loader.c @@ -23,9 +23,13 @@ int grpc_rb_load_core() { #if GPR_ARCH_64 - TCHAR fname[] = _T("grpc_c.64.ruby"); +#if GRPC_RUBY_WINDOWS_UCRT + TCHAR fname[] = _T("grpc_c.64-ucrt.ruby"); #else - TCHAR fname[] = _T("grpc_c.32.ruby"); + TCHAR fname[] = _T("grpc_c.64-msvcrt.ruby"); +#endif +#else + TCHAR fname[] = _T("grpc_c.32-msvcrt.ruby"); #endif HMODULE module = GetModuleHandle(_T("grpc_c.so")); TCHAR path[2048 + 32] = _T(""); diff --git a/third_party/rake-compiler-dock/rake_arm64-darwin/Dockerfile b/third_party/rake-compiler-dock/rake_arm64-darwin/Dockerfile index 5a94b536aba..0782c7eda0d 100644 --- a/third_party/rake-compiler-dock/rake_arm64-darwin/Dockerfile +++ b/third_party/rake-compiler-dock/rake_arm64-darwin/Dockerfile @@ -1 +1 @@ -FROM larskanis/rake-compiler-dock-mri-arm64-darwin:1.2.1 +FROM larskanis/rake-compiler-dock-mri-arm64-darwin:1.2.2 diff --git a/third_party/rake-compiler-dock/rake_x64-mingw-ucrt/Dockerfile b/third_party/rake-compiler-dock/rake_x64-mingw-ucrt/Dockerfile index 94daa620924..141b6f6822b 100644 --- a/third_party/rake-compiler-dock/rake_x64-mingw-ucrt/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x64-mingw-ucrt/Dockerfile @@ -1,4 +1,4 @@ -FROM larskanis/rake-compiler-dock-mri-x64-mingw-ucrt:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x64-mingw-ucrt:1.2.2 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done diff --git a/third_party/rake-compiler-dock/rake_x64-mingw32/Dockerfile b/third_party/rake-compiler-dock/rake_x64-mingw32/Dockerfile index 96c23e5797e..4c934177083 100644 --- a/third_party/rake-compiler-dock/rake_x64-mingw32/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x64-mingw32/Dockerfile @@ -1,4 +1,4 @@ -FROM larskanis/rake-compiler-dock-mri-x64-mingw32:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x64-mingw32:1.2.2 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done diff --git a/third_party/rake-compiler-dock/rake_x86-linux/Dockerfile b/third_party/rake-compiler-dock/rake_x86-linux/Dockerfile index e7fa5726290..6d7f1730382 100644 --- a/third_party/rake-compiler-dock/rake_x86-linux/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x86-linux/Dockerfile @@ -1,4 +1,4 @@ -FROM larskanis/rake-compiler-dock-mri-x86-linux:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x86-linux:1.2.2 #================= # Install ccache diff --git a/third_party/rake-compiler-dock/rake_x86-mingw32/Dockerfile b/third_party/rake-compiler-dock/rake_x86-mingw32/Dockerfile index 63f69dfa3e8..0b02ed70194 100644 --- a/third_party/rake-compiler-dock/rake_x86-mingw32/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x86-mingw32/Dockerfile @@ -1,4 +1,4 @@ -FROM larskanis/rake-compiler-dock-mri-x86-mingw32:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x86-mingw32:1.2.2 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done diff --git a/third_party/rake-compiler-dock/rake_x86_64-darwin/Dockerfile b/third_party/rake-compiler-dock/rake_x86_64-darwin/Dockerfile index 1579cda0f93..0418aff9da8 100644 --- a/third_party/rake-compiler-dock/rake_x86_64-darwin/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x86_64-darwin/Dockerfile @@ -1 +1 @@ -FROM larskanis/rake-compiler-dock-mri-x86_64-darwin:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x86_64-darwin:1.2.2 diff --git a/third_party/rake-compiler-dock/rake_x86_64-linux/Dockerfile b/third_party/rake-compiler-dock/rake_x86_64-linux/Dockerfile index f35690ae4e4..a82d97f89ef 100644 --- a/third_party/rake-compiler-dock/rake_x86_64-linux/Dockerfile +++ b/third_party/rake-compiler-dock/rake_x86_64-linux/Dockerfile @@ -1,4 +1,4 @@ -FROM larskanis/rake-compiler-dock-mri-x86_64-linux:1.2.1 +FROM larskanis/rake-compiler-dock-mri-x86_64-linux:1.2.2 #================= # Install ccache diff --git a/tools/run_tests/artifacts/artifact_targets.py b/tools/run_tests/artifacts/artifact_targets.py index 71a43b9b920..aecf20c1a57 100644 --- a/tools/run_tests/artifacts/artifact_targets.py +++ b/tools/run_tests/artifacts/artifact_targets.py @@ -486,6 +486,7 @@ def targets(): PythonArtifact('windows', 'x64', 'Python310', presubmit=True), RubyArtifact('linux', 'x86-mingw32', presubmit=True), RubyArtifact('linux', 'x64-mingw32', presubmit=True), + RubyArtifact('linux', 'x64-mingw-ucrt', presubmit=True), RubyArtifact('linux', 'x86_64-linux', presubmit=True), RubyArtifact('linux', 'x86-linux', presubmit=True), RubyArtifact('linux', 'x86_64-darwin', presubmit=True),