Skip to content

Commit 8aac238

Browse files
committed
ruby: add "x86_64-darwin" platform gem
Using RCD for this platform unifies the Darwin native gem build process with the Linux native gems, which should help avoid inconsistencies in packaging that result in issues like the missing Ruby 3.0 binaries in grpc#25060. Please note that this change leaves the "universal-darwin" platform native gem untouched, but provides a path forward if the project ever decides to drop "universal" binary support. Related to: - grpc#25429 - grpc#25756
1 parent 9a1f3c6 commit 8aac238

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Rakefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext|
3030
ext.cross_platform = [
3131
'x86-mingw32', 'x64-mingw32',
3232
'x86_64-linux', 'x86-linux',
33+
'x86_64-darwin',
3334
'universal-darwin'
3435
]
3536
ext.cross_compiling do |spec|
@@ -143,7 +144,7 @@ task 'gem:native' do
143144
# Truncate grpc_c.*.ruby files because they're for Windows only.
144145
File.truncate('grpc_c.32.ruby', 0)
145146
File.truncate('grpc_c.64.ruby', 0)
146-
['x86_64-linux', 'x86-linux'].each do |plat|
147+
['x86_64-linux', 'x86-linux', 'x86_64-darwin'].each do |plat|
147148
run_rake_compiler(plat, <<~EOT)
148149
gem update --system --no-document && \
149150
bundle && \

src/ruby/ext/grpc/extconf.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
bsd = RUBY_PLATFORM =~ /bsd/
2020
darwin = RUBY_PLATFORM =~ /darwin/
2121
linux = RUBY_PLATFORM =~ /linux/
22+
cross_compiling = ENV['RCD_HOST_RUBY_VERSION'] # set by rake-compiler-dock in build containers
2223

2324
grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
2425

@@ -39,7 +40,7 @@
3940
ENV['LD'] = ENV['CC']
4041
end
4142

42-
if darwin
43+
if darwin && !cross_compiling
4344
ENV['AR'] = 'libtool'
4445
ENV['ARFLAGS'] = '-o'
4546
end
@@ -49,7 +50,7 @@
4950
ENV['EMBED_CARES'] = 'true'
5051

5152
ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG']
52-
if darwin
53+
if darwin && !cross_compiling
5354
if RUBY_PLATFORM =~ /arm64/
5455
ENV['ARCH_FLAGS'] = '-arch arm64'
5556
else
@@ -104,7 +105,7 @@
104105
create_makefile(output)
105106

106107
strip_tool = RbConfig::CONFIG['STRIP']
107-
strip_tool = 'strip -x' if darwin
108+
strip_tool += ' -x' if darwin
108109

109110
if grpc_config == 'opt'
110111
File.open('Makefile.new', 'w') do |o|

templates/src/ruby/ext/grpc/extconf.rb.template

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
bsd = RUBY_PLATFORM =~ /bsd/
2222
darwin = RUBY_PLATFORM =~ /darwin/
2323
linux = RUBY_PLATFORM =~ /linux/
24+
cross_compiling = ENV['RCD_HOST_RUBY_VERSION'] # set by rake-compiler-dock in build containers
2425

2526
grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
2627

@@ -41,7 +42,7 @@
4142
ENV['LD'] = ENV['CC']
4243
end
4344

44-
if darwin
45+
if darwin && !cross_compiling
4546
ENV['AR'] = 'libtool'
4647
ENV['ARFLAGS'] = '-o'
4748
end
@@ -51,7 +52,7 @@
5152
ENV['EMBED_CARES'] = 'true'
5253

5354
ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG']
54-
if darwin
55+
if darwin && !cross_compiling
5556
if RUBY_PLATFORM =~ /arm64/
5657
ENV['ARCH_FLAGS'] = '-arch arm64'
5758
else
@@ -106,7 +107,7 @@
106107
create_makefile(output)
107108

108109
strip_tool = RbConfig::CONFIG['STRIP']
109-
strip_tool = 'strip -x' if darwin
110+
strip_tool += ' -x' if darwin
110111

111112
if grpc_config == 'opt'
112113
File.open('Makefile.new', 'w') do |o|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM larskanis/rake-compiler-dock-mri-x86_64-darwin:1.1.0

0 commit comments

Comments
 (0)