Skip to content

Fix issue with old rubygems not detecting musl linux properly#40

Merged
ivoanjo merged 4 commits into
mainfrom
ivoanjo/handle-buggy-rubygems-musl
Aug 18, 2022
Merged

Fix issue with old rubygems not detecting musl linux properly#40
ivoanjo merged 4 commits into
mainfrom
ivoanjo/handle-buggy-rubygems-musl

Conversation

@ivoanjo

@ivoanjo ivoanjo commented Aug 18, 2022

Copy link
Copy Markdown
Member

What does this PR do?

Fix issue with old rubygems not detecting musl linux properly.

Old versions of rubygems (for instance 3.0.3) don't properly detect alternative libc implementations on Linux; in particular for our case, they don't detect musl.

(For reference, Rubies older than 2.7 may have shipped with an affected version of rubygems).

In such cases, we fall back to use RbConfig::CONFIG['arch'] instead.

Why not use RbConfig::CONFIG['arch'] always? Because Gem::Platform.local.to_s does some normalization we want in other situations -- for instance, it turns x86_64-linux-gnu to
x86_64-linux. So for now we only add this workaround in a specific situation where we actually know it is wrong.

See also ruby/rubygems#2922 and ruby/rubygems#4082

Fixes DataDog/dd-trace-rb#2222

Motivation

Fix DataDog/dd-trace-rb#2222; customers can manually upgrade to a non-buggy rubygems, but having this fixed on our side provides a better user experience.

Additional Notes

I'll ask someone working on Ruby to review this change, since it's very Ruby-specific.

How to test the change?

The ruby:2.5.9-alpine3.13 docker image ships with an affected version of Rubygems 3.0.3. Without this fix, the following command will print the wrong (non-musl) path for libdatadog:

$ docker run --network=host -ti -v `pwd`:/working ruby:2.5.9-alpine3.13 /bin/sh
/ # gem -v
3.0.3
/ # gem install libdatadog
Fetching libdatadog-0.7.0.1.0-x86_64-linux.gem
Successfully installed libdatadog-0.7.0.1.0-x86_64-linux
1 gem installed
/ # ruby -e "require 'libdatadog'; pp Libdatadog.pkgconfig_folder"
"/usr/local/bundle/gems/libdatadog-0.7.0.1.0-x86_64-linux/vendor/libdatadog-0.7.0/x86_64-linux/libdatadog-x86_64-unknown-linux-gnu/lib/pkgconfig"

with the new libdatadog (here I install it manually -- you can run bundle exec rake package to replicate locally), the correct version gets used:

/ # gem install working/libdatadog-0.7.0.1.1-x86_64-linux.gem
Successfully installed libdatadog-0.7.0.1.1-x86_64-linux
1 gem installed
/ # gem -v
3.0.3
/ # ruby -e "require 'libdatadog'; pp Libdatadog.pkgconfig_folder"
"/usr/local/bundle/gems/libdatadog-0.7.0.1.1-x86_64-linux/vendor/libdatadog-0.7.0/x86_64-linux-musl/libdatadog-x86_64-alpine-linux-musl/lib/pkgconfig"

Old versions of rubygems (for instance 3.0.3) don't properly detect
alternative libc implementations on Linux; in particular for our case,
they don't detect musl.

(For reference, Rubies older than 2.7 may have shipped with an affected
 version of rubygems).

In such cases, we fall back to use RbConfig::CONFIG['arch'] instead.

Why not use `RbConfig::CONFIG['arch']` always? Because
`Gem::Platform.local.to_s` does some normalization we want
in other situations -- for instance, it turns `x86_64-linux-gnu` to
`x86_64-linux`. So for now we only add this workaround in a specific
situation where we actually know it is wrong.

See also ruby/rubygems#2922 and
ruby/rubygems#4082

Fixes DataDog/dd-trace-rb#2222
I'm planning to release 0.7.0.1.1 with the musl fix. This will be
automatically picked up by customers using the currently-released
version of dd-trace-rb (1.3.0).
@ivoanjo ivoanjo requested a review from a team as a code owner August 18, 2022 13:19
Otherwise this breaks in Linux due to the rest of the spec flow.
@ivoanjo ivoanjo force-pushed the ivoanjo/handle-buggy-rubygems-musl branch from 3803a55 to 4c091c0 Compare August 18, 2022 13:22
@ivoanjo ivoanjo merged commit 35b4b18 into main Aug 18, 2022
@morrisonlevi morrisonlevi deleted the ivoanjo/handle-buggy-rubygems-musl branch August 18, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Profile disabled on alpine 3.13 with a runtime error loading the native extension

2 participants