본문으로 건너뛰기

Rust Cargo

Cargo Commands

cargo --version
cargo 1.83.0 (5ffbef321 2024-10-29)

# create a new rust project with `Cargo.toml`
cargo new hello_cargo
Creating binary (application) `hello_cargo` package

# compile the project and create an executable in `target/debug/`
cargo build
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s

# compile the project with optimizations, and create an executable in `target/release/`, the optimizaitons make your code run faster, but it takes longer to compile.
cargo build --release
Compiling hello_cargo v0.1.0 (/Users/ling/projects/playground/rust/hello_cargo)
Finished `release` profile [optimized] target(s) in 0.24s

# compile the project and run the resultant executable
cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_cargo`
Hello, world again!

# quickly checks your code to make sure it compiles but doesn't produce an executable
cargo check
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s

# build documentation provided by all your dependencies locally and open it in your browser
cargo doc --open