Cross compiling Rust programs on Macos to Linux

I found a nice tutorial how to cross-compile and link a static binary on Macos for Linux with Rust. However the tutorial uses brew to install the musl-cross toolchain.

Is the musl-cross package available on Nix for Macos? The “nix search musl” shows “musl” and “muslCross” but this are only the musl libraries and not the whole toolchain that let me cross-compile the Rust program. The later is not even installable on Macos.

1 Like

I don’t have a mac to test on and may be totally wrong, but have you tried following Cross Compiling - NixOS Wiki? You’ll need to set config = x86_64-unknown-linux-musl instead, but the rest might work.

Thank you very much for the article. Now I am able to cross compile Rust programs.