2016-05-04 20:39:32 -05:00
|
|
|
# cargo
|
|
|
|
|
|
|
|
> Manage Rust projects and their module dependencies (crates).
|
2023-09-22 09:10:40 +02:00
|
|
|
> Some subcommands such as `build` have their own usage documentation.
|
2023-05-16 12:19:30 +02:00
|
|
|
> More information: <https://doc.rust-lang.org/cargo>.
|
2016-05-04 20:39:32 -05:00
|
|
|
|
|
|
|
- Search for crates:
|
|
|
|
|
|
|
|
`cargo search {{search_string}}`
|
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Install a binary crate:
|
2016-05-04 20:39:32 -05:00
|
|
|
|
|
|
|
`cargo install {{crate_name}}`
|
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- List installed binary crates:
|
2016-05-04 20:39:32 -05:00
|
|
|
|
|
|
|
`cargo install --list`
|
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Create a new binary or library Rust project in the specified directory (or the current working directory by default):
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
`cargo init --{{bin|lib}} {{path/to/directory}}`
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Add a dependency to `Cargo.toml` in the current directory:
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
`cargo add {{dependency}}`
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Build the Rust project in the current directory using the release profile:
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2025-03-15 21:28:32 +00:00
|
|
|
`cargo {{[b|build]}} {{[-r|--release]}}`
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Build the Rust project in the current directory using the nightly compiler (requires `rustup`):
|
2022-09-08 00:11:59 +01:00
|
|
|
|
2025-03-15 21:28:32 +00:00
|
|
|
`cargo +nightly {{[b|build]}}`
|
2022-09-08 00:11:59 +01:00
|
|
|
|
2023-09-22 09:10:40 +02:00
|
|
|
- Build using a specific number of threads (default is the number of logical CPUs):
|
2016-05-04 20:39:32 -05:00
|
|
|
|
2025-03-15 21:28:32 +00:00
|
|
|
`cargo {{[b|build]}} --jobs {{number_of_threads}}`
|