Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cross compile Rust code into Intel assembly on an ARM M1 Apple Silicon Mac?

I've been comparing the assembly code generated by C and Rust for x86 and ARM.

I have an M1 Mac and I found how to cross-compile C with Clang, but so far I can't find how to cross-compile Rust.

How can I generate an x86_64 binary from Rust on an M1 Mac?

like image 660
hippietrail Avatar asked Dec 17 '22 11:12

hippietrail


1 Answers

Cross-compilation is built in, just use rustup to install the target support:

$ rustup target install x86_64-apple-darwin

and build your crate like this:

$ cargo build --target x86_64-apple-darwin

Thanks to Rosetta you can even run it like this:

$ cargo run --target x86_64-apple-darwin
like image 109
HHK Avatar answered Dec 27 '22 11:12

HHK