2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-29 18:27:12 +00:00
|
|
|
date: 2020-08-27
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 33187ecc-81fd-4136-ad10-b69e8463bd6d
|
|
|
|
title: Rust tooling
|
|
|
|
---
|
|
|
|
|
|
|
|
# Rustc
|
|
|
|
|
|
|
|
Rustc handles Rust compilation `rustc main.rs`
|
|
|
|
|
|
|
|
# Cargo
|
|
|
|
|
|
|
|
Cargo is Rust's build system and package manager
|
|
|
|
|
|
|
|
## Cargo commands
|
|
|
|
|
|
|
|
### Create project
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
cargo new hello_cargo
|
|
|
|
```
|
|
|
|
|
|
|
|
### Build project
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
cargo build
|
|
|
|
```
|
|
|
|
|
|
|
|
### Build & run project
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
cargo run
|
|
|
|
```
|
|
|
|
|
|
|
|
1. Backtrace
|
|
|
|
|
|
|
|
When you want to see an error backtrace set the `RUST_BACKTRACE`
|
|
|
|
environment variable:
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
RUST_BACKTRACE=1 cargo run
|
|
|
|
```
|
|
|
|
|
|
|
|
### Check code
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
cargo check
|
|
|
|
```
|
|
|
|
|
|
|
|
### Build for release
|
|
|
|
|
|
|
|
``` shell
|
|
|
|
cargo build --release
|
|
|
|
```
|
|
|
|
|
|
|
|
## Cargo.toml
|
|
|
|
|
|
|
|
``` toml
|
|
|
|
[package]
|
|
|
|
name = "hello_cargo"
|
|
|
|
version = "0.1.0"
|
|
|
|
authors = ["Your Name <you@example.com>"]
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
```
|