Stream: nix

Topic: Rust cross-compilation


view this post on Zulip Drew Jose (Feb 14 2024 at 07:02):

Hello, everyone! I've been using nix mostly as a package manager with home-manager, and today I had a dillemma: cross compiling.
On trying to do so it gives you the helpful advice to do rustup target add, which prompted me to delete all my rust packages from home manager and just install rustup.

https://emacs.ch/@crmsnbleyd/111928501351116776

Have any of you ever done cross compilation with rust without resorting to this?

view this post on Zulip Andreas (Feb 14 2024 at 07:37):

There is a thing called flakebox which is supposedly offering this. Maybe worth a try. They have a tutorial including cross-compilation here: https://github.com/rustshop/flakebox/blob/master/docs/building-new-project.md

view this post on Zulip Srid (Feb 14 2024 at 08:46):

What are you cross-compiling to?

See

They both use https://crane.dev/ and in the first repo you can see rust-toolchain.toml containing the wasm target which is what Nix uses.

view this post on Zulip Srid (Feb 14 2024 at 08:47):

https://crane.dev/examples/cross-rust-overlay.html

view this post on Zulip Srid (Feb 14 2024 at 08:49):

Flakebox uses crane; I'd recommend fiddling with crane first.

view this post on Zulip Drew Jose (Feb 14 2024 at 08:58):

Srid said:

What are you cross-compiling to?

from Darwin to x86_64-unknown-linux-gnu

view this post on Zulip Srid (Feb 14 2024 at 08:59):

You can try it with https://crane.dev/examples/cross-rust-overlay.html

view this post on Zulip Srid (Feb 14 2024 at 09:01):

I also just came across this. Looks interesting, but don't know much about it:

https://old.reddit.com/r/rust/comments/11okj5w/rust_crosscompilation_without_struggles_by_using/

view this post on Zulip Srid (Feb 14 2024 at 09:02):

With it, you can build Linux binaries and docker images from the MacOS hosts without any virtual machines.

view this post on Zulip Srid (Feb 14 2024 at 09:03):

Full flake example

view this post on Zulip Srid (Feb 14 2024 at 09:03):

Unlike crane, this uses whatever build infra nixpkgs provides. As an interesting aside, the example uses #flake-parts

view this post on Zulip Notification Bot (Feb 14 2024 at 11:29):

Drew Jose has marked this topic as resolved.

view this post on Zulip Notification Bot (Feb 14 2024 at 11:29):

Drew Jose has marked this topic as unresolved.


Last updated: Nov 15 2024 at 12:33 UTC