Rust dependencies
Site admins can sync Rust dependencies from any Cargo repository, including crates.io or an internal Artifactory, to their Sourcegraph instance so that users can search and navigate their dependencies.
To add Rust dependencies to Sourcegraph you need to setup a Rust dependencies code host:
- As site admin: go to Site admin > Global settings and enable the experimental feature by adding:
{"experimentalFeatures": {"rustPackages": "enabled"} }
- As site admin: go to Site admin > Manage code hosts
- Select Rust Dependencies.
- Configure the connection by following the instructions above the text field. Additional fields can be added using
Cmd/Ctrl+Space
for auto-completion. See the configuration documentation below. - Press Add repositories.
Repository syncing
There are two ways to sync Rust dependency repositories.
- Indexing (recommended): run
scip-rust
against your Rust codebase and upload the generated index to Sourcegraph using the src-cli commandsrc code-intel upload
. This is usually setup to run in a CI pipeline. Sourcegraph automatically synchronizes Rust dependency repositories based on the dependencies that are discovered byscip-rust
. - Code host configuration: manually list dependencies in the
"dependencies"
section of the JSON configuration when creating the Rust dependency code host. This method can be useful to verify that the credentials are picked up correctly without having to upload an index.
Credentials
The "repository"
field in the configuration section is automatically redacted and can optionally include the username and password of an internal Artifactory Cargo repository.
Rate limiting
By default, requests to the Cargo repository is 8 request per second.
To manually set the value, add the following to your code host configuration:
JSON"rateLimit": { "enabled": true, "requestsPerHour": 600 }
where the requestsPerHour
field is set based on your requirements.
Not recommended: Rate-limiting can be turned off entirely as well. This increases the risk of overloading the code host.
JSON"rateLimit": { "enabled": false }
Configuration
Rust dependencies code host connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.
admin/code_hosts/rust-packages.schema.json
JSON{ // An array of strings specifying Rust packages to mirror in Sourcegraph. "dependencies": null, // Other example values: // - ["[email protected]"] // Name of the git repository containing the crates.io index. Only set if you intend to sync every crate from the index. Updating this setting does not trigger a sync immediately, you must wait until the next scheduled sync for the value to get picked up. "indexRepositoryName": null, // Other example values: // - "github.com/crates.io/index" // How frequently to sync with the index repository. String formatted as a Go time.Duration. The Sourcegraph server needs to be restarted to pick up a new value of this configuration option. "indexRepositorySyncInterval": "12h", // Other example values: // - "12h" // - "10s" // Rate limit applied when making background API requests to the configured Rust repository APIs. "rateLimit": { "enabled": true, "requestsPerHour": 3600 } }