Rust / Cargo
Note
Only available in Sonatype Nexus Repository Pro. Interested in a free trial? Start here.
Rust is known for its memory safety, concurrency, and performance. Cargo, Rust's build tool and package manager, automates dependency management, building, and testing.
Cargo uses a Cargo.toml
manifest file where developers declare their project's dependencies. It then automatically fetches and builds these dependencies from the crates.io
registry or other sources, ensuring consistent builds. It also automates the compilation and linking process, including handling builds for different target platforms and configurations.
Supported Features and Limitations
This section covers supported features and limitations for Rust Cargo in Nexus Repository.
Incompatible with Community Plugin - Nexus Repository's native support for Rust Cargo is not compatible with the existing community plugin. You will not be able to migrate data from the plugin.
Repository Types - Hosted, proxy, and group
Component Upload via Cargo Publish Only - Sonatype Nexus Repository does not currently support uploading components via UI or API; you can use the
cargo publish
command to publish components to a hosted repository.Cargo Protocol - Nexus Repository only supports Cargo's Sparse protocol; it does not support the older Git protocol
Cargo Versions - 1.68+
Repository Management - cleanup policies, tasks, import, export, and search
Nexus Repository does not currently support the Cargo client native search capability
Nexus Repository does support
yank
andunyank
endpoints; however, useyank
with caution as it can break builds for users who haven't locked their dependencies
Security - SSL configuration (HTTP/HTTPS settings) for secure data transfer and repository access; authentication via anonymous access and user tokens
REST APIs - Compatible with the repositories, search, component, asset, and tags REST APIs
Pro Features - Staging, tagging, content replication, Firewall integration
Support Features - Auditing and logging
Authenticating with User Tokens for Cargo
For Cargo, user tokens are configured in the Cargo credentials config file (credentials.toml
). Each token is associated with a specific repository and only authenticates access to that particular repository. Tokens are primarily used during the crate publishing process.
To use your user token for Cargo repository authentication, take the following steps:
Generate and access your user token following the instructions in our user token help documentation. Copy the base64 representation of your user token.
Open your Cargo credentials config file (
credentials.toml
); add and save the following lines, replacing the registry name with the name of your repository, and<your-token>
with the base64 representation of your user token:[registries.cargo-hosted] token = "Basic <your-token>" [registries.my-hosted-repo] token = "Basic <your-token>"
Alternatively, you can use a command like the following to update the file:
cargo login --registry <your-repo-name>
This will result in a prompt for your repository's token. Provide it as
Basic <your-token>
to update the file.Or, you can use an environment variable by running a command like the following:
export CARGO_REGISTRIES_<REPO_NAME>_TOKEN="Basic <your-token>"
You can test your authentication by running a command like
cargo publish
to publish a crate to your hosted repository.