Command Line Tooling
dotnet new console -n DotnetConsoleApp
cargo init --name rust_app
The Rust compiler is actually called rustc. You can compile a single file by calling rustc <file_name>. Clearly, most projects aren't made up of a single file though. And that's where cargo comes in.
The respective commands will scaffold you a console application.
Build Your Application
If you want to build your application, you'd run
dotnet build
In .NET, as you might expect you'd run
cargo build
in Rust. You can also publish a release build by running:
dotnet publish -c Release
and in Rust
cargo build --release
One of the trade-offs with Rust is extended compilation times. To get the performance, the compiler does a lot of work upfront. Running a release build further extends this. If you're running/developing locally stick to cargo build.
Cross-Compilation
Rust does support cross compilation, in the same way you might run dotnet publish -c Release -r linux-x64 in .NET. There are two parts to cross compilation, the host and the target. The host platform is the one doing the compiling, and the target is what you are building for.
The target platform is specified as a triplet, which follows the structure machine-vendor-os. The machine part could be x86_64, aarch64 or even wasm32. The vendor part is going to be one of pc (Windows), apple (MacOS) and unknown for everything else. And then the os part tells the compiler what format to use for the final binary output, using a value of linux will give you .so files, windows will give you .dll.
To tell Rust to cross-compile, you pass the required target to the --target flag.
cargo build --target aarch64-unknown-linux
Before you can actually compile your application though, you'll need to add the toolchain for the required target.
rustup target add aarch64-unknown-linux
Rustup is a command-line tool that serves as the official installer and version management system for the Rust programming language.
Check your application
Rust also has a command to check your application, rather than compiling you can validate that your code is correct.
cargo check
Extending Cargo
Much like .NET tools in the .NET CLI, which allow you to extend the functionality of the dotnet command. Cargo also supports similar functionality.
One of the most useful is cargo watch, which will sit and watch your file system for changes and automatically re-run cargo check whenever your code changes.
cargo install cargo-watch
cargo watch
cargo watch also supports chaining, which means you can write things like:
cargo watch -x check -x test
Which will first run cargo check, if it completes successfully it will then automatically run cargo test.