Compiling x86-64 Linux executables on M1 Mac host

If I have an M1 Mac running macOS, what's the best way to build a large Rust/Cargo project for Linux x86-64? The project uses C sys deps too. It's Debian bullseye.

I assume cross-compiling straight from macOS host to a Linux target would be annoying, because Rust can't handle setting up sysroots and linkers for me.

I would like to use the power of M1, so using another computer/cloud service is out. Qemu is also out.

Would it be best to run a VM with an ARM Linux which cross-compiles to x86-64 Linux? Has anyone tried? What's the setup you recommend?

It'll probably fail, but try using cargo build --target x86_64-linux-unknown-unknown anyway and see how it goes.

We use cross for cross-compiling at work - mainly x86 Linux to ARM Linux and Android, MacOS to iOS. They've already gone to the trouble of setting up the C toolchain and packaging it up in a Docker container, and it normally works pretty well.

1 Like

I would probably just spin up a Docker container, because that is Linux and it basically runs at native speed, as there is essentially no virtualization involved. The only thing you have to be careful about is giving your container access to a sufficiently high number of cores/threads, because AFAIK the default limit is 2 cores.

It will be a bit more work, but you can even set up a Dockerfile-based image so that you don't have to repeat installing Rust and configuring the environment should you want to re-compile the project.

1 Like

This sentence wrecks any hope of clean cross compiling. Use a VM or container.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.