Skip to content

Commit

Permalink
Merge pull request #706 from joshcooper/solaris-sparc-native
Browse files Browse the repository at this point in the history
(PA-4867) Build ruby on Solaris 11 SPARC
  • Loading branch information
cthorn42 authored Aug 3, 2023
2 parents 8eb0a73 + 0968bde commit 9b8b735
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 29 deletions.
12 changes: 10 additions & 2 deletions configs/components/_base-ruby-augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
pkg.environment "PKG_CONFIG_PATH", "#{File.join(settings[:libdir], 'pkgconfig')}:/usr/lib/pkgconfig"

if platform.is_solaris?
if platform.architecture == 'sparc'
if platform.is_cross_compiled?
pkg.environment "RUBY", host_ruby
end
ruby = "#{host_ruby} -r#{settings[:datadir]}/doc/rbconfig-#{ruby_version}-orig.rb"

if !platform.is_cross_compiled? && platform.architecture == 'sparc'
ruby = File.join(ruby_bindir, 'ruby')
else
# This should really only be done when cross compiling but
# to avoid breaking solaris x86_64 in 7.x continue preloading
# our hook.
ruby = "#{host_ruby} -r#{settings[:datadir]}/doc/rbconfig-#{ruby_version}-orig.rb"
end
elsif platform.is_cross_compiled?
if platform.is_linux? || platform.is_macos?
pkg.environment "RUBY", host_ruby
Expand Down
13 changes: 9 additions & 4 deletions configs/components/_base-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.is_cross_compiled? && platform.architecture == '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"
Expand Down
3 changes: 3 additions & 0 deletions configs/components/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.is_cross_compiled? && platform.architecture == '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"
Expand Down
2 changes: 1 addition & 1 deletion configs/components/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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
Expand Down
8 changes: 7 additions & 1 deletion configs/components/libffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.is_cross_compiled? && platform.architecture == '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?
Expand Down
11 changes: 8 additions & 3 deletions configs/components/openssl-3.0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.is_cross_compiled? && platform.architecture == '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?

Expand Down
19 changes: 17 additions & 2 deletions configs/components/ruby-3.2.2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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?
Expand All @@ -131,6 +138,7 @@
'redhatfips-7-x86_64',
'sles-12-ppc64le',
'solaris-11-sparc',
'solaris-113-sparc',
'windows-2012r2-x64',
'windows-2012r2-x86',
'windows-2019-x64',
Expand Down Expand Up @@ -212,10 +220,17 @@
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.architecture != 'sparc')
# REMIND: why are we overriding rbconfig for solaris intel?
if platform.name =~ /osx-11/
rbconfig_changes["CC"] = 'clang -target arm64-apple-macos11'
elsif platform.name =~ /osx-12/
Expand Down
27 changes: 21 additions & 6 deletions configs/components/ruby-shadow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@
pkg.ref "refs/tags/2.5.0"

pkg.build_requires "ruby-#{settings[:ruby_version]}"
pkg.environment "PATH", "$(PATH):/usr/ccs/bin:/usr/sfw/bin"
if !platform.is_cross_compiled? && platform.architecture == 'sparc'
pkg.environment "PATH", "$(PATH):/opt/pl-build-tools/bin:/usr/ccs/bin:/usr/sfw/bin"
else
pkg.environment "PATH", "$(PATH):/usr/ccs/bin:/usr/sfw/bin"
end

pkg.environment "CONFIGURE_ARGS", '--vendor'

if platform.is_solaris?
if platform.architecture == 'sparc'
if platform.is_cross_compiled?
pkg.environment "RUBY", settings[:host_ruby]
end
ruby = "#{settings[:host_ruby]} -r#{settings[:datadir]}/doc/rbconfig-#{settings[:ruby_version]}-orig.rb"

if !platform.is_cross_compiled? && platform.architecture == 'sparc'
ruby = File.join(settings[:ruby_bindir], 'ruby')
else
# This should really only be done when cross compiling but
# to avoid breaking solaris x86_64 in 7.x continue preloading
# our hook.
ruby = "#{settings[:host_ruby]} -r#{settings[:datadir]}/doc/rbconfig-#{settings[:ruby_version]}-orig.rb"
end
elsif platform.is_cross_compiled?
pkg.environment "RUBY", settings[:host_ruby]
ruby = "#{settings[:host_ruby]} -r#{settings[:datadir]}/doc/rbconfig-#{settings[:ruby_version]}-orig.rb"
else
ruby = File.join(settings[:ruby_bindir], 'ruby')
end

matchdata = platform.settings[:ruby_version].match /(\d+)\.(\d+)\.\d+/
matchdata = platform.settings[:ruby_version].match(/(\d+)\.(\d+)\.\d+/)
ruby_major_version = matchdata[1].to_i
if ruby_major_version >= 3
base = "resources/patches/ruby_32"
Expand All @@ -29,8 +42,10 @@
end

pkg.build do
["#{ruby} extconf.rb",
"#{platform[:make]} -e -j$(shell expr $(shell #{platform[:num_cores]}) + 1)"]
[
"#{ruby} extconf.rb",
"#{platform[:make]} -e -j$(shell expr $(shell #{platform[:num_cores]}) + 1)"
]
end

pkg.install do
Expand Down
12 changes: 8 additions & 4 deletions configs/components/rubygem-ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@
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.start_with?('solaris-11-')
pkg.environment "MAKE", platform[:make] if platform.is_solaris?

if platform.is_cross_compiled_linux?
pkg.environment "PATH", "/opt/pl-build-tools/bin:$(PATH)"
elsif platform.is_solaris?
if settings[:ruby_version] =~ /3\.\d+\.\d+/
pkg.environment "PATH", "/opt/csw/bin:/opt/pl-build-tools/bin:$(PATH)"
if !platform.is_cross_compiled? && platform.architecture == 'sparc'
pkg.environment "PATH", "#{settings[:ruby_bindir]}:$(PATH)"
else
pkg.environment "PATH", "/opt/csw/bin:/opt/pl-build-tools/bin:$(PATH)"
end
else
pkg.environment "PATH", "/opt/pl-build-tools/bin:/opt/csw/bin:$(PATH)"
end
end
end
end

# With Ruby 3.2 on Solaris-11 we install OpenSCW's libffi, no need to copy over the system libffi
if platform.name =~ /solaris-11-i386/ && rb_major_minor_version < 3.2
Expand Down
60 changes: 60 additions & 0 deletions configs/platforms/solaris-113-sparc.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions configs/projects/_shared-agent-settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,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")
Expand All @@ -114,12 +118,14 @@
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_solaris?
# For solaris, we build cross-compilers
if platform.architecture == 'i386'
platform_triple = "#{platform.architecture}-pc-solaris2.#{platform.os_version}"
else
elsif platform.is_cross_compiled?
platform_triple = "#{platform.architecture}-sun-solaris2.#{platform.os_version}"
host = "--host #{platform_triple}"
else
platform_triple = "#{platform.architecture}-sun-solaris2.11"
host = "--host #{platform_triple}"
end
elsif platform.is_windows?
# For windows, we need to ensure we are building for mingw not cygwin
Expand Down
4 changes: 2 additions & 2 deletions configs/projects/agent-runtime-main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9b8b735

Please sign in to comment.