Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a Rust program which can be executed without using `cargo run`?

How can I make a program in Rust which can be executed from anywhere without using cargo run, by just clicking on the file?

Is there any crate? I have written code for snake game and I want to run it by just clicking on a file.

like image 201
shakaib naqvi Avatar asked Sep 06 '25 14:09

shakaib naqvi


1 Answers

If you compile a Rust application with:

cargo build --release

it will place a binary file in ./target/release. So if your application is called snake_game, you can run it with ./target/release/snake_game, or by double-clicking on that file.

This binary is completely self-contained, so you can move or copy it to somewhere else on your computer.

like image 82
Peter Hall Avatar answered Sep 11 '25 05:09

Peter Hall