From 8980a873f33dca38435417b5e2c32017f675ce00 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 18 Jul 2023 23:29:06 -0700 Subject: [PATCH] (PA-4867) Build ruby on Solaris 11 SPARC I couldn't find a way to to make solaris-11-sparc platform definition take into account the project, because of the way vanagon creates the Platform and then later the Project. So create a new solaris-113-sparc platform definition for native Solaris compiles. Since the name of the file contains 113, vanagon assumes that's the `os_version`. Setting the os_version from within the platform definition doesn't seem to work, so I had to specialy case some logic to check for the platform.name Ruby and all of its dependencies successfully build, but there are still some issues to be worked out. --- configs/components/_base-ruby.rb | 13 +++-- configs/components/augeas.rb | 3 + configs/components/curl.rb | 2 +- configs/components/libffi.rb | 8 ++- configs/components/openssl-3.0.rb | 11 +++- configs/components/ruby-3.2.2.rb | 18 +++++- configs/components/rubygem-ffi.rb | 2 +- configs/platforms/solaris-113-sparc.rb | 60 ++++++++++++++++++++ configs/projects/_shared-agent-components.rb | 4 +- configs/projects/_shared-agent-settings.rb | 20 +++++-- configs/projects/agent-runtime-main.rb | 4 +- 11 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 configs/platforms/solaris-113-sparc.rb diff --git a/configs/components/_base-ruby.rb b/configs/components/_base-ruby.rb index d381792fa..9627e7a3e 100644 --- a/configs/components/_base-ruby.rb +++ b/configs/components/_base-ruby.rb @@ -31,10 +31,15 @@ elsif platform.is_solaris? # See PA-5639, if we decide to go without OpenCSW GCC then we can simplify this logic if ruby_version_y >= '3.0' - pkg.environment 'PATH', "#{settings[:bindir]}:/opt/csw/bin:/usr/ccs/bin:/usr/sfw/bin:$(PATH)" - pkg.environment 'CC', '/opt/csw/bin/gcc' - pkg.environment 'LD', '/opt/csw/bin/gld' - pkg.environment 'AR', '/opt/csw/bin/gar' + if platform.name == 'solaris-113-sparc' + pkg.environment 'PATH', "#{settings[:bindir]}:/opt/pl-build-tools/bin:/opt/csw/bin:/usr/ccs/bin:/usr/sfw/bin:$(PATH)" + pkg.environment 'CC', "/opt/pl-build-tools/bin/#{settings[:platform_triple]}-gcc" + else + pkg.environment 'PATH', "#{settings[:bindir]}:/opt/csw/bin:/usr/ccs/bin:/usr/sfw/bin:$(PATH)" + pkg.environment 'CC', '/opt/csw/bin/gcc' + pkg.environment 'LD', '/opt/csw/bin/gld' + pkg.environment 'AR', '/opt/csw/bin/gar' + end else pkg.environment 'PATH', "#{settings[:bindir]}:/usr/ccs/bin:/usr/sfw/bin:$(PATH):/opt/csw/bin" pkg.environment 'CC', "/opt/pl-build-tools/bin/#{settings[:platform_triple]}-gcc" diff --git a/configs/components/augeas.rb b/configs/components/augeas.rb index 4893b32ba..5e17075b8 100644 --- a/configs/components/augeas.rb +++ b/configs/components/augeas.rb @@ -98,6 +98,9 @@ if platform.os_version == "10" pkg.environment "PKG_CONFIG_PATH", "/opt/csw/lib/pkgconfig" pkg.environment "PKG_CONFIG", "/opt/csw/bin/pkg-config" + elsif platform.name == 'solaris-113-sparc' + pkg.environment "PKG_CONFIG_PATH", "#{settings[:libdir]}/pkgconfig" + pkg.environment "PKG_CONFIG", "/usr/bin/pkg-config" else pkg.environment "PKG_CONFIG_PATH", "/usr/lib/pkgconfig" pkg.environment "PKG_CONFIG", "/opt/pl-build-tools/bin/pkg-config" diff --git a/configs/components/curl.rb b/configs/components/curl.rb index 925a953e7..42679a525 100644 --- a/configs/components/curl.rb +++ b/configs/components/curl.rb @@ -46,7 +46,7 @@ extra_cflags << '-mmacosx-version-min=12.0 -arch arm64' if platform.name =~ /osx-12/ end - if (platform.is_solaris? && platform.os_version == "11") || platform.is_aix? + if (platform.is_solaris? && platform.os_version.start_with?("11")) || platform.is_aix? # Makefile generation with automatic dependency tracking fails on these platforms configure_options << "--disable-dependency-tracking" end diff --git a/configs/components/libffi.rb b/configs/components/libffi.rb index 755475062..d0e2b3673 100644 --- a/configs/components/libffi.rb +++ b/configs/components/libffi.rb @@ -16,7 +16,13 @@ pkg.environment "LDFLAGS", settings[:ldflags] elsif platform.is_solaris? pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH):/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin:#{settings[:bindir]}" - pkg.environment "CFLAGS", "#{settings[:cflags]} -std=c99" + if platform.name == 'solaris-113-sparc' + # must use gnu99 due to `asm` keyword + # https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Extended-Asm.html + pkg.environment "CFLAGS", "#{settings[:cflags]} -std=gnu99" + else + pkg.environment "CFLAGS", "#{settings[:cflags]} -std=c99" + end pkg.environment "LDFLAGS", settings[:ldflags] pkg.environment 'MAKE', 'gmake' elsif platform.is_macos? diff --git a/configs/components/openssl-3.0.rb b/configs/components/openssl-3.0.rb index 2739ea112..227cac32e 100644 --- a/configs/components/openssl-3.0.rb +++ b/configs/components/openssl-3.0.rb @@ -61,10 +61,15 @@ target = 'aix-gcc' elsif platform.is_solaris? pkg.environment 'PATH', '/opt/csw/bin:$(PATH):/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin' - pkg.environment 'CC', "/opt/csw/bin/gcc" - + if platform.name == 'solaris-113-sparc' + pkg.environment 'CC', "/opt/pl-build-tools/bin/gcc" + gcc_lib = "/opt/pl-build-tools/#{settings[:platform_triple]}/lib" + else + pkg.environment 'CC', "/opt/csw/bin/gcc" + gcc_lib = "/opt/csw/#{settings[:platform_triple]}/lib" + end cflags = "#{settings[:cflags]} -fPIC" - ldflags = "-R/opt/csw/#{settings[:platform_triple]}/lib -Wl,-rpath=#{settings[:libdir]} -L/opt/csw/#{settings[:platform_triple]}/lib" + ldflags = "-R#{gcc_lib} -Wl,-rpath=#{settings[:libdir]} -L#{gcc_lib}" target = platform.architecture =~ /86/ ? 'solaris-x86-gcc' : 'solaris-sparcv9-gcc' elsif platform.is_macos? diff --git a/configs/components/ruby-3.2.2.rb b/configs/components/ruby-3.2.2.rb index 25c6f7058..e915e3874 100644 --- a/configs/components/ruby-3.2.2.rb +++ b/configs/components/ruby-3.2.2.rb @@ -111,7 +111,14 @@ # https://github.com/ruby/ruby/blob/c9c2245c0a25176072e02db9254f0e0c84c805cd/configure.ac#L2329-L2330 special_flags += " --with-baseruby=#{host_ruby} --with-coroutine=arm64 " elsif platform.is_solaris? && platform.architecture == "sparc" - special_flags += " --with-baseruby=#{host_ruby} --enable-close-fds-by-recvmsg-with-peek " + if platform.is_cross_compiled? + special_flags += " --with-baseruby=#{host_ruby} " + else + # configure seems to enable dtrace because the executable is present, + # explicitly disable it and don't enable it below + special_flags += " --with-baseruby=no --enable-dtrace=no " + end + special_flags += " --enable-close-fds-by-recvmsg-with-peek " elsif platform.name =~ /el-6/ special_flags += " --with-baseruby=no " elsif platform.is_windows? @@ -137,6 +144,7 @@ 'redhatfips-7-x86_64', 'sles-12-ppc64le', 'solaris-11-sparc', + 'solaris-113-sparc', 'windows-2012r2-x64', 'windows-2012r2-x86', 'windows-2019-x64', @@ -218,10 +226,16 @@ rbconfig_topdir = "$$(#{ruby_bindir}/ruby -e \"puts RbConfig::CONFIG[\\\"topdir\\\"]\")" end + # When cross compiling or building on non-linux, we sometimes need to patch + # the rbconfig.rb in the "host" ruby so that later when we try to build gems + # with native extensions, like ffi, the "host" ruby's mkmf will use the CC, + # etc specified below. For example, if we're building on mac Intel for ARM, + # then the CC override allows us to build ffi_c.so for ARM as well. The + # "host" ruby is configured in _shared-agent-settings rbconfig_changes = {} if platform.is_aix? rbconfig_changes["CC"] = "gcc" - elsif platform.is_cross_compiled? || platform.is_solaris? + elsif platform.is_cross_compiled? || (platform.is_solaris? && platform.name != 'solaris-113-sparc') # why are we overriding rbconfig for solaris 10/11 native compiles? if platform.name =~ /osx-11/ rbconfig_changes["CC"] = 'clang -target arm64-apple-macos11' elsif platform.name =~ /osx-12/ diff --git a/configs/components/rubygem-ffi.rb b/configs/components/rubygem-ffi.rb index e60ae1a89..03d6751c0 100644 --- a/configs/components/rubygem-ffi.rb +++ b/configs/components/rubygem-ffi.rb @@ -62,7 +62,7 @@ end # due to contrib/make_sunver.pl missing on solaris 11 we cannot compile libffi, so we provide the opencsw library - pkg.environment "CPATH", "/opt/csw/lib/libffi-3.2.1/include" if platform.name =~ /solaris-11/ + pkg.environment "CPATH", "/opt/csw/lib/libffi-3.2.1/include" if platform.name =~ /solaris-11-/ pkg.environment "MAKE", platform[:make] if platform.is_solaris? if platform.is_cross_compiled_linux? diff --git a/configs/platforms/solaris-113-sparc.rb b/configs/platforms/solaris-113-sparc.rb new file mode 100644 index 000000000..351b7e9e8 --- /dev/null +++ b/configs/platforms/solaris-113-sparc.rb @@ -0,0 +1,60 @@ +# This platform definition is used to build natively on SPARC, unlike +# solaris-10/11-sparc, which are cross compiled. Therefore, this definition does +# not inherit from vanagon defaults. +platform "solaris-11-sparc" do |plat| + plat.servicedir "/lib/svc/manifest" + plat.defaultdir "/lib/svc/method" + plat.servicetype "smf" + + plat.vmpooler_template "solaris-11-sparc" + plat.add_build_repository "http://solaris-11-reposync.delivery.puppetlabs.net:81", "puppetlabs.com" + plat.install_build_dependencies_with "pkg install ", " || [[ $? -eq 4 ]]" + + packages = [ + "pl-gcc10", + "pl-libffi", + "pl-openssl", + "pl-yaml-cpp-sparc", + + "autoconf", + "automake", + "cmake", + "gnu-make", + "libtool", + "pkg-config" + ] + plat.provision_with("pkg install #{packages.join(' ')}") + + plat.provision_with %[echo "# Write the noask file to a temporary directory +# please see man -s 4 admin for details about this file: +# http://www.opensolarisforum.org/man/man4/admin.html +# +# The key thing we don\'t want to prompt for are conflicting files. +# The other nocheck settings are mostly defensive to prevent prompts +# We _do_ want to check for available free space and abort if there is +# not enough +mail= +# Overwrite already installed instances +instance=overwrite +# Do not bother checking for partially installed packages +partial=nocheck +# Do not bother checking the runlevel +runlevel=nocheck +# Do not bother checking package dependencies (We take care of this) +idepend=nocheck +rdepend=nocheck +# DO check for available free space and abort if there isn\'t enough +space=quit +# Do not check for setuid files. +setuid=nocheck +# Do not check if files conflict with other packages +conflict=nocheck +# We have no action scripts. Do not check for them. +action=nocheck +# Install to the default base directory. +basedir=default" > /var/tmp/vanagon-noask; + echo "mirror=https://artifactory.delivery.puppetlabs.net/artifactory/generic__remote_opencsw_mirror/testing" > /var/tmp/vanagon-pkgutil.conf; + pkgadd -n -a /var/tmp/vanagon-noask -d http://get.opencsw.org/now all + /opt/csw/bin/pkgutil -U && /opt/csw/bin/pkgutil -y -i bison || exit 1 + ] +end diff --git a/configs/projects/_shared-agent-components.rb b/configs/projects/_shared-agent-components.rb index 2a03db874..2e4f11442 100644 --- a/configs/projects/_shared-agent-components.rb +++ b/configs/projects/_shared-agent-components.rb @@ -38,8 +38,8 @@ proj.component 'libxml2' unless platform.is_windows? proj.component 'libxslt' unless platform.is_windows? -proj.component 'ruby-augeas' unless platform.is_windows? -proj.component 'ruby-shadow' unless platform.is_aix? || platform.is_windows? +proj.component 'ruby-augeas' unless platform.is_windows? || platform.name == 'solaris-113-sparc' +proj.component 'ruby-shadow' unless platform.is_aix? || platform.is_windows? || platform.name == 'solaris-113-sparc' # We only build ruby-selinux for EL, Fedora, Debian and Ubuntu (amd64/i386) if platform.is_el? || platform.is_fedora? || platform.name =~ /debian|ubuntu/ if platform.name !~ /ubuntu-.*-ppc64el/ diff --git a/configs/projects/_shared-agent-settings.rb b/configs/projects/_shared-agent-settings.rb index 9d974598f..963adec7e 100644 --- a/configs/projects/_shared-agent-settings.rb +++ b/configs/projects/_shared-agent-settings.rb @@ -90,11 +90,15 @@ platform_triple = "arm-linux-gnueabihf" if platform.architecture == "armhf" platform_triple = "aarch64-apple-darwin" if platform.is_cross_compiled? && platform.is_macos? +# Ruby's build process needs a functional "baseruby". When native compiling, +# ruby will build "miniruby" and use that as "baseruby". When cross compiling, +# we need a "host" ruby from somewhere else. +# +# Our build process also needs a "host" ruby to install rubygem-* components. if platform.is_windows? proj.setting(:host_ruby, File.join(proj.ruby_bindir, "ruby.exe")) proj.setting(:host_gem, File.join(proj.ruby_bindir, "gem.bat")) -elsif platform.is_cross_compiled_linux? || (platform.is_solaris? && platform.architecture == 'sparc') - # Install a standalone ruby for cross-compiled platforms +elsif platform.is_cross_compiled? && (platform.is_linux? || platform.is_solaris?) if platform.name =~ /solaris-10-sparc/ proj.setting(:host_ruby, "/opt/csw/bin/ruby") proj.setting(:host_gem, "/opt/csw/bin/gem2.0") @@ -112,12 +116,18 @@ if platform.is_cross_compiled_linux? host = "--host #{platform_triple}" -elsif platform.is_cross_compiled? && platform.is_macos? - host = "--host aarch64-apple-darwin --build x86_64-apple-darwin --target aarch64-apple-darwin" +elsif platform.is_macos? + if platform.is_cross_compiled? + host = "--host aarch64-apple-darwin --build x86_64-apple-darwin --target aarch64-apple-darwin" + else + host = "--host aarch64-apple-darwin" + end elsif platform.is_solaris? - # For solaris, we build cross-compilers if platform.architecture == 'i386' platform_triple = "#{platform.architecture}-pc-solaris2.#{platform.os_version}" + elsif platform.name == 'solaris-113-sparc' + platform_triple = "#{platform.architecture}-sun-solaris2.11" + host = "--host #{platform_triple}" else platform_triple = "#{platform.architecture}-sun-solaris2.#{platform.os_version}" host = "--host #{platform_triple}" diff --git a/configs/projects/agent-runtime-main.rb b/configs/projects/agent-runtime-main.rb index c31ad00a0..eab61966f 100644 --- a/configs/projects/agent-runtime-main.rb +++ b/configs/projects/agent-runtime-main.rb @@ -79,6 +79,6 @@ proj.component 'rubygem-erubi' proj.component 'rubygem-prime' - proj.component 'boost' if ENV['NO_PXP_AGENT'].to_s.empty? - proj.component 'yaml-cpp' if ENV['NO_PXP_AGENT'].to_s.empty? + proj.component 'boost' if ENV['NO_PXP_AGENT'].to_s.empty? && platform.name != 'solaris-113-sparc' + proj.component 'yaml-cpp' if ENV['NO_PXP_AGENT'].to_s.empty? && platform.name != 'solaris-113-sparc' end