|
| 1 | +##### |
| 2 | +# Component release information: |
| 3 | +# https://github.com/ruby/ruby/releases |
| 4 | +# https://www.ruby-lang.org/en/downloads/releases/ |
| 5 | +# Notes: |
| 6 | +# The file name of the ruby component must match the ruby_version |
| 7 | +##### |
| 8 | +component 'ruby-4.0' do |pkg, settings, platform| |
| 9 | + pkg.version '4.0.1' |
| 10 | + pkg.sha256sum '3924be2d05db30f4e35f859bf028be85f4b7dd01714142fd823e4af5de2faf9d' |
| 11 | + |
| 12 | + ruby_dir = settings[:ruby_dir] |
| 13 | + ruby_bindir = settings[:ruby_bindir] |
| 14 | + host_ruby = settings[:host_ruby] |
| 15 | + |
| 16 | + # rbconfig-update is used to munge rbconfigs after the fact. |
| 17 | + pkg.add_source('file://resources/files/ruby/rbconfig-update.rb') |
| 18 | + |
| 19 | + # Most ruby configuration happens in the base ruby config: |
| 20 | + instance_eval File.read('configs/components/_base-ruby.rb') |
| 21 | + |
| 22 | + ######### |
| 23 | + # PATCHES |
| 24 | + ######### |
| 25 | + |
| 26 | + #base = 'resources/patches/ruby_32' |
| 27 | + |
| 28 | + #pkg.apply_patch "#{base}/rbinstall_gem_path.patch" if platform.is_cross_compiled? |
| 29 | + |
| 30 | + #pkg.apply_patch "#{base}/reline_disable_terminfo.patch" if platform.is_aix? |
| 31 | + |
| 32 | + #if platform.is_windows? |
| 33 | + # pkg.apply_patch "#{base}/windows_mingw32_mkmf.patch" |
| 34 | + # pkg.apply_patch "#{base}/ruby-faster-load_32.patch" |
| 35 | + # pkg.apply_patch "#{base}/revert_speed_up_rebuilding_loaded_feature_index.patch" |
| 36 | + # pkg.apply_patch "#{base}/revert-ruby-double-load-symlink.patch" |
| 37 | + # pkg.apply_patch "#{base}/revert_ruby_utf8_default_encoding.patch" |
| 38 | + #end |
| 39 | + |
| 40 | + #if platform.is_fips? |
| 41 | + # # This is needed on Ruby < 3.3 until the fix is backported (if ever) |
| 42 | + # # See: https://bugs.ruby-lang.org/issues/20000 |
| 43 | + # pkg.apply_patch "#{base}/openssl3_fips.patch" |
| 44 | + #end |
| 45 | + |
| 46 | + #################### |
| 47 | + # ENVIRONMENT, FLAGS |
| 48 | + #################### |
| 49 | + |
| 50 | + cflags = settings[:cflags] |
| 51 | + cppflags = settings[:cppflags] |
| 52 | + if platform.is_macos? |
| 53 | + pkg.environment 'optflags', cflags |
| 54 | + pkg.environment 'CFLAGS', cflags |
| 55 | + pkg.environment 'CPPFLAGS', cppflags |
| 56 | + pkg.environment 'LDFLAGS', settings[:ldflags] |
| 57 | + pkg.environment 'CC', settings[:cc] |
| 58 | + pkg.environment 'CXX', settings[:cxx] |
| 59 | + pkg.environment 'MACOSX_DEPLOYMENT_TARGET', settings[:deployment_target] |
| 60 | + pkg.environment 'PATH', '$(PATH):/opt/homebrew/bin:/usr/local/bin' |
| 61 | + elsif platform.is_windows? |
| 62 | + optflags = "#{cflags} -O3" |
| 63 | + pkg.environment 'optflags', optflags |
| 64 | + pkg.environment 'CFLAGS', optflags |
| 65 | + pkg.environment 'MAKE', 'make' |
| 66 | + elsif platform.is_cross_compiled? |
| 67 | + pkg.environment 'CROSS_COMPILING', 'true' |
| 68 | + elsif platform.is_aix? |
| 69 | + # When using the default -ggdb3 I was seeing linker errors like, so use -g0 instead: |
| 70 | + # |
| 71 | + # ld: 0711-759 INTERNAL ERROR: Source file dwarf.c, line 528. |
| 72 | + # Depending on where this product was acquired, contact your service |
| 73 | + # representative or the approved supplier. |
| 74 | + # collect2: error: ld returned 16 exit status |
| 75 | + |
| 76 | + pkg.environment 'optflags', '-O2 -fPIC -g0 ' |
| 77 | + elsif platform.is_solaris? |
| 78 | + pkg.environment 'optflags', '-O1' |
| 79 | + else |
| 80 | + pkg.environment 'optflags', '-O2' |
| 81 | + end |
| 82 | + |
| 83 | + special_flags = " --prefix=#{ruby_dir} --with-opt-dir=#{settings[:prefix]} " |
| 84 | + |
| 85 | + if (platform.is_debian? && platform.os_version.to_i >= 13) || (platform.is_ubuntu? && platform.os_version.to_f >= 25.04 || platform.is_sles? && platform.os_version.to_i >= 16) |
| 86 | + # A problem with --enable-dtrace, which I suspect may be because of GCC on the Trixie image. |
| 87 | + # Check if this is still needed next time we bump Ruby and/or bump the Debian 13 |
| 88 | + # container to the release version. |
| 89 | + cflags += ' -Wno-error=implicit-function-declaration ' |
| 90 | + end |
| 91 | + |
| 92 | + special_flags += " CFLAGS='#{cflags}' LDFLAGS='#{settings[:ldflags]}' CPPFLAGS='#{settings[:cppflags]}' " if settings[:supports_pie] |
| 93 | + |
| 94 | + # Ruby's build process requires a "base" ruby and we need a ruby to install |
| 95 | + # gems into the /opt/puppetlabs/puppet/lib directory. |
| 96 | + # |
| 97 | + # For cross-compiles, the base ruby must be executable on the host we're |
| 98 | + # building on (usually Intel), not the arch we're building for (such as |
| 99 | + # SPARC). This is usually pl-ruby. |
| 100 | + # |
| 101 | + # For native compiles, we don't want ruby's build process to use whatever ruby |
| 102 | + # is in the PATH, as it's probably too old to build ruby 3.2. And we don't |
| 103 | + # want to use/maintain pl-ruby if we don't have to. Instead set baseruby to |
| 104 | + # "no" which will force ruby to build and use miniruby. |
| 105 | + special_flags += if platform.is_cross_compiled? |
| 106 | + " --with-baseruby=#{host_ruby} " |
| 107 | + else |
| 108 | + ' --with-baseruby=no ' |
| 109 | + end |
| 110 | + |
| 111 | + if platform.is_aix? |
| 112 | + # This normalizes the build string to something like AIX 7.1.0.0 rather |
| 113 | + # than AIX 7.1.0.2 or something |
| 114 | + special_flags += " --build=#{settings[:platform_triple]} " |
| 115 | + elsif platform.is_cross_compiled? && platform.is_macos? |
| 116 | + # When the target arch is aarch64, ruby incorrectly selects the 'ucontext' coroutine |
| 117 | + # implementation instead of 'arm64', so specify 'amd64' explicitly |
| 118 | + # https://github.com/ruby/ruby/blob/c9c2245c0a25176072e02db9254f0e0c84c805cd/configure.ac#L2329-L2330 |
| 119 | + special_flags += ' --with-coroutine=arm64 ' |
| 120 | + elsif platform.is_solaris? && platform.architecture == 'sparc' |
| 121 | + unless platform.is_cross_compiled? |
| 122 | + # configure seems to enable dtrace because the executable is present, |
| 123 | + # explicitly disable it and don't enable it below |
| 124 | + special_flags += ' --enable-dtrace=no ' |
| 125 | + end |
| 126 | + special_flags += '--enable-close-fds-by-recvmsg-with-peek ' |
| 127 | + |
| 128 | + elsif platform.is_windows? |
| 129 | + # ruby's configure script guesses the build host is `cygwin`, because we're using |
| 130 | + # cygwin opensshd & bash. So mkmf will convert compiler paths, e.g. -IC:/... to |
| 131 | + # cygwin paths, -I/cygdrive/c/..., which confuses mingw-w64. So specify the build |
| 132 | + # target explicitly. |
| 133 | + special_flags += " CPPFLAGS='-DFD_SETSIZE=2048' debugflags=-g " |
| 134 | + |
| 135 | + special_flags += if platform.architecture == 'x64' |
| 136 | + ' --build x86_64-w64-mingw32 ' |
| 137 | + else |
| 138 | + ' --build i686-w64-mingw32 ' |
| 139 | + end |
| 140 | + elsif platform.is_macos? |
| 141 | + special_flags += " --with-openssl-dir=#{settings[:prefix]} " |
| 142 | + end |
| 143 | + |
| 144 | + without_dtrace = [ |
| 145 | + 'aix-7.2-ppc', |
| 146 | + 'el-7-ppc64le', |
| 147 | + 'macos-all-arm64', |
| 148 | + 'macos-all-x86_64', |
| 149 | + 'redhatfips-7-x86_64', |
| 150 | + 'sles-12-ppc64le', |
| 151 | + 'solaris-11-sparc', |
| 152 | + 'solaris-113-sparc', |
| 153 | + 'windows-all-x64', |
| 154 | + 'windowsfips-2016-x64' |
| 155 | + ] |
| 156 | + |
| 157 | + special_flags += ' --enable-dtrace ' unless without_dtrace.include? platform.name |
| 158 | + |
| 159 | + ########### |
| 160 | + # CONFIGURE |
| 161 | + ########### |
| 162 | + |
| 163 | + # TODO: Remove this once PA-1607 is resolved. |
| 164 | + # TODO: Can we use native autoconf? The dependencies seemed a little too extensive |
| 165 | + if platform.is_aix? |
| 166 | + pkg.configure { ['/opt/freeware/bin/autoconf'] } |
| 167 | + else |
| 168 | + pkg.configure { ['bash autogen.sh'] } |
| 169 | + end |
| 170 | + |
| 171 | + pkg.configure do |
| 172 | + [ |
| 173 | + "bash configure \ |
| 174 | + --enable-shared \ |
| 175 | + --disable-install-doc \ |
| 176 | + --disable-install-rdoc \ |
| 177 | + #{settings[:host]} \ |
| 178 | + #{special_flags}" |
| 179 | + ] |
| 180 | + end |
| 181 | + |
| 182 | + if platform.name =~ /windowsfips-2016/ |
| 183 | + # We need the below patch since during ruby build step for windowsfips-2016-x64 agent-runtime builds, |
| 184 | + # the rbconfig.rb file that gets generated contains '\r' trailing character in 'ruby_version' config. |
| 185 | + # We patch rbconfig.rb to remove the '\r' character. |
| 186 | + # This patch has to run after the build step since rbconfig.rb is generated during the build step. |
| 187 | + # This is sort of a hacky way to do this. We need to find why the '\r' character gets appended to |
| 188 | + # 'ruby_version' field in the future so that this patch can be removed - PA-6902. |
| 189 | + pkg.add_source("#{base}/rbconfig_win.patch") |
| 190 | + pkg.build do |
| 191 | + ['TMP=/var/tmp /usr/bin/patch.exe --binary --strip=1 --fuzz=0 --ignore-whitespace --no-backup-if-mismatch < ../rbconfig_win.patch'] |
| 192 | + end |
| 193 | + end |
| 194 | + |
| 195 | + ######### |
| 196 | + # INSTALL |
| 197 | + ######### |
| 198 | + |
| 199 | + if platform.is_windows? |
| 200 | + # Ruby 3.2 copies bin/gem to $ruby_bindir/gem.cmd, but generates bat files for |
| 201 | + # other gems like bundle.bat, irb.bat, etc. Just rename the cmd.cmd to cmd.bat |
| 202 | + # as we used to in ruby 2.7 and earlier. |
| 203 | + # |
| 204 | + # Note that this step must happen after the install step above. |
| 205 | + pkg.install do |
| 206 | + %w[gem].map do |name| |
| 207 | + "mv #{ruby_bindir}/#{name}.cmd #{ruby_bindir}/#{name}.bat" |
| 208 | + end |
| 209 | + end |
| 210 | + |
| 211 | + # Required when using `stack-protection-strong` and older versions of mingw-w64-gcc |
| 212 | + pkg.install_file File.join(settings[:gcc_bindir], 'libssp-0.dll'), File.join(settings[:bindir], 'libssp-0.dll') |
| 213 | + end |
| 214 | + |
| 215 | + target_doubles = { |
| 216 | + 'powerpc-ibm-aix7.2.0.0' => 'powerpc-aix7.2.0.0', |
| 217 | + 'aarch64-redhat-linux' => 'aarch64-linux', |
| 218 | + 'ppc64-redhat-linux' => 'powerpc64-linux', |
| 219 | + 'ppc64le-redhat-linux' => 'powerpc64le-linux', |
| 220 | + 'powerpc64le-suse-linux' => 'powerpc64le-linux', |
| 221 | + 'powerpc64le-linux-gnu' => 'powerpc64le-linux', |
| 222 | + 'i386-pc-solaris2.10' => 'i386-solaris2.10', |
| 223 | + 'sparc-sun-solaris2.10' => 'sparc-solaris2.10', |
| 224 | + 'i386-pc-solaris2.11' => 'i386-solaris2.11', |
| 225 | + 'sparc-sun-solaris2.11' => 'sparc-solaris2.11', |
| 226 | + 'arm-linux-gnueabihf' => 'arm-linux-eabihf', |
| 227 | + 'arm-linux-gnueabi' => 'arm-linux-eabi', |
| 228 | + 'x86_64-w64-mingw32' => 'x64-mingw32', |
| 229 | + 'i686-w64-mingw32' => 'i386-mingw32' |
| 230 | + } |
| 231 | + rbconfig_topdir = if target_doubles.key?(settings[:platform_triple]) |
| 232 | + File.join(ruby_dir, 'lib', 'ruby', '4.0.0', target_doubles[settings[:platform_triple]]) |
| 233 | + else |
| 234 | + "$$(#{ruby_bindir}/ruby -e \"puts RbConfig::CONFIG[\\\"topdir\\\"]\")" |
| 235 | + end |
| 236 | + |
| 237 | + # When cross compiling or building on non-linux, we sometimes need to patch |
| 238 | + # the rbconfig.rb in the "host" ruby so that later when we try to build gems |
| 239 | + # with native extensions, like ffi, the "host" ruby's mkmf will use the CC, |
| 240 | + # etc specified below. For example, if we're building on mac Intel for ARM, |
| 241 | + # then the CC override allows us to build ffi_c.so for ARM as well. The |
| 242 | + # "host" ruby is configured in _shared-agent-settings |
| 243 | + rbconfig_changes = {} |
| 244 | + if platform.is_aix? |
| 245 | + rbconfig_changes['CC'] = 'gcc' |
| 246 | + elsif platform.is_cross_compiled? || (platform.is_solaris? && platform.architecture != 'sparc') |
| 247 | + # REMIND: why are we overriding rbconfig for solaris intel? |
| 248 | + rbconfig_changes['CC'] = 'gcc' |
| 249 | + rbconfig_changes['warnflags'] = |
| 250 | + '-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' |
| 251 | + if platform.name =~ /el-7-ppc64/ |
| 252 | + # EL 7 on POWER will fail with -Wl,--compress-debug-sections=zlib so this |
| 253 | + # will remove that entry |
| 254 | + # Matches both endians |
| 255 | + rbconfig_changes['DLDFLAGS'] = |
| 256 | + '-Wl,-rpath=/opt/puppetlabs/puppet/lib -L/opt/puppetlabs/puppet/lib -Wl,-rpath,/opt/puppetlabs/puppet/lib' |
| 257 | + elsif platform.name =~ /sles-12-ppc64le/ |
| 258 | + # the ancient gcc version on sles-12-ppc64le does not understand -fstack-protector-strong, so remove the `strong` part |
| 259 | + rbconfig_changes['LDFLAGS'] = |
| 260 | + '-L. -Wl,-rpath=/opt/puppetlabs/puppet/lib -fstack-protector -rdynamic -Wl,-export-dynamic -L/opt/puppetlabs/puppet/lib' |
| 261 | + end |
| 262 | + elsif platform.is_macos? |
| 263 | + rbconfig_changes['CC'] = "#{settings[:cc]} #{cflags}" |
| 264 | + elsif platform.is_windows? |
| 265 | + rbconfig_changes['CC'] = if platform.architecture == 'x64' |
| 266 | + 'x86_64-w64-mingw32-gcc' |
| 267 | + else |
| 268 | + 'i686-w64-mingw32-gcc' |
| 269 | + end |
| 270 | + end |
| 271 | + |
| 272 | + pkg.add_source('file://resources/files/ruby_vendor_gems/operating_system.rb') |
| 273 | + defaults_dir = File.join(settings[:libdir], 'ruby/4.0.0/rubygems/defaults') |
| 274 | + pkg.directory(defaults_dir) |
| 275 | + pkg.install_file '../operating_system.rb', File.join(defaults_dir, 'operating_system.rb') |
| 276 | + |
| 277 | + certs_dir = File.join(settings[:libdir], 'ruby/4.0.0/rubygems/ssl_certs/puppetlabs.net') |
| 278 | + pkg.directory(certs_dir) |
| 279 | + |
| 280 | + pkg.add_source('file://resources/files/rubygems/COMODO_RSA_Certification_Authority.pem') |
| 281 | + pkg.install_file '../COMODO_RSA_Certification_Authority.pem', |
| 282 | + File.join(certs_dir, 'COMODO_RSA_Certification_Authority.pem') |
| 283 | + |
| 284 | + pkg.add_source('file://resources/files/rubygems/GlobalSignRootCA_R3.pem') |
| 285 | + pkg.install_file '../GlobalSignRootCA_R3.pem', File.join(certs_dir, 'GlobalSignRootCA_R3.pem') |
| 286 | + |
| 287 | + pkg.add_source('file://resources/files/rubygems/DigiCertGlobalRootG2.pem') |
| 288 | + pkg.install_file '../DigiCertGlobalRootG2.pem', File.join(certs_dir, 'DigiCertGlobalRootG2.pem') |
| 289 | + |
| 290 | + if rbconfig_changes.any? |
| 291 | + pkg.install do |
| 292 | + [ |
| 293 | + "#{host_ruby} ../rbconfig-update.rb \"#{rbconfig_changes.to_s.gsub('"', '\"')}\" #{rbconfig_topdir}", |
| 294 | + "cp original_rbconfig.rb #{settings[:datadir]}/doc/rbconfig-#{pkg.get_version}-orig.rb", |
| 295 | + "cp new_rbconfig.rb #{rbconfig_topdir}/rbconfig.rb" |
| 296 | + ] |
| 297 | + end |
| 298 | + end |
| 299 | +end |
0 commit comments