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