Skip to content

Commit 5a7c608

Browse files
committed
Support grpc gems after v1.48.0 for FIPS builds
grpc/grpc#27660 significantly modified the Ruby extconf.rb for TruffleRuby. Update the system SSL patch to enable FIPS builds to work for gems after 1.48.0.
1 parent 51c9411 commit 5a7c608

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb
2+
index e0974c4420..ec51a18bf7 100644
3+
--- a/src/ruby/ext/grpc/extconf.rb
4+
+++ b/src/ruby/ext/grpc/extconf.rb
5+
@@ -68,8 +68,12 @@ if apple_toolchain && !cross_compiling
6+
ENV['ARFLAGS'] = '-o'
7+
end
8+
9+
+# By default, use the system OpenSSL instead of BoringSSL. This is
10+
+# needed on systems that need to use a FIPS-approved OpenSSL or cannot
11+
+# compile the embedded BoringSSL module (e.g. s390x).
12+
+embed_ssl = ENV['EMBED_OPENSSL'] == 'true'
13+
# Don't embed on TruffleRuby (constant-time crypto is unsafe with Sulong, slow build times)
14+
-ENV['EMBED_OPENSSL'] = (RUBY_ENGINE != 'truffleruby').to_s
15+
+ENV['EMBED_OPENSSL'] = embed_ssl ? 'true' : 'false'
16+
# Don't embed on TruffleRuby (the system zlib is already linked for the zlib C extension, slow build times)
17+
ENV['EMBED_ZLIB'] = (RUBY_ENGINE != 'truffleruby').to_s
18+
19+
@@ -160,6 +164,7 @@ if linux && RUBY_ENGINE != 'truffleruby'
20+
$LDFLAGS << ' -static-libgcc -static-libstdc++'
21+
end
22+
$LDFLAGS << ' -static' if windows
23+
+$LDFLAGS << ' -lssl' unless embed_ssl
24+
25+
$CFLAGS << ' -std=c11 '
26+
$CFLAGS << ' -Wall '

config/software/ruby-grpc.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
build do
2828
block 're-install grpc gem with system OpenSSL' do
29+
env = with_standard_compiler_flags(with_embedded_path)
2930
gem_bin = embedded_bin('gem')
3031
command = %(#{embedded_bin('ruby')} -e "puts Gem::Specification.select { |x| x.name == 'grpc' }.map(&:version).uniq.map(&:to_s)")
3132
grpc_versions = shellout!(command).stdout || ""
@@ -35,20 +36,37 @@
3536

3637
warn "Multiple versions of gRPC found: #{grpc_versions.join(', ')}" if grpc_versions.length > 1
3738

38-
source = 'grpc-system-ssl.patch'
39-
_locations, patch_path = find_file('config/patches', source)
39+
patches = {}
4040

41-
raise "Missing gRPC patch: #{source}" unless patch_path
41+
grpc_versions.each do |version|
42+
source =
43+
# https://github.com/grpc/grpc/pull/27660 significantly changed the extconf.rb for TruffleRuby
44+
if Gem::Version.new(version) < Gem::Version.new('1.48.0')
45+
'grpc-system-ssl-1.42.0.patch'
46+
else
47+
'grpc-system-ssl-1.48.0.patch'
48+
end
49+
50+
_locations, patch_path = find_file('config/patches', source)
51+
patches[version] = patch_path
52+
end
4253

4354
shellout!("#{gem_bin} install --no-document gem-patch -v 0.1.6")
4455
shellout!("#{gem_bin} uninstall --force --all grpc")
4556

57+
# This works around an issue with the grpc gem attempting to include
58+
# /opt/gitlab/include headers instead of the vendored re2 headers:
59+
# https://github.com/grpc/grpc/pull/32580. This can be removed
60+
# after grpc is updated with that pull request.
61+
env['CPPFLAGS'] = "-Ithird_party/re2 #{env['CPPFLAGS']}"
62+
4663
grpc_versions.each do |version|
64+
patch_path = patches[version]
4765
gemfile = "grpc-#{version}.gem"
4866
shellout!("rm -f #{gemfile}")
4967
shellout!("#{gem_bin} fetch grpc -v #{version} --platform ruby")
5068
shellout!("#{gem_bin} patch -p1 #{gemfile} #{patch_path}")
51-
shellout!("#{gem_bin} install --platform ruby --no-document #{gemfile}")
69+
shellout!("#{gem_bin} install --platform ruby --no-document #{gemfile}", env: env)
5270
end
5371

5472
shellout!("#{gem_bin} uninstall gem-patch")

0 commit comments

Comments
 (0)