Bundler: Enforce consistent platform versions

Updated . Posted . Visible to the public.

Some rubygems come in platform-specific versions (i.e. "x86_64-linux") in addition to the usual "ruby" platform. This is often is done for gems with native extensions that want to deliver precompiled binaries for ease of installation. However, there is an issue on some versions of Bundler (at least 2.3.x) that makes it inconsistent which versions of a gem will be installed.

Why this happens

On (very) old versions of Bundler, the Gemfile.lock could never indicate which version of a gem was installed, i.e. the Gemfile read nokogiri (1.12.5) although nokogiri (1.12.5-x86_64-linux) might actually be installed.

In addition, there is a section PLATFORMS which indicates the allowed platforms to be used.

Newer versions of Bundler (at least since 2.3) have two different behaviors:

  • If your Gemfile.lock reads PLATFORMS: ruby, it might either install a compatible platform-specific version, or the plain ruby version of a gem. I could not figure out under which circumstances one or the other occurs.
  • If your Gemfile.lock has PLATFORMS: x86_64-linux (or similar), bundler will install exactly the versions indiciated in the Gemfile.lock.

Fix

For better consistency, I would advise to make sure you always have

PLATFORMS
  x86_64-linux

in your Gemfile.lock, as is the current default.

You can change this by calling bundle lock --remove-platform ruby --add-platform x86_64-linux (adapt the platforms according to your use case)

If you change this, after bundling you might now get a different version than you want. Say you do want the platform-specific version of e.g. libv8-node. In this case, simply manually change libv8-node (15.14.0.1) to libv8-node (15.14.0.1-x86_64-linux) in your Gemfile.lock.

Tobias Kraze
Last edit
Bruno Sedler
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2024-08-09 11:47)