Build for production?

I followed a tutorial to build a snake game in Rust with PistonWindow.

I would like to produce a build file for mac, windows, and linux respectively, so that I can send someone the file and they could download and double click to play the game.

I see the executable file in /target/debug, however when I double click that on my mac I get an 'The application "terminal" is not open anymore' error message. Is this an issue specific to my code, or my use of cargo run/build?

My background in building desktop applications is from writing Electron Apps with javascript. I searched around a good little bit and have not found my answer.

Seems to be a bug in macOS. Restarting supposedly fixes it: https://apple.stackexchange.com/questions/354902/the-application-is-not-open-anymore

1 Like

On macOS, full-fledged GUI apps are more complicated than a single executable. In order to make a properly functioning application, you'll need to create a so-called app bundle, with an Info.plist file, the executable, icons, dependence libraries, etc. all in the correct folder structure. You can probably hack your way around that but you really shouldn't.

Here's the official documentation on app bundles.

2 Likes

You generally need to package macOS applications for distribution. This is most important when the app needs to be shipped with dylib dependencies and other resources. Running an executable from the terminal on macOS has some "non-standard" behavior, but it can work well enough for developers. For users, you're going to want an app bundle.

cargo-bundle can be used to build installers for various platforms.

For distribution in the Apple app store, the app must be signed, but that doesn't appear to be supported by cargo-bundle yet.

2 Likes

Thanks. That worked for making the exe file launch on click.

Thanks. Cargo-bundle worked nicely. In order to cross compile for other OS, I see that you need to specify the target.

Could you point me in the direction of how I could understand those target descriptors?

I didn’t see an obvious solution to compile for Windows 10 for example. Is that under windows gnu or msvc?

There's a list of supported targets in the rustc book: https://doc.rust-lang.org/nightly/rustc/platform-support.html

Cross compiling can be very annoying because you will usually have to install a compiler toolchain for your target. E.g. for cross-compiling on a macOS host to Windows you will need MinGW installed on the Mac.

If you really want to get into cross compiling, your best bet is probably trust.

1 Like

So, not as important for this project, but then say I were to create a desktop application and wanted to offer it for linux, windows and mac. What is the common approach? And what are the options in the context of Rust?

Is an installer compiling the application from source on the users device to avoid the issue you are describing with cross compiling?

Thanks again.

No, the trust repo shows how your CI pipeline can build releases on the various systems. There's no cross compilation involved, since CI runs the compiler on each host OS. The only thing the user needs to do is download whatever binary or installer your CI pipeline produces for their system.

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.