4 ms·
Is there an easy way to cross compile rust?
When developing applications in Go, setting the target OS and target architecture is all you need to compile your application across to another platform.
I have recently started learning rust and it seems like there isn't an easy way to cross compile. Did I miss something in the documentation?
Why is that?
- digikata 6y agorustup target install <arch> e.g. armv7-unknown-linux-gnueabi cargo build --target <arch> You can also set it by default: https://stackoverflow.com/questions/49453571/how-can-i-set-default-build-target-for-cargo https://stackoverflow.com/questions/49453571/how-can-i-set-d...
- steveklabnik 6y agoRust tends to be harder than Go for a few reasons, but they all sort of boil down to this: Go has created its own little world, which means that it makes cross compiling easier. Rust tends to work directly with the system, which means that cross compiling is harder. For example, a lot of Rust projects are totally fine wrapping a C library to get the job done. This means you don’t just need Rust set up to cross compile, but also C. There’s a very strong push for pure-Go code bases in Go for this reason. Go also attempts to not use libc if possible, though they’ve weakened that a bit over the years. We use the system linker, and so cross compiling to x86_64-pc-windows-msvc is tough, because link.exe won’t run outside of Windows, for example. That being said, some combinations are easy. Compiling to embedded targets is a piece of cake, as the other comment explains. Cross compiling between UNIXes is easy, and cross compiling to Linux is easy.
- apatheticonion 6y agoThis makes a lot of sense, thanks!