|
| 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 |
0 commit comments