Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider supporting *-linux-musl as a target platform #75

Closed
flavorjones opened this issue Nov 1, 2022 · 17 comments · Fixed by #111
Closed

consider supporting *-linux-musl as a target platform #75

flavorjones opened this issue Nov 1, 2022 · 17 comments · Fixed by #111

Comments

@flavorjones
Copy link
Collaborator

flavorjones commented Nov 1, 2022

Since Bundler 2.3.21 / Rubygems 3.3.21, it's possible to ship a gem for the specific *-linux-musl platform.

For many gems, like Nokogiri, we've been able to figure out how to build binaries that work on both glibc and musl platforms, but other gems (like sass-ruby) had to stop precompiling because of incompatibilities; and it sounds like (based on a chat with @ianks) that the Rust toolchain handles musl systems very differently as well.

This is a placeholder to discuss if, and when, we should support x86_64-linux-musl and aarch64-linux-musl as distinct target platforms.

@ianks
Copy link

ianks commented Nov 1, 2022

For additional context, here is the Dockerfile we use for x86_64-linux-musl. @eliias did all of the hard work on making it work properly, so looping in. From what I gather, it's mostly copy-pasta of what RCD already had... but could be wrong.

@eliias
Copy link

eliias commented Nov 2, 2022

Hey folks,

as @ianks already wrote, the Dockerfile I provided is mostly a straightforward port of the RCD image, minus the manylinux specific setup parts, because I am relying on a base image that provides all the tools for musl (messense/rust-musl-cross:x86_64-musl, https://github.com/messense/rust-musl-cross/blob/main/Dockerfile) and this image is based on Ubuntu 22. The result of all that is that the image is quite large (it probably adds at least 10% to the image size).

For full disclosure, I once tried to build a basic image where I add the musl tool chain myself, but it took forever to build, and I was running into various issues, so the result is a shortcut. I was looking into https://musl.cc/, and there are indeed some pre-compiled binaries we could use, it is probably just some extra work to add them.

As a side note, my primary motivation was to support builds for Alpine.

@flavorjones
Copy link
Collaborator Author

Here's an interesting failure case for how we're currently handling musl (which is, basically, hoping and testing):

sparklemotion/sqlite3-ruby#372

Some prior art I was able to find around generating musl binaries:

@ianks
Copy link

ianks commented Jan 12, 2023

@flavorjones Have you given a shot just directly using RCD_IMAGE=rbsys/x86_64-linux-musl:latest? Curious if it would Just Work™️

@CAMOBAP
Copy link

CAMOBAP commented Mar 26, 2023

@flavorjones Have you given a shot just directly using RCD_IMAGE=rbsys/x86_64-linux-musl:latest? Curious if it would Just Work™️

@ianks thanks a lot for suggesting image (it works in my case), BTW maybe you can suggest a good candidate for aarch64-linux-musl?

@ianks
Copy link

ianks commented Mar 27, 2023

@flavorjones Have you given a shot just directly using RCD_IMAGE=rbsys/x86_64-linux-musl:latest? Curious if it would Just Work™️

@ianks thanks a lot for suggesting image (it works in my case), BTW maybe you can suggest a good candidate for aarch64-linux-musl?

As of now, there is no supported rake-compiler-dock image for aarch64-linux-musl unfortunately.

@segiddins
Copy link

What would be needed to make this happen? I'm currently looking into revamping rubygems' support for "platforms", and as a part of that we want to make shipping precompiled extensions as ubiquitous as possible, so I'd love to understand what blocks cross-compiling against musl here

@flavorjones
Copy link
Collaborator Author

flavorjones commented Aug 31, 2023

we want to make shipping precompiled extensions as ubiquitous as possible

@segiddins This is very very interesting to me (I've given multiple conference talks (1, 2) on precompiled gems; and help maintain precompiled gems nokogiri, sqlite3, and ruby-magic, as well as this project; and created a project explaining precompilation with working examples and CI) ... and probably to @larskanis and others as well. How can we help support this effort?

This issue is to discuss a (slowly) ongoing project to create a docker image suitable for cross-compiling for musl. This is pretty much just a time-and-effort question, since @eliias and @ianks have already done something specifically for rust extensions (see Ian's comment above). I explored using the rb-sys image with nokogiri but ran into some errors that I didn't have time to finish investigating.

I'll try to carve out some time this weekend to rebuild context and document where support stands.

@flavorjones
Copy link
Collaborator Author

Closing the loop, I did find time to explore this again over the weekend, and although I can precompile a working nokogiri gem for MUSL, it's not reliable and I think this is because rake-compiler doesn't know how to handle the difference between x86_64-linux and x86_64-linux-musl.

I've timed out for today, but I'm pretty confident I can figure this out with a bit more work.

@ianks
Copy link

ianks commented Sep 7, 2023

@segiddins This effort would be very much appreciated. If you want to chat or discuss ideas, please don’t hesitate to contact me. Very exciting.

@eliias
Copy link

eliias commented Sep 9, 2023

Closing the loop, I did find time to explore this again over the weekend, and although I can precompile a working nokogiri gem for MUSL, it's not reliable and I think this is because rake-compiler doesn't know how to handle the difference between x86_64-linux and x86_64-linux-musl.

I've timed out for today, but I'm pretty confident I can figure this out with a bit more work.

@flavorjones IIRC I added this line to make it work, pretty hacky but doing the job https://github.com/oxidize-rb/rb-sys/blob/main/docker/Dockerfile.x86_64-linux-musl#L127

@flavorjones
Copy link
Collaborator Author

Picking this back up again today due to the recent musl changes in alpine:3.19.

@flavorjones
Copy link
Collaborator Author

See #111 for progress. I'm close to having x86_64-linux-musl working now using musl-cross-make.

@flavorjones
Copy link
Collaborator Author

Oh yeah! x86_64-linux-musl tests are green. Should be quick work to bang out the other linux platforms and make a release. EXCITE

@flavorjones
Copy link
Collaborator Author

#111 is totally green and ready for review.

@flavorjones
Copy link
Collaborator Author

v1.5.0.rc1 has been released with musl support. see https://github.com/rake-compiler/rake-compiler-dock/releases/tag/v1.5.0.rc1 for details

@flavorjones
Copy link
Collaborator Author

(I'm going to test nokogiri and sqlite3 against the RC and if they're fine then I'll ship a final release this weekend)

Quintasan added a commit to Quintasan/przypominacz-bot that referenced this issue Mar 28, 2024
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 a pull request may close this issue.

5 participants