LANGUAGE » RUST
Cargo
Usage
Rust's package manager.
shell
cargo OPTIONS COMMAND| Command | Description |
|---|---|
new | Create a new Cargo package. |
add | Add dependencies to a manifest file. |
remove | Remove dependencies from a manifest file. |
build | Compile the current package. |
run | Build if not compiled, generate a binary and run. |
test | Run the tests. |
update | Update dependencies in the Cargo.lock file. |
Creating new rust project:
shell
cargo new myprojectAdd new dependency and feature:
shell
cargo add iced
cargo add bevy -F waylandBuild and run for development:
shell
cargo runTIP
More details on how cargo update and Cargo.toml works here.
Release builds
Strip on releases to get smaller binaries by adding to Cargo.toml:
toml
[profile.release]
strip = "symbols"Further optimizations can be done with lto and codegen-units.
toml
[profile.release]
codegen-units = 1
lto = "fat"Build the binary:
shell
cargo build --releaseTests
Create a directory named tests:
txt
myproject
├── Cargo.toml
├── src
│ └── main.rs
│ └── lib.rs
└── tests
├── my_test.rs
└── my_other_test.rsRun a subset of the tests with by using a pattern.
shell
cargo test PATTERN