The currently-active branch of Ruby-kit is
2.7-prime, created in early January 2021 by Funtoo, and is based on a snapshot of Gentoo Ruby ebuilds from late December 2020. It is an auto-generated kit which will allow more frequent updates.
At the time
2.7-prime was created, the Gentoo Ruby Team was focusing on integrating support for Ruby 3.0 into Gentoo. Another notable event happening at around this time was the deprecation of Ruby 2.5 by the Ruby team itself, as it is currently in maintenance mode and nearing EOL. These events were factored into the plan for Ruby-kit related to supported versions.
Supported Ruby Versions
The Ruby versions available in
- This is the Funtoo OS "preferred" Ruby for satisfying system dependencies. This is the Ruby version that applications will try to use if 2.7 support is actually available in ebuilds and dependencies.
- This is the Funtoo OS "compatible" Ruby for satisfying system dependencies. This is the version that all applications are likely to support and is more universally supported in ebuilds. 2.6 is also our backup version of Ruby that is used by our eclass logic (more info below).
- This version of Ruby is being made available but is not currently used for resolving dependencies for Funtoo systems. It can be installed by Ruby developers and Ruby modules can be installed via
2.7-prime has a number of important Funtoo changes which are documented here.
ruby-*.eclass eclasses have been forked and are stored in our
kit-fixups repository, in
core-kit/curated/eclasses, so they will end up on end-user systems inside Core-kit and will be available to all kits.
The forked eclasses are:
The Problem Being Solved
These changes were made to solve a specific issue. We have found that in Gentoo, Ruby versions (this also happens with Python versions) can be very "sticky". By "sticky", I mean that it can be very hard to get rid of an older version of Ruby (or Python), and upstream Gentoo tends to try to handle this by orchestrating a mass purge of all ebuilds that reference this older implementation. Only then can this older version of the language be removed or deprecated in Gentoo. This involves updating hundreds of ebuilds, which is a lot of manual work, and thus isn't really a great solution. But it does fit in with the Gentoo model of having a large development team that "shuffles" individual ebuilds along to either add support for new language versions, or drop old versions. For Funtoo, this isn't really a workable option so a better solution was needed.
For Funtoo, I wanted to have a way to define what versions of Ruby were active in a build of Funtoo, in as central a way as possible, and not have annoying, soul-crushing dependency problems that
users or Funtoo developers had to deal with. The solution used was to modify Ruby eclasses to more aggressively mask the
USE_RUBY settings from the ebuilds based on what Ruby implementation
we actually want "active" in Funtoo.
A specific issue I wanted to address was to be able to easily deprecate Ruby 2.5. And yet, many ebuilds still referenced
ruby25 or even earlier as the maximum version that they support. To fix this issue, I
introduced an idea of a "backup Ruby version" which would get enabled if our more aggressive masking of
USE_RUBY resulted in a Ruby package or module not having support for any Ruby
implementation at all. In this case, the eclass will enable the backup Ruby version -- in this case Ruby 2.6, which has a high degree of compatibility with Ruby 2.5 that we are deprecating so it
is likely to work in the majority of cases for older Ruby ebuilds, and in the few cases where it may not, we can deal with these problems on a case-by-case basis.
This way, we can set Ruby 2.6 as our "baseline", or "compatibility" version that our minimum supported version in Funtoo ebuilds. Ensuring everything works with 2.6 should not be tremendously hard,
and we can move to 2.6 without changing every single ebuild that only references a 2.5 or earlier Ruby version. 2.7 is our "preferred" version -- and will be used if an ebuild supports it. But many
ebuilds are missing
USE_RUBY. They may work fine with Ruby 2.7 and simply need to be updated to reflect this, or they may not. I view this as a bit more of a stretch at this
time as compared to 2.6, so I did not select Ruby 2.7 as our "compatibility" version, although I would have preferred to do this.
These masking changes also have an interesting side-effect where we can make Ruby 3.0 available for developers, but Ruby-using packages will not actually depend on Ruby 3.0, even if they reference
USE_RUBY, until we "flip the switch" and tweak our eclasses. This allows Ruby 3.0 to be available to merge but not get entangled in system dependencies. This does mean that you
would need to install Ruby 3.0 dependencies using
gem, which is a fine solution since no ebuilds in Funtoo will need any ruby-module ebuilds installed. Basically we create a clean-room where
Ruby 3.0 can be used for now, until it becomes the official Ruby implementation in a future version of this kit -- when we choose.
The most notable changes are in the following files:
- Aggressively mask
USE_RUBYbased on our
RUBY_TARGETSsettings. If we mask all implementations, add
BACKUP_RUBYas backup implementation (currently 2.6).
_ruby_get_all_impls(), aggressively mask
USE_RUBYebuild settings based on our
BACKUP_RUBYlogic. Also change
IUSEcalculation to not aggressively mask
IUSEsettings, since the ebuild could have some logic based on some of the Ruby targets we masked out, and not having these targets in
IUSEwill cause Portage to complain.
The eclass changes, taken as a whole, allow Funtoo to set the Ruby implementation(s) active
in Funtoo more easily. Traditionally, in Gentoo, Ruby implementations are set based on
RUBY_TARGETS, which is defined in the profiles and set to something like this:
make.defaults(bash source code)
In addition, Ruby-using ebuilds that leverage the Ruby eclasses will set something like this:
ruby-using.ebuild(bash source code)
USE_RUBY="ruby25 ruby26 ruby27 ruby30"
The Funtoo changes cause the
USE_RUBY settings in ebuilds to be more aggressively masked based on the Funtoo OS settings for
RUBY_TARGETS. In addition, if our more aggressive masking causes a Ruby module or package to not have any valid Ruby implementations, a "backup" typically safe Ruby implementation will be enabled automatically.
This gives us the ability to "focus" our Ruby support around specific versions of Ruby.
Portage Limitations (Technical)
To implement all this, the
RUBY_TARGETS settings in the profiles must be kept in sync with the forked Ruby eclasses in Core-kit, so that they reference the same Ruby versions. Ideally, we would be able to
RUBY_TARGETS in one central place, and not keep multiple things in sync. But due to limitations in Portage, this is how it needs to be done.
The reason why we can't set Ruby settings all in one place is because
RUBY_TARGETS is a profile setting, which gets USE expanded to
ruby_targets_ruby26, etc. Dependencies "interact" with USE settings via conditionals which are actually stored in the dependency itself, and in the md5-cache, so dependencies can "dynamically adapt" to USE settings (this is why USE settings are used so heavily by Gentoo for so many strange things.)
USE_RUBY is an ebuild setting, which is hard-coded into each ebuild. The Ruby eclasses use the setting of
RUBY_TARGETS to influence the content of
DEPEND and other variables in the ebuild -- things either will or will not get written based on the logic of the eclass. These dependency changes get written to the Portage ebuild md5-cache. The Portage ebuild md5-cache can detect when eclasses have been changed, and when this happens, the cache entries will be invalidated and new data will be extracted from the ebuild to ensure that the dependency values are correct. But the Portage ebuild md5-cache cannot detect when a change to profiles would impact dependencies. In other words, Portage expects that "an ebuild's dependencies" come from the ebuild (tracked by md5 digest), potentially modified by eclasses (tracked by md5 digest), and that there are no other external influences.
Because of this design, settings in profiles that have the potential of changing are not allowed to "influence" the eclass directly. Eclasses are just allowed to "augment" things like dependencies in an ebuild based on their own, self-contained logic. Thus,
RUBY_TARGETS is not allowed to be simply read and used by the eclass. Doing this would result in the Portage md5-cache containing incorrect information. So we are unfortunately stuck in a position where we need to "keep the beams from touching" and need to have hard-coded logic or values in the eclass so that Portage can track any changes to this logic. If we change the values in the eclass, then its digest will change, and thus the md5-cache will detect this change and update its cache of ebuild metadata.
There is no trivial solution to this that I am aware, but there are potential solutions:
RUBY_TARGETS, and have the OS Ruby settings set in the eclass. Now they are defined in one place. This means that users can't override them in
/etc/make.conf. The eclasses must live in core-kit for technical reasons, and thus couldn't change automatically if a user changed their Ruby kit. So there are some downsides to this.
2. Deprecate md5-caching, or at least Funtoo-generated cache entries for improved performance. Then a user's local profile settings could be factored in to the md5-cache calculation. This would allow eclasses to interact with dynamic profile settings. It could reduce speed of Portage temporarily since it would need to rebuild its cache more often. If cache regen were fast enough, this wouldn't matter (and Funtoo has much faster cache regeneration code than Gentoo which could be leveraged.)
3. Just deal with the current situation for now, which is at least an improvement. Users don't generally need access to different ruby-kits, except developers when testing, and we have tools for developers to deal with this easily anyway (