Skip to content

Commit 6d33399

Browse files
Support for prebuilt Ruby binary on x64-mingw-ucrt platform (grpc#29684)
* Add support for prebuilt Ruby binary on x64-mingw-ucrt platform, which is used for Windows RubyInstaller Ruby 3.1+
1 parent b7699ef commit 6d33399

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Rakefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext|
2828
ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
2929
ext.cross_compile = true
3030
ext.cross_platform = [
31-
'x86-mingw32', 'x64-mingw32',
31+
'x86-mingw32', 'x64-mingw32', 'x64-mingw-ucrt',
3232
'x86_64-linux', 'x86-linux',
3333
'x86_64-darwin', 'arm64-darwin',
3434
'universal-darwin'
@@ -38,7 +38,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext|
3838
|file| file.start_with?(
3939
"src/ruby/bin/", "src/ruby/ext/", "src/ruby/lib/", "src/ruby/pb/")
4040
}
41-
spec.files += %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
41+
spec.files += %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby grpc_c.64-ucrt.ruby )
4242
end
4343
end
4444

@@ -87,9 +87,10 @@ task 'dlls', [:plat] do |t, args|
8787
plat_list = args[:plat]
8888

8989
build_configs = []
90+
w64_ucrt = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64-ucrt.ruby', platform: 'x64-mingw-ucrt' }
9091
w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby', platform: 'x64-mingw32' }
9192
w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby', platform: 'x86-mingw32' }
92-
[w64, w32].each do |config|
93+
[w64_ucrt, w64, w32].each do |config|
9394
if plat_list.include?(config[:platform])
9495
# build the DLL (as grpc_c.*.ruby)
9596
build_configs.append(config)
@@ -151,6 +152,7 @@ task 'gem:native', [:plat] do |t, args|
151152

152153
FileUtils.touch 'grpc_c.32.ruby'
153154
FileUtils.touch 'grpc_c.64.ruby'
155+
FileUtils.touch 'grpc_c.64-ucrt.ruby'
154156
unless '2.5' == /(\d+\.\d+)/.match(RUBY_VERSION).to_s
155157
fail "rake gem:native (the rake task to build the binary packages) is being " \
156158
"invoked on macos with ruby #{RUBY_VERSION}. The ruby macos artifact " \
@@ -168,7 +170,7 @@ task 'gem:native', [:plat] do |t, args|
168170
prepare_ccache_cmd += "export PATH=\"$PATH:/usr/local/bin\" && "
169171
prepare_ccache_cmd += "source tools/internal_ci/helper_scripts/prepare_ccache_symlinks_rc "
170172

171-
supported_windows_platforms = ['x86-mingw32', 'x64-mingw32']
173+
supported_windows_platforms = ['x86-mingw32', 'x64-mingw32', 'x64-mingw-ucrt']
172174
supported_unix_platforms = ['x86_64-linux', 'x86-linux', 'x86_64-darwin', 'arm64-darwin']
173175
supported_platforms = supported_windows_platforms + supported_unix_platforms
174176

@@ -210,6 +212,7 @@ task 'gem:native', [:plat] do |t, args|
210212
# them to take up space in the gems that don't target windows.
211213
File.truncate('grpc_c.32.ruby', 0)
212214
File.truncate('grpc_c.64.ruby', 0)
215+
File.truncate('grpc_c.64-ucrt.ruby', 0)
213216

214217
unix_platforms.each do |plat|
215218
run_rake_compiler(plat, <<~EOT)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM larskanis/rake-compiler-dock-mri-x64-mingw-ucrt:1.2.1
2+
3+
RUN find / -name win32.h | while read f ; do sed -i 's/gettimeofday/rb_gettimeofday/' $f ; done
4+
5+
#=================
6+
# Install ccache
7+
8+
# Install ccache from source since ccache 3.x packaged with most linux distributions
9+
# does not support Redis backend for caching.
10+
RUN curl -sSL -o ccache.tar.gz https://github.com/ccache/ccache/releases/download/v4.5.1/ccache-4.5.1.tar.gz \
11+
&& tar -zxf ccache.tar.gz \
12+
&& cd ccache-4.5.1 \
13+
&& mkdir build && cd build \
14+
&& cmake -DCMAKE_BUILD_TYPE=Release -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON .. \
15+
&& make -j4 && make install \
16+
&& cd ../.. \
17+
&& rm -rf ccache-4.5.1 ccache.tar.gz

0 commit comments

Comments
 (0)