How do I build my rust application which is compatible to run on Windows, Mac and Linux in a single command line?

I want to build my rust app in such a way that it is compatible with all major Operating Systems(Windows, Mac, and Linux). Right now, I am able to build it for Windows only(.exe) only. Is it possible to build all the necessary files using just one single command of cargo? If that's not possible how would I go about building it?

It's not possible, regardless of language, since application formats are different. You have to build Windows, Linux and MacOS binaries as three separate files - either with cross-compiling (cargo build --target target-triple), or by copying the code on each target platform.

3 Likes

Not entirely true...:wink:

αcτµαlly pδrταblε εxεcµταblε

To the OP though, for all practical purposes what @Cerberuser says is true

5 Likes

In practice you're going to need a Windows machine/VM, a Linux machine/VM, and a Mac with a $99 Apple Code Signing Developer Id Certificate, and compile on each one individually. CI services like AppVeyor and GitHub Actions may help.

Rust by itself can only cross-compile static libraries. Executables need cross-linkers and system libraries that Rust doesn't ship with, and which usually are super painful to set up for anything non-trivial.

1 Like

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.