Skip to content

Commit ae12465

Browse files
committed
(PA-4715) Add Ruby 3.2 to puppet-runtime, validated with EL-7 and EL-8 x86_64 agent-runtime
This PR adds ruby 3.2 as a component to puppet runtime. It also copies the agent-runtime-main into a new project that has ruby 3.2. Until we have a branch of puppet-agent to promote ruby 2.7.6 to we'll need to seperate out this. There are three changes that are needed to get Ruby 3.2 to build: * Package libffi * Package libyaml * Patch ruby-shadow Starting with Ruby 3.2 libffi and libyaml are no longer packaged with Ruby, so we need to take care of that. Ruby-shadow is a gem dependcy that is way out of date and wont build with Ruby 3, there is a simple patch we apply that allow us to build it. The scope of this PR is just to build against EL-7 and EL-8, there is further work to do to get all other supported platforms to build.
1 parent ed63985 commit ae12465

File tree

8 files changed

+441
-0
lines changed

8 files changed

+441
-0
lines changed

configs/components/_base-ruby.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
ruby_version_condensed = pkg.get_version.tr('.', '')
77
# Y version, e.g. '2.4.3' -> '2.4'
88
ruby_version_y = pkg.get_version.gsub(/(\d+)\.(\d+)\.(\d+)/, '\1.\2')
9+
# Strip the -preview from 3.2-preview, can be removed once ruby 3.2 is released
10+
ruby_version_y = ruby_version_y.gsub(/(\d+)\.(\d+)-preview(\d+)/, '\1.\2') if ruby_version_y =~ /-preview/
911

1012
pkg.mirror "#{settings[:buildsources_url]}/ruby-#{pkg.get_version}.tar.gz"
1113
pkg.url "https://cache.ruby-lang.org/pub/ruby/#{ruby_version_y}/ruby-#{pkg.get_version}.tar.gz"

configs/components/libffi.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
component 'libffi' do |pkg, settings, platform|
2+
pkg.version '3.4.3'
3+
pkg.md5sum 'b57b0ac1d1072681cee9148a417bd2ec'
4+
pkg.url "https://github.com/libffi/libffi/releases/download/#{pkg.get_name}/#{pkg.get_name}-#{pkg.get_version}.tar.gz"
5+
pkg.mirror "#{settings[:buildsources_url]}/#{pkg.get_name}-#{pkg.get_version}.tar.gz"
6+
7+
if platform.is_aix?
8+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH)"
9+
elsif platform.is_cross_compiled_linux?
10+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH):#{settings[:bindir]}"
11+
pkg.environment "CFLAGS", settings[:cflags]
12+
pkg.environment "LDFLAGS", settings[:ldflags]
13+
elsif platform.is_solaris?
14+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH):/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin:#{settings[:bindir]}"
15+
pkg.environment "CFLAGS", "#{settings[:cflags]} -std=c99"
16+
pkg.environment "LDFLAGS", settings[:ldflags]
17+
elsif platform.is_macos?
18+
pkg.environment "LDFLAGS", settings[:ldflags]
19+
pkg.environment "CFLAGS", settings[:cflags]
20+
if platform.is_cross_compiled?
21+
pkg.environment 'CC', 'clang -target arm64-apple-macos11' if platform.name =~ /osx-11/
22+
pkg.environment 'CC', 'clang -target arm64-apple-macos12' if platform.name =~ /osx-12/
23+
end
24+
else
25+
pkg.environment "LDFLAGS", settings[:ldflags]
26+
pkg.environment "CFLAGS", settings[:cflags]
27+
end
28+
29+
pkg.build_requires "runtime-#{settings[:runtime_project]}"
30+
31+
pkg.configure do
32+
["./configure --prefix=#{settings[:prefix]} --sbindir=#{settings[:prefix]}/bin --libexecdir=#{settings[:prefix]}/lib/libffi --disable-multi-os-directory #{settings[:host]}"]
33+
end
34+
35+
pkg.build do
36+
["#{platform[:make]} VERBOSE=1 -j$(shell expr $(shell #{platform[:num_cores]}) + 1)"]
37+
end
38+
39+
pkg.install do
40+
[
41+
"#{platform[:make]} VERBOSE=1 -j$(shell expr $(shell #{platform[:num_cores]}) + 1) install",
42+
"rm -rf #{settings[:datadir]}/doc/#{pkg.get_name}*"
43+
]
44+
end
45+
end

configs/components/libyaml.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
component 'libyaml' do |pkg, settings, platform|
2+
pkg.version '0.2.5'
3+
pkg.md5sum 'bb15429d8fb787e7d3f1c83ae129a999'
4+
pkg.url "https://github.com/yaml/libyaml/releases/download/#{pkg.get_name}/yaml-#{pkg.get_version}-0.2.5.tar.gz"
5+
pkg.mirror "#{settings[:buildsources_url]}/yaml-#{pkg.get_version}.tar.gz"
6+
7+
if platform.is_aix?
8+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH)"
9+
elsif platform.is_cross_compiled_linux?
10+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH):#{settings[:bindir]}"
11+
pkg.environment "CFLAGS", settings[:cflags]
12+
pkg.environment "LDFLAGS", settings[:ldflags]
13+
elsif platform.is_solaris?
14+
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH):/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin:#{settings[:bindir]}"
15+
pkg.environment "CFLAGS", "#{settings[:cflags]} -std=c99"
16+
pkg.environment "LDFLAGS", settings[:ldflags]
17+
elsif platform.is_macos?
18+
pkg.environment "LDFLAGS", settings[:ldflags]
19+
pkg.environment "CFLAGS", settings[:cflags]
20+
if platform.is_cross_compiled?
21+
pkg.environment 'CC', 'clang -target arm64-apple-macos11' if platform.name =~ /osx-11/
22+
pkg.environment 'CC', 'clang -target arm64-apple-macos12' if platform.name =~ /osx-12/
23+
end
24+
else
25+
pkg.environment "LDFLAGS", settings[:ldflags]
26+
pkg.environment "CFLAGS", settings[:cflags]
27+
end
28+
29+
pkg.build_requires "runtime-#{settings[:runtime_project]}"
30+
31+
pkg.configure do
32+
["./configure --prefix=#{settings[:prefix]} --sbindir=#{settings[:prefix]}/bin --libexecdir=#{settings[:prefix]}/lib/libyaml #{settings[:host]}"]
33+
end
34+
35+
pkg.build do
36+
["#{platform[:make]} VERBOSE=1 -j$(shell expr $(shell #{platform[:num_cores]}) + 1)"]
37+
end
38+
39+
pkg.install do
40+
[
41+
"#{platform[:make]} VERBOSE=1 -j$(shell expr $(shell #{platform[:num_cores]}) + 1) install",
42+
"rm -rf #{settings[:datadir]}/doc/#{pkg.get_name}*"
43+
]
44+
end
45+
end

configs/components/ruby-3.2.0.rb

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
component 'ruby-3.2.0' do |pkg, settings, platform|
2+
pkg.version '3.2.0-preview2'
3+
pkg.sha256sum '8a78fd7a221b86032f96f25c1d852954c94d193b9d21388a9b434e160b7ed891'
4+
5+
# rbconfig-update is used to munge rbconfigs after the fact.
6+
pkg.add_source("file://resources/files/ruby/rbconfig-update.rb")
7+
8+
# PDK packages multiple rubies and we need to tweak some settings
9+
# if this is not the *primary* ruby.
10+
if pkg.get_version !~ /preview/ && pkg.get_version != settings[:ruby_version]
11+
# not primary ruby
12+
13+
# ensure we have config for this ruby
14+
unless settings.key?(:additional_rubies) && settings[:additional_rubies].key?(pkg.get_version)
15+
raise "missing config for additional ruby #{pkg.get_version}"
16+
end
17+
18+
ruby_settings = settings[:additional_rubies][pkg.get_version]
19+
20+
ruby_dir = ruby_settings[:ruby_dir]
21+
ruby_bindir = ruby_settings[:ruby_bindir]
22+
host_ruby = ruby_settings[:host_ruby]
23+
else
24+
# primary ruby
25+
ruby_dir = settings[:ruby_dir]
26+
ruby_bindir = settings[:ruby_bindir]
27+
host_ruby = settings[:host_ruby]
28+
end
29+
30+
# Most ruby configuration happens in the base ruby config:
31+
instance_eval File.read('configs/components/_base-ruby.rb')
32+
# Configuration below should only be applicable to ruby 2.5
33+
34+
#########
35+
# PATCHES
36+
#########
37+
38+
base = 'resources/patches/ruby_32'
39+
40+
if platform.is_cross_compiled?
41+
unless platform.is_macos?
42+
# pkg.apply_patch "#{base}/uri_generic_remove_safe_nav_operator_r2.5.patch"
43+
# pkg.apply_patch "#{base}/lib_optparse_remove_safe_nav_operator.patch"
44+
# pkg.apply_patch "#{base}/revert_delete_prefix.patch"
45+
# pkg.apply_patch "#{base}/remove_squiggly_heredocs.patch"
46+
# pkg.apply_patch "#{base}/remove_deprecate_constant_statements.patch"
47+
# pkg.apply_patch "#{base}/ruby2_keywords_guard.patch"
48+
# pkg.apply_patch "#{base}/ruby_version_extra_guards.patch"
49+
# pkg.apply_patch "#{base}/ruby_20_guards.patch"
50+
# pkg.apply_patch "#{base}/Replace-reference-to-RUBY-var-with-opt-pl-build-tool.patch"
51+
end
52+
53+
# pkg.apply_patch "#{base}/rbinstall_gem_path.patch"
54+
# pkg.apply_patch "#{base}/revert_host_value_changes.patch"
55+
end
56+
57+
if platform.is_aix?
58+
# TODO: Remove this patch once PA-1607 is resolved.
59+
# pkg.apply_patch "#{base}/aix_configure.patch"
60+
# pkg.apply_patch "#{base}/aix-fix-libpath-in-configure.patch"
61+
# pkg.apply_patch "#{base}/aix-do-not-use-realpath.patch"
62+
# pkg.apply_patch "#{base}/aix_ruby_2.1_fix_make_test_failure_r2.5.patch"
63+
# pkg.apply_patch "#{base}/Remove-O_CLOEXEC-check-for-AIX-builds_r2.5.patch"
64+
end
65+
66+
if platform.is_windows?
67+
# pkg.apply_patch "#{base}/windows_ruby_2.5_fixup_generated_batch_files.patch"
68+
# pkg.apply_patch "#{base}/windows_nocodepage_utf8_fallback_r2.5.patch"
69+
# pkg.apply_patch "#{base}/win32_long_paths_support.patch"
70+
# pkg.apply_patch "#{base}/ruby-faster-load_27.patch"
71+
# pkg.apply_patch "#{base}/windows_configure.patch"
72+
end
73+
74+
####################
75+
# ENVIRONMENT, FLAGS
76+
####################
77+
78+
if platform.is_macos?
79+
pkg.environment 'optflags', settings[:cflags]
80+
elsif platform.is_windows?
81+
pkg.environment 'optflags', settings[:cflags] + ' -O3'
82+
pkg.environment 'MAKE', 'make'
83+
elsif platform.is_cross_compiled?
84+
pkg.environment 'CROSS_COMPILING', 'true'
85+
else
86+
pkg.environment 'optflags', '-O2'
87+
end
88+
89+
special_flags = " --prefix=#{ruby_dir} --with-opt-dir=#{settings[:prefix]} "
90+
91+
if platform.name =~ /sles-15|el-8|debian-10/
92+
special_flags += " CFLAGS='#{settings[:cflags]}' LDFLAGS='#{settings[:ldflags]}' CPPFLAGS='#{settings[:cppflags]}' "
93+
end
94+
95+
if platform.is_aix?
96+
# This normalizes the build string to something like AIX 7.1.0.0 rather
97+
# than AIX 7.1.0.2 or something
98+
special_flags += " --build=#{settings[:platform_triple]} "
99+
elsif platform.is_cross_compiled? && platform.is_linux?
100+
special_flags += " --with-baseruby=#{host_ruby} "
101+
elsif platform.is_cross_compiled? && platform.is_macos?
102+
# When the target arch is aarch64, ruby incorrectly selects the 'ucontext' coroutine
103+
# implementation instead of 'arm64', so specify 'amd64' explicitly
104+
# https://github.com/ruby/ruby/blob/c9c2245c0a25176072e02db9254f0e0c84c805cd/configure.ac#L2329-L2330
105+
special_flags += " --with-baseruby=#{host_ruby} --with-coroutine=arm64 "
106+
elsif platform.is_solaris? && platform.architecture == "sparc"
107+
special_flags += " --with-baseruby=#{host_ruby} --enable-close-fds-by-recvmsg-with-peek "
108+
elsif platform.name =~ /el-6/
109+
special_flags += " --with-baseruby=no "
110+
elsif platform.is_windows?
111+
special_flags = " CPPFLAGS='-DFD_SETSIZE=2048' debugflags=-g --prefix=#{ruby_dir} --with-opt-dir=#{settings[:prefix]} "
112+
end
113+
114+
without_dtrace = [
115+
'aix-7.1-ppc',
116+
'el-7-ppc64le',
117+
'el-7-aarch64',
118+
'osx-11-arm64',
119+
'osx-12-arm64',
120+
'redhatfips-7-x86_64',
121+
'sles-12-ppc64le',
122+
'solaris-11-sparc',
123+
'windows-2012r2-x64',
124+
'windows-2012r2-x86',
125+
'windows-2019-x64',
126+
'windowsfips-2012r2-x64'
127+
]
128+
129+
unless without_dtrace.include? platform.name
130+
special_flags += ' --enable-dtrace '
131+
end
132+
133+
###########
134+
# CONFIGURE
135+
###########
136+
137+
# TODO: Remove this once PA-1607 is resolved.
138+
# TODO: Can we use native autoconf? The dependencies seemed a little too extensive
139+
pkg.configure { ["/opt/pl-build-tools/bin/autoconf"] } if platform.is_aix?
140+
141+
pkg.configure do
142+
[
143+
"bash configure \
144+
--enable-shared \
145+
--disable-install-doc \
146+
--disable-install-rdoc \
147+
#{settings[:host]} \
148+
#{special_flags}"
149+
]
150+
end
151+
152+
#########
153+
# INSTALL
154+
#########
155+
156+
if platform.is_windows?
157+
# With ruby 2.5, ruby will generate cmd files instead of bat files; These
158+
# cmd wrappers work fine in our environment if they're just renamed as batch
159+
# files. Rake is omitted here on purpose - it retains the old batch wrapper.
160+
#
161+
# Note that this step must happen after the install step above.
162+
pkg.install do
163+
%w{erb gem irb rdoc ri}.map do |name|
164+
"mv #{ruby_bindir}/#{name}.cmd #{ruby_bindir}/#{name}.bat"
165+
end
166+
end
167+
end
168+
169+
target_doubles = {
170+
'powerpc-ibm-aix7.1.0.0' => 'powerpc-aix7.1.0.0',
171+
'aarch64-apple-darwin' => 'aarch64-darwin',
172+
'aarch64-redhat-linux' => 'aarch64-linux',
173+
'ppc64-redhat-linux' => 'powerpc64-linux',
174+
'ppc64le-redhat-linux' => 'powerpc64le-linux',
175+
'powerpc64le-suse-linux' => 'powerpc64le-linux',
176+
'powerpc64le-linux-gnu' => 'powerpc64le-linux',
177+
'i386-pc-solaris2.10' => 'i386-solaris2.10',
178+
'sparc-sun-solaris2.10' => 'sparc-solaris2.10',
179+
'i386-pc-solaris2.11' => 'i386-solaris2.11',
180+
'sparc-sun-solaris2.11' => 'sparc-solaris2.11',
181+
'arm-linux-gnueabihf' => 'arm-linux-eabihf',
182+
'arm-linux-gnueabi' => 'arm-linux-eabi',
183+
'x86_64-w64-mingw32' => 'x64-mingw32',
184+
'i686-w64-mingw32' => 'i386-mingw32'
185+
}
186+
if target_doubles.key?(settings[:platform_triple])
187+
rbconfig_topdir = File.join(ruby_dir, 'lib', 'ruby', '3.2.0', target_doubles[settings[:platform_triple]])
188+
else
189+
rbconfig_topdir = "$$(#{ruby_bindir}/ruby -e \"puts RbConfig::CONFIG[\\\"topdir\\\"]\")"
190+
end
191+
192+
rbconfig_changes = {}
193+
if platform.is_aix?
194+
rbconfig_changes["CC"] = "gcc"
195+
elsif platform.is_cross_compiled? || platform.is_solaris?
196+
if platform.name =~ /osx-11/
197+
rbconfig_changes["CC"] = 'clang -target arm64-apple-macos11'
198+
elsif platform.name =~ /osx-12/
199+
rbconfig_changes["CC"] = 'clang -target arm64-apple-macos12'
200+
else
201+
rbconfig_changes["CC"] = "gcc"
202+
rbconfig_changes["warnflags"] = "-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized"
203+
end
204+
if platform.name =~ /el-7-ppc64/
205+
# EL 7 on POWER will fail with -Wl,--compress-debug-sections=zlib so this
206+
# will remove that entry
207+
# Matches both endians
208+
rbconfig_changes["DLDFLAGS"] = "-Wl,-rpath=/opt/puppetlabs/puppet/lib -L/opt/puppetlabs/puppet/lib -Wl,-rpath,/opt/puppetlabs/puppet/lib"
209+
elsif platform.name =~ /sles-12-ppc64le/
210+
# the ancient gcc version on sles-12-ppc64le does not understand -fstack-protector-strong, so remove the `strong` part
211+
rbconfig_changes["LDFLAGS"] = "-L. -Wl,-rpath=/opt/puppetlabs/puppet/lib -fstack-protector -rdynamic -Wl,-export-dynamic -L/opt/puppetlabs/puppet/lib"
212+
end
213+
elsif platform.is_windows?
214+
rbconfig_changes["CC"] = "x86_64-w64-mingw32-gcc"
215+
end
216+
217+
pkg.add_source("file://resources/files/ruby_vendor_gems/operating_system.rb")
218+
defaults_dir = File.join(settings[:libdir], "ruby/3.2.0/rubygems/defaults")
219+
pkg.directory(defaults_dir)
220+
pkg.install_file "../operating_system.rb", File.join(defaults_dir, 'operating_system.rb')
221+
222+
certs_dir = File.join(settings[:libdir], 'ruby/3.2.0/rubygems/ssl_certs/puppetlabs.net')
223+
pkg.directory(certs_dir)
224+
225+
pkg.add_source('file://resources/files/rubygems/COMODO_RSA_Certification_Authority.pem')
226+
pkg.install_file '../COMODO_RSA_Certification_Authority.pem', File.join(certs_dir, 'COMODO_RSA_Certification_Authority.pem')
227+
228+
pkg.add_source('file://resources/files/rubygems/GlobalSignRootCA_R3.pem')
229+
pkg.install_file '../GlobalSignRootCA_R3.pem', File.join(certs_dir, 'GlobalSignRootCA_R3.pem')
230+
231+
if rbconfig_changes.any?
232+
pkg.install do
233+
[
234+
"#{host_ruby} ../rbconfig-update.rb \"#{rbconfig_changes.to_s.gsub('"', '\"')}\" #{rbconfig_topdir}",
235+
"cp original_rbconfig.rb #{settings[:datadir]}/doc/rbconfig-#{pkg.get_version}-orig.rb",
236+
"cp new_rbconfig.rb #{rbconfig_topdir}/rbconfig.rb",
237+
]
238+
end
239+
end
240+
end

configs/components/ruby-shadow.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
end
4242
end
4343

44+
matchdata = platform.settings[:ruby_version].match /(\d+)\.(\d+)\.\d+/
45+
ruby_major_version = matchdata[1].to_i
46+
if ruby_major_version >= 3
47+
base = "resources/patches/ruby_32"
48+
# https://github.com/apalmblad/ruby-shadow/issues/26
49+
# if ruby-shadow gets a 3 release this should be removed
50+
pkg.apply_patch "#{base}/ruby-shadow-2.5.0-cflags.patch", strip: "0"
51+
end
52+
4453
pkg.build do
4554
["#{ruby} extconf.rb",
4655
"#{platform[:make]} -e -j$(shell expr $(shell #{platform[:num_cores]}) + 1)"]

configs/projects/_shared-agent-components.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
# Common components required by all agent branches
1414
proj.component 'runtime-agent'
1515

16+
matchdata = platform.settings[:ruby_version].match /(\d+)\.\d+\.\d+/
17+
ruby_major_version = matchdata[1].to_i
18+
# Ruby 3.2 does not package these two libraries so we need to add them as a component
19+
if ruby_major_version >= 3
20+
proj.component 'libffi'
21+
proj.component 'libyaml'
22+
end
23+
1624
if platform.name =~ /^redhatfips-.*/
1725
proj.component "openssl-1.1.1-fips"
1826
else

0 commit comments

Comments
 (0)