Rust cross-compilation using Nix - general working implementation for reference

A part of Flakebox is a fully integrated support for cross-compiling Rust including non-trivial non-Rust dependencies. Build on Linux and Darwin, targeting Linux, Android, Darwin and iOS (limited capacity).

This also works in dev shells with cargo build --target <...>. (see nix develop .#crossFull), mixing and matching all targets one wish to support.

We’ve been using some of it for over a year in Fedimint, but with Flakebox I’ve finally had a time to sit down, extract and polish it, add cross-compilation to Linux using pkgs.pkgsCross, add unit-tests etc.

Even if you’re not planning to use Flakebox, it might be a good reference for people looking how to handle it, so I’m hoping it will help some people redirected by search engines here.

Rust Nix Nixpkgs Cross-Compilation (for search engines, I hope it’s OK)

6 Likes