Search code examples
rustrust-cargo

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.


Solution

  • 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.