Building arm64 against musl libc


I’ve recently been looking into cross-compiling with rust. So I implemented support for that in snapcraft - for those who’re interested in trying it out, it’ll be available as of snapcraft 2.32.

rustup --with-target fetches the toolchain for me, and that’s basically the key to cross-compiling. Unfortunately the linker isn’t autodetected, so I came up with this simple autogenerated .cargo/config:


linker = aarch64-linux-gnu-gcc

Now that’s pretty sweet.

My next idea was to build static binaries. So I made snapcraft link against musl using the same approach. Unfortunately it turns out, my target, arm64, has no toolchain?..

Starting new HTTPS connection (1):
"GET / HTTP/1.1" 200 61986
rustup: gpg available. signatures will be verified
rustup: downloading manifest for 'stable'
rustup: unable to find package url for std, for aarch64-unknown-linux-musl
/tmp/tmp7ds8o5z0/parts/rust-musl/rust/ --prefix=/tmp/tmp7ds8o5z0/parts/rust-musl/rust --disable-sudo --save --with-target=aarch64-unknown-linux-musl
Command '['/bin/sh', '/tmp/tmpfo580w8_', '/tmp/tmp7ds8o5z0/parts/rust-musl/rust/', '--prefix=/tmp/tmp7ds8o5z0/parts/rust-musl/rust', '--disable-sudo', '--save', '--with-target=aarch64-unknown-linux-musl']' returned non-zero exit status 1

Is there a process to request more architectures to support musl? Or is there another option? I’ve heard of multirust, but I’m not entirely sure how it relates to rustup or if it uses different toolchains.


This required some additional support in the compiler, and then in the CI system to automatically build for aarch64-unknown-linux-musl. That was merged recently :slight_smile:

So, now you can run rustup target add --toolchain nightly aarch64-unknown-linux-musl to get the target for a nightly toolchain. It should be in the next beta, and then in stable 1.22, I would think.