Rust's Build & Package Manager - Cargo
Cargo is Rust build and package manager
If Rust is all installed and up without any issues, you can check for the version on the cargo $ cargo --version
Creating a Project With Cargo
Let's create a rust project
$ cargo new hello_cargo
$ cd hello_cargo
Now let's see what's inside this project
It also initializes a new GIT repo along with a .gitignore file.
The cargo.toml file holds the required configuration based on the purpose and scope of the project
All the source files go into the src folder. Cargo when initializing the project has created a main.rs file under the src folder. This is where we will write our first introductory program
领英推荐
The main is the special function that runs first in every executable Rust program
Now that the minimum requirements are in place, lets initiate the build of the project $ cargo build
This build creates an executable file under a "target/debug" folder of the current working directory.
Then you can simply use this command to run. If all goes well, the output should be right there on the console
$ ./target/debug/hello_cargo
You can also use $ cargo run to both build and run the project and executables respectively
The command $ cargo check is used to check on for compilations and does not produce any executables. This is lightweight and generally used to check for any compilation errors as and when we need it.
End of the day, the code has to be production ready and $ cargo build --release will compile the code with optimizations and put the executables under the target/release,
Recap