Skip to content

Commit 2c312fd

Browse files
committed
ruby: add "x86_64-darwin" and "arm64-darwin" platform gems
Using RCD for these platforms 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#25755 - grpc#25756
1 parent b8aeb8b commit 2c312fd

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
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', 'arm64-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', 'arm64-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
@@ -102,7 +103,7 @@
102103
create_makefile(output)
103104

104105
strip_tool = RbConfig::CONFIG['STRIP']
105-
strip_tool = 'strip -x' if darwin
106+
strip_tool += ' -x' if darwin
106107

107108
if grpc_config == 'opt'
108109
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-arm64-darwin:1.1.0
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)