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
pull/30298/head
Johnny Shields 2 years ago committed by GitHub
parent 6bf7dfc975
commit 34a66d9496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      Rakefile
  2. 2
      src/ruby/ext/grpc/extconf.rb
  3. 8
      src/ruby/ext/grpc/rb_loader.c
  4. 2
      third_party/rake-compiler-dock/rake_arm64-darwin/Dockerfile
  5. 2
      third_party/rake-compiler-dock/rake_x64-mingw-ucrt/Dockerfile
  6. 2
      third_party/rake-compiler-dock/rake_x64-mingw32/Dockerfile
  7. 2
      third_party/rake-compiler-dock/rake_x86-linux/Dockerfile
  8. 2
      third_party/rake-compiler-dock/rake_x86-mingw32/Dockerfile
  9. 2
      third_party/rake-compiler-dock/rake_x86_64-darwin/Dockerfile
  10. 2
      third_party/rake-compiler-dock/rake_x86_64-linux/Dockerfile
  11. 1
      tools/run_tests/artifacts/artifact_targets.py

@ -38,7 +38,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext|
|file| file.start_with?( |file| file.start_with?(
"src/ruby/bin/", "src/ruby/ext/", "src/ruby/lib/", "src/ruby/pb/") "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
end end
@ -86,14 +86,16 @@ task 'dlls', [:plat] do |t, args|
nproc_override = ENV['GRPC_RUBY_BUILD_PROCS'] || `nproc`.strip nproc_override = ENV['GRPC_RUBY_BUILD_PROCS'] || `nproc`.strip
plat_list = args[:plat] plat_list = args[:plat]
build_configs = [] build_configs = [
w64_ucrt = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-ucrt.ruby', platform: 'x64-mingw-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' } { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-msvcrt.ruby', platform: 'x64-mingw32' },
w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby', platform: 'x86-mingw32' } { cross: 'i686-w64-mingw32', out: 'grpc_c.32-msvcrt.ruby', platform: 'x86-mingw32' }
[w64_ucrt, w64, w32].each do |config| ]
selected_build_configs = []
build_configs.each do |config|
if plat_list.include?(config[:platform]) if plat_list.include?(config[:platform])
# build the DLL (as grpc_c.*.ruby) # build the DLL (as grpc_c.*.ruby)
build_configs.append(config) selected_build_configs.append(config)
else else
# create an empty grpc_c.*.ruby file as a placeholder # create an empty grpc_c.*.ruby file as a placeholder
FileUtils.touch config[:out] 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 += "export PATH=\"$PATH:/usr/local/bin\" && "
prepare_ccache_cmd += "source tools/internal_ci/helper_scripts/prepare_ccache_symlinks_rc " 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 = "CC=#{opt[:cross]}-gcc "
env_comp += "CXX=#{opt[:cross]}-g++ " env_comp += "CXX=#{opt[:cross]}-g++ "
env_comp += "LD=#{opt[:cross]}-gcc " 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." fail "Cannot pass platform as an argument when on Darwin."
end end
FileUtils.touch 'grpc_c.32.ruby' FileUtils.touch 'grpc_c.32-msvcrt.ruby'
FileUtils.touch 'grpc_c.64.ruby' FileUtils.touch 'grpc_c.64-msvcrt.ruby'
FileUtils.touch 'grpc_c.64-ucrt.ruby' FileUtils.touch 'grpc_c.64-ucrt.ruby'
unless '2.5' == /(\d+\.\d+)/.match(RUBY_VERSION).to_s unless '2.5' == /(\d+\.\d+)/.match(RUBY_VERSION).to_s
fail "rake gem:native (the rake task to build the binary packages) is being " \ 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 # 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. # them to take up space in the gems that don't target windows.
File.truncate('grpc_c.32.ruby', 0) File.truncate('grpc_c.32-msvcrt.ruby', 0)
File.truncate('grpc_c.64.ruby', 0) File.truncate('grpc_c.64-msvcrt.ruby', 0)
File.truncate('grpc_c.64-ucrt.ruby', 0) File.truncate('grpc_c.64-ucrt.ruby', 0)
unix_platforms.each do |plat| unix_platforms.each do |plat|

@ -16,6 +16,7 @@ require 'etc'
require 'mkmf' require 'mkmf'
windows = RUBY_PLATFORM =~ /mingw|mswin/ windows = RUBY_PLATFORM =~ /mingw|mswin/
windows_ucrt = RUBY_PLATFORM =~ /(mingw|mswin).*ucrt/
bsd = RUBY_PLATFORM =~ /bsd/ bsd = RUBY_PLATFORM =~ /bsd/
darwin = RUBY_PLATFORM =~ /darwin/ darwin = RUBY_PLATFORM =~ /darwin/
linux = RUBY_PLATFORM =~ /linux/ linux = RUBY_PLATFORM =~ /linux/
@ -85,6 +86,7 @@ end
env_append 'CPPFLAGS', '-DGPR_BACKWARDS_COMPATIBILITY_MODE' env_append 'CPPFLAGS', '-DGPR_BACKWARDS_COMPATIBILITY_MODE'
env_append 'CPPFLAGS', '-DGRPC_XDS_USER_AGENT_NAME_SUFFIX="\"RUBY\""' 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' require_relative '../../lib/grpc/version'
env_append 'CPPFLAGS', '-DGRPC_XDS_USER_AGENT_VERSION_SUFFIX="\"' + GRPC::VERSION + '\""' env_append 'CPPFLAGS', '-DGRPC_XDS_USER_AGENT_VERSION_SUFFIX="\"' + GRPC::VERSION + '\""'

@ -23,9 +23,13 @@
int grpc_rb_load_core() { int grpc_rb_load_core() {
#if GPR_ARCH_64 #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 #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 #endif
HMODULE module = GetModuleHandle(_T("grpc_c.so")); HMODULE module = GetModuleHandle(_T("grpc_c.so"));
TCHAR path[2048 + 32] = _T(""); TCHAR path[2048 + 32] = _T("");

@ -1 +1 @@
FROM larskanis/rake-compiler-dock-mri-arm64-darwin:1.2.1 FROM larskanis/rake-compiler-dock-mri-arm64-darwin:1.2.2

@ -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 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done

@ -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 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done

@ -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 # Install ccache

@ -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 RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done

@ -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

@ -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 # Install ccache

@ -486,6 +486,7 @@ def targets():
PythonArtifact('windows', 'x64', 'Python310', presubmit=True), PythonArtifact('windows', 'x64', 'Python310', presubmit=True),
RubyArtifact('linux', 'x86-mingw32', presubmit=True), RubyArtifact('linux', 'x86-mingw32', presubmit=True),
RubyArtifact('linux', 'x64-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_64-linux', presubmit=True),
RubyArtifact('linux', 'x86-linux', presubmit=True), RubyArtifact('linux', 'x86-linux', presubmit=True),
RubyArtifact('linux', 'x86_64-darwin', presubmit=True), RubyArtifact('linux', 'x86_64-darwin', presubmit=True),

Loading…
Cancel
Save