Edit

Restore Cargo packages (CLI)

Azure Artifacts enables developers to host various package types in a feed, whether published directly or saved from upstream sources. This guide helps you set up your project, authenticate with your Azure Artifacts feed, and use the command line to restore Cargo packages directly from your feed.

Prerequisites

Product Requirements
Azure DevOps - An Azure DevOps organization.
- An Azure DevOps project.
- Download and install rustup. You'll need Cargo version 1.74.0 or later.

Create a feed

To consume and publish Rust crates with Azure Artifacts, it's recommended to use two separate feeds: One dedicated feed for consuming crates from crates.io, and another separate feed for publishing your internal crates. See Source Replacement for more details. If you don’t already have a feed set up, here’s how to create one:

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Artifacts, and then select Create Feed.

  3. Provide a Name for your feed, and set its Visibility. If the feed is intended for consuming crates from crates.io, check the option to Include packages from common public sources. If the feed is for publishing private packages, leave that option unchecked. finally select the appropriate Scope for your feed. Scoping the feed to a specific project is recommended over organization-wide scope.

  4. Select Create when you're done.

    A screenshot showing how to create a new feed in Azure Artifacts.

Restore packages

To restore your dependencies, make sure that you have your dependecies listed in your Cargo.toml under [dependencies]. If you're referencing crates from crates.io through your upstreaming feed using the replace-with configuration, specify them as follows:

[dependencies]
CRATE_NAME = "VERSION_NUMBER"

If you're referencing crates from your private Azure Artifacts feed, you must explicity specify the registry:

[dependencies]
CRATE_NAME = { version = "VERSION_NUMBER", registry = "FEED_NAME" }
  1. If you haven't authenticated with your feed yet, follow the steps in the Project setup to configure your config files, set up a credential provider, and log in to the registry.

  2. Run the following command in your project directory to build your project and restore your dependencies from the feed:

    cargo build
    

The downloaded crates are cached locally in your ~/.cargo/registry/cache/<registry-hash>/ where the registry-hash is a unique identifier based on your feed URL.

A screenshot displaying the result of the cargo fetch command.