tldr/pages/common/cargo.md

38 lines
986 B
Markdown
Raw Normal View History

2016-05-05 02:39:32 +01:00
# cargo
> Manage Rust projects and their module dependencies (crates).
> 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}}`
- Install a binary crate:
2016-05-05 02:39:32 +01:00
`cargo install {{crate_name}}`
- List installed binary crates:
2016-05-05 02:39:32 +01:00
`cargo install --list`
- 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
`cargo init --{{bin|lib}} {{path/to/directory}}`
2016-05-05 02:39:32 +01:00
- Add a dependency to `Cargo.toml` in the current directory:
2016-05-05 02:39:32 +01:00
`cargo add {{dependency}}`
2016-05-05 02:39:32 +01:00
- Build the Rust project in the current directory using the release profile:
2016-05-05 02:39:32 +01:00
`cargo build --release`
2016-05-05 02:39:32 +01:00
- Build the Rust project in the current directory using the nightly compiler (requires `rustup`):
`cargo +nightly build`
- Build using a specific number of threads (default is the number of logical CPUs):
2016-05-05 02:39:32 +01:00
`cargo build --jobs {{number_of_threads}}`