See the gist at https://gist.github.com/smaeul/77d2f4cb3a883f87e297a32fac257eb5 Contents of the gist are copied below:
I worked on adding support to the Rust compiler for bootstrapping on and running on several Linux distributions that use musl. Musl is an alternative C library (compared to glibc) focused on being "fast, simple, free, and … correct". Linux distributions using musl libc include Alpine, Adélie, Gentoo, and Void.
Unlike glibc, musl supports fully statically-linked binaries. This allows creation of programs that can be freely copied to any machine running Linux 2.6 or newer, and will run properly no matter what userspace libraries are installed. Historically, since glibc has been the dominant system libc, musl has filled this static-linking niche, and Rust support for musl was limited to cross-compiling static libraries and binaries.
Today, the Linux distributions listed above (among others) provide an installation with musl serving as the system libc, and programs dynamically linked to it. Providing these distributions with a native Rust compiler required removing some assumptions made that musl == static, and fixing how rustc interacted with other system libraries (e.g. libgcc) on musl-based platforms.
I chose to work on this issue because I use Gentoo's musl profile on all of the computers I administer (laptop, desktop, firewall). Adding native musl support benefitted me directly, allowing me to install Rust directly on my system instead of needing to use a glibc-based virtual machine. Besides making it easier to learn and use Rust for personal projects, having a native rustc available is necessary for compiling software packages that have Rust components, such as Mozilla Firefox. Without native Rust, musl-based distributions would have been forced to ship old versions of Firefox (bad for security) or pre-build its Rust components with a glibc-hosted cross compiler.
A couple of people had hacked together a native Rust compiler on dynamic musl before, but they had been unable to reliably bootstrap newer compiler versions, and so these efforts quickly became out of date. For example, the Alpine package linked above is 8 months (5 feature releases) behind.
Two weeks ago, I was able to create a patchset and build script for the Rust package on Gentoo, bootstrapping a compiler from glibc over the course of a few days. However, the changes I made were not developed with upstreaming in mind. More importantly, the rustc build system was completely redone in the intervening time! The move from Makefiles to Cargo-based infrastructure meant that all of my build system changes had to be rewritten from scratch.
This could have been put off for a few more months, until Rust 1.17 (the first version to remove the Makefile-based build scrits) was stable, but since a couple of developers from the Rust project were here at the hackathon, I wanted to get this fixed and upstreamed over the weekend. Working with mentor Alex Crichton, we were able to build and verify the series of changes needed, combining his knowledge of the Rust build system with my experience porting software to work with musl, and the musl-based test environment I was able to provide.
After completing and verifying that these changes worked, I divided them into a series of patches and created a pull request. From the feedback that Alex (the mentor) was able to provide, this pull request should be merged in the near future. After that, I simply have to wait until Rust 1.17 is released, or backport these changes to Rust 1.15 and 1.16 to use them immediately (which should be trivial). The final step is to upstream my changes to the Gentoo ebuild (the script used to generate the "rust" package).
Due to the interest from me and other musl users, the Rust project has expressed interest in adding native or cross-compiled dynamic musl builds to their continuous integration system, ensuring that this use case continues to work, and making bootstrapping a native build significantly easier. Until/unless that happens, I may need to provide help or prebuilt bootstrap compilers to other musl-based Linux distributions to help them create their own Rust packages.
I worked alone on the project, but help from Alex, the Rust developer who wrote the build system in the first place, was invaluable. Thanks!
Log in or sign up for Devpost to join the conversation.