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
:
[build]
target=aarch64-unknown-linux-gnu
[[target.aarch64-unknown-linux-gnu]
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): static.rust-lang.org
"GET /rustup.sh 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/rustup.sh --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/rustup.sh', '--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.