Skip to content

Commit fc83ef8

Browse files
committed
(PA-6422) Only install ffi gem once
Previously, we were installing the ffi gem twice, but with different arguments, once in the base-rubygem component and again in the rubygem-ffi component. For example: /opt/puppetlabs/puppet/bin/gem install --no-document --local ffi-1.15.5.gem && \ /opt/puppetlabs/puppet/bin/gem install --no-document --local ffi-1.15.5.gem -- --enable-system-ffi Building native extensions. This could take a while... Successfully installed ffi-1.15.5 1 gem installed Building native extensions with: '--enable-system-ffi' This could take a while... Successfully installed ffi-1.15.5 1 gem installed Now we only execute the gem install command once. On Windows, we install ffi gems with precompiled binaries (so we don't need to specify enable/disable flags). On non-Windows, we continue to pass enable/disable based on the ruby version.
1 parent c54c2a6 commit fc83ef8

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

configs/components/rubygem-ffi.rb

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,16 @@
1515
pkg.sha256sum '6f2ed2fa68047962d6072b964420cba91d82ce6fa8ee251950c17fca6af3c2a0'
1616
end
1717

18-
instance_eval File.read('configs/components/_base-rubygem.rb')
19-
2018
rb_major_minor_version = settings[:ruby_version].to_f
2119

22-
# Prior to ruby 3.2, both ruby and the ffi gem vendored a version of libffi.
23-
# If libffi happened to be installed in /usr/lib, then the ffi gem preferred
24-
# that instead of building libffi itself. To ensure consistency, we use
25-
# --disable-system-ffi so that the ffi gem *always* builds libffi, then
26-
# builds the ffi_c native extension and links it against libffi.so.
27-
#
28-
# In ruby 3.2 and up, libffi is no longer vendored. So we created a separate
29-
# libffi vanagon component which is built before ruby. The ffi gem still
30-
# vendors libffi, so we use the --enable-system-ffi option to ensure the ffi
31-
# gem *always* uses the libffi.so we already built. Note the term "system" is
32-
# misleading, because we override PKG_CONFIG_PATH below so that our libffi.so
33-
# is preferred, not the one in /usr/lib.
34-
if rb_major_minor_version > 2.7
35-
pkg.install do
36-
"#{settings[:gem_install]} ffi-#{pkg.get_version}.gem -- --enable-system-ffi"
37-
end
38-
else
39-
pkg.install do
40-
"#{settings[:gem_install]} ffi-#{pkg.get_version}.gem -- --disable-system-ffi"
41-
end
42-
end
43-
4420
# Windows versions of the FFI gem have custom filenames, so we overwite the
4521
# defaults that _base-rubygem provides here, just for Windows for Ruby < 3.2
4622
if platform.is_windows? && rb_major_minor_version < 3.2
4723
# Pin this if lower than Ruby 2.7
4824
pkg.version '1.9.25' if rb_major_minor_version < 2.7
4925

26+
instance_eval File.read('configs/components/_base-rubygem.rb')
27+
5028
# Vanagon's `pkg.mirror` is additive, and the _base_rubygem sets the
5129
# non-Windows gem as the first mirror, which is incorrect. We need to unset
5230
# the list of mirrors before adding the Windows-appropriate ones here:
@@ -81,6 +59,25 @@
8159
pkg.install do
8260
"#{settings[:gem_install]} ffi-#{pkg.get_version}-#{platform.architecture}-mingw32.gem"
8361
end
62+
else
63+
# Prior to ruby 3.2, both ruby and the ffi gem vendored a version of libffi.
64+
# If libffi happened to be installed in /usr/lib, then the ffi gem preferred
65+
# that instead of building libffi itself. To ensure consistency, we use
66+
# --disable-system-ffi so that the ffi gem *always* builds libffi, then
67+
# builds the ffi_c native extension and links it against libffi.so.
68+
#
69+
# In ruby 3.2 and up, libffi is no longer vendored. So we created a separate
70+
# libffi vanagon component which is built before ruby. The ffi gem still
71+
# vendors libffi, so we use the --enable-system-ffi option to ensure the ffi
72+
# gem *always* uses the libffi.so we already built. Note the term "system" is
73+
# misleading, because we override PKG_CONFIG_PATH below so that our libffi.so
74+
# is preferred, not the one in /usr/lib.
75+
settings[:gem_install_options] = if rb_major_minor_version > 2.7
76+
"-- --enable-system-ffi"
77+
else
78+
"-- --disable-system-ffi"
79+
end
80+
instance_eval File.read('configs/components/_base-rubygem.rb')
8481
end
8582

8683
# due to contrib/make_sunver.pl missing on solaris 11 we cannot compile libffi, so we provide the opencsw library
@@ -157,4 +154,4 @@
157154
%(#{platform[:sed]} -i '0,/ensure_required_ruby_version_met/b; /ensure_required_ruby_version_met/d' #{base_ruby}/rubygems/installer.rb)
158155
end
159156
end
160-
end
157+
end

0 commit comments

Comments
 (0)