Skip to content

Conversation

@stanhu
Copy link

@stanhu stanhu commented Jul 28, 2025

This will allow Alpine-based containers to use the precompiled gems without having to install gcompat.

Relates to #648

This will allow Alpine-based containers to use the precompiled
gems without having to install `gcompat`.

Relates to ged#648
@stanhu stanhu force-pushed the sh-add-musl-builds branch from 817bd5a to 88e93c4 Compare July 28, 2025 20:04
['x86_64-linux', 'linux-x86_64', 'x86_64-linux-gnu'],
['aarch64-linux', 'linux-aarch64', 'aarch64-linux-gnu'],
['x86_64-linux-gnu', 'linux-x86_64', 'x86_64-linux-gnu'],
['x86_64-linux-musl', 'linux-x86_64', 'x86_64-unknown-linux-musl'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this one is unknown-linux while below is linux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbandy I think it's because the gnu compiler is installed via the Ubuntu packages, while the musl compiler is built and installed from https://github.com/richfelker/musl-cross-make.git (see rake-compiler/rake-compiler-dock@da4268d5#diff-f840daec2e49fd92de367e204a8dc78d8713fc3ea99f724da29a841798730fa9):

$ docker run -it ghcr.io/rake-compiler/rake-compiler-dock-image:1.9.1-mri-x86_64-linux-gnu bash
root@06bb6bae360a:/# dpkg -S x86_64-linux-gnu-gcc
gcc-9: /usr/bin/x86_64-linux-gnu-gcc-ranlib-9
gcc: /usr/bin/x86_64-linux-gnu-gcc-ar
gcc: /usr/bin/x86_64-linux-gnu-gcc
gcc-9: /usr/share/man/man1/x86_64-linux-gnu-gcc-9.1.gz
gcc: /usr/share/man/man1/x86_64-linux-gnu-gcc-ranlib.1.gz
gcc: /usr/bin/x86_64-linux-gnu-gcc-ranlib
gcc: /usr/bin/x86_64-linux-gnu-gcc-nm
gcc-9: /usr/bin/x86_64-linux-gnu-gcc-ar-9
gcc-9: /usr/share/man/man1/x86_64-linux-gnu-gcc-ranlib-9.1.gz
gcc-9: /usr/share/man/man1/x86_64-linux-gnu-gcc-ar-9.1.gz
gcc: /usr/share/man/man1/x86_64-linux-gnu-gcc.1.gz
gcc: /usr/share/man/man1/x86_64-linux-gnu-gcc-ar.1.gz
gcc: /usr/share/man/man1/x86_64-linux-gnu-gcc-nm.1.gz
gcc-9: /usr/share/man/man1/x86_64-linux-gnu-gcc-nm-9.1.gz
gcc-9: /usr/bin/x86_64-linux-gnu-gcc-9
gcc-9: /usr/bin/x86_64-linux-gnu-gcc-nm-9
$ docker run -it ghcr.io/rake-compiler/rake-compiler-dock-image:1.9.1-mri-x86_64-linux-musl bash
root@e97ee7e32d0e:/# which x86_64-unknown-linux-musl-gcc
/usr/bin/x86_64-unknown-linux-musl-gcc
root@e97ee7e32d0e:/# dpkg -S x86_64-unknown-linux-musl-gcc
dpkg-query: no path found matching pattern *x86_64-unknown-linux-musl-gcc*

strategy:
fail-fast: false
matrix:
include:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to test arm64 as well?

diff --git a/.github/workflows/binary-gems.yml b/.github/workflows/binary-gems.yml
index fbed528..3e9fd13 100644
--- a/.github/workflows/binary-gems.yml
+++ b/.github/workflows/binary-gems.yml
@@ -172,6 +172,10 @@ jobs:
             image_platform: linux/x86_64
             gem_platform: x86_64-linux-musl
             dockerfile: alpine
+          - from_image: alpine
+            image_platform: linux/arm64
+            gem_platform: aarch64-linux-musl
+            dockerfile: alpine

     runs-on: ubuntu-latest
     steps:

RubyGems version >= 3.3.22 is needed, so just bump the Ruby version from
3.0 to 3.1. This fixes
https://github.com/ged/ruby-pg/actions/runs/16579089729/job/46916537537.
@larskanis
Copy link
Collaborator

I know from ffi.gem that platform x86_64-linux-gnu needs a more recent rubygems version than platform x86_64-linux. And pg-1.6.0-x86_64-linux.gem fully works on alpine without any segfaults, when gcompat is installed. So there's no need to explicit exclude pg-1.6.0-x86_64-linux.gem from musl based systems (in contrast to ffi.gem). That's why I would like to add platform x86_64-linux-musl without renaming x86_64-linux to x86_64-linux-gnu. Does someone has experience with that?

@stanhu
Copy link
Author

stanhu commented Aug 1, 2025

@larskanis See the detailed notes by @flavorjones in rake-compiler/rake-compiler-dock#117:

Given the inconsisent behavior of gem and bundle when the gem in question ships linux and linux-musl platform gems, it seems pretty clear that it's not a good idea to do this.

So the recommendation has to be:

  • either:
    • ship a -linux platform gem that works for both gnu and musl systems,
    • or ship both -linux-gnu and -linux-musl platform gems.
  • do NOT ship -linux and -linux-musl platform gems for the same version.

@larskanis
Copy link
Collaborator

Thank you @stanhu for the pointer! I checked it and my conclusion is that it makes more sense to provide linux and linux-musl gems. This is because the situation is different from what is described in rake-compiler/rake-compiler-dock#117 . The pg-1.6.0-x86_64-linux.gem and pg-1.6.0-aarch64-linux.gem both work on musl and succeeds the full test suite there. So when old ruby / rubygem / bundler versions pick the non-musl version, then it isn't a bad choice. It fully works when gcompat is present on the system.

The only thing I worry about is the situation when rubygems or bundler completely fails. I can reproduce the Could not find gems matching 'rcee_precompiled (= 0.5.0.1)' valid for all resolution platforms on ruby-3.0 (updated rubygems), bundler 2.5.6/2.5.7, rubygems-3.5.7. But newer bundler-2.5.x versions fix this particular issue and updating bundler is easy, even on older systems and system provided rubies.

IMHO the added requirement of a more recent rubygems version is worse than the "bad" decision to install the non-musl gem on a musl system.

@stanhu
Copy link
Author

stanhu commented Aug 1, 2025

@larskanis Ok! I've updated this to test both linux and linux-musl gems, with and without gcompat, respectively.

@larskanis
Copy link
Collaborator

larskanis commented Aug 1, 2025

Oh, I should have notified you. I already put #649 together. The problem is that it fails because after sucessfully building linux-musl gem, it tries to build linux platform gem in addition in the musl image, possibly due to a broken platform selection logic in rake-compiler. See here where x86_64-linux is in the chain of linux-musl.gem

@stanhu
Copy link
Author

stanhu commented Aug 1, 2025

Thanks. I'll close this in favor of #657 then.

@larskanis
Copy link
Collaborator

@stanhu Thank you for helping with musl support! I merged #657 now. Will push a new release in the next days.

@stanhu
Copy link
Author

stanhu commented Aug 1, 2025

Great! Looking forward to the next release.

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.

3 participants