Skip to content

Commit 6452292

Browse files
Robert Marshallstanhu
andcommitted
Merge branch 'sh-workaround-grpc-re2-issues' into 'master'
Support grpc gem v1.48.0+ with workaround for native extension not compiling See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/6908 Merged-by: Robert Marshall <[email protected]> Approved-by: Robert Marshall <[email protected]> Co-authored-by: Stan Hu <[email protected]>
2 parents f4af923 + 5a7c608 commit 6452292

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-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/gitlab-rails.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@
113113

114114
bundle "config set --local gemfile #{gitlab_bundle_gemfile}" if gitlab_bundle_gemfile != 'Gemfile'
115115
bundle 'config force_ruby_platform true', env: env if OhaiHelper.ruby_native_gems_unsupported?
116+
117+
# This works around an issue with the grpc gem attempting to include
118+
# /opt/gitlab/include headers instead of the vendored re2 headers:
119+
# https://github.com/grpc/grpc/pull/32580. This can be removed
120+
# after grpc is updated with that pull request.
121+
env['CPPFLAGS'] = "-Ithird_party/re2 #{env['CPPFLAGS']}" if OhaiHelper.arm?
122+
116123
bundle 'config build.gpgme --use-system-libraries', env: env
117124
bundle "config build.nokogiri --use-system-libraries --with-xml2-include=#{install_dir}/embedded/include/libxml2 --with-xslt-include=#{install_dir}/embedded/include/libxslt", env: env
118125
bundle 'config build.grpc --with-ldflags=-Wl,--no-as-needed --with-dldflags=-latomic', env: env if OhaiHelper.raspberry_pi?

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)