Manage Rust project dependencies

Configure and vendor dependencies for Rust projects on Red Hat Enterprise Linux by using the Cargo build tool to control crate versions and offline builds.

Prerequisites

  • Rust Toolset is installed.

Configure Rust project dependencies

Configure the dependencies of your Rust project by using the Cargo build tool. Edit the Cargo.toml file in the project directory and rebuild your project. Cargo downloads packages and dependencies locally. Use cargo build or cargo run to compile your code and produce a runnable executable.

Before you begin

Procedure

  1. In your project directory, edit the Cargo.toml file, and list each dependency in the following format in the [dependencies] section:
    <crate_name> = <version>

    Rust code packages are called crates.

  2. Rebuild your project:
    $ cargo build
  3. Run your project:
    $ cargo run

Vendor Rust project dependencies

Create a local copy of the dependencies of your Rust project for offline redistribution by using the Cargo build tool (vendoring). Vendored sources live in the vendor directory, including any Windows-target crates you captured. Point Cargo at that tree to build offline without network access.

Before you begin

Procedure

To vendor your Rust project with dependencies by using Cargo, enter in the project directory:
$ cargo vendor