Skip to main content

Working with Cargo

Publish Cargo Package

  1. Edit $HOME/.cargo/config.toml to add a registry like below:

    [registries.onedev]
    index = "sparse+https://onedev.example.com/<project path>/~cargo/"
    credential-provider = "cargo:token"
    ParamExplanation
    <project path>path of a project with package management enabled
  2. Login to the registry:

    $ cargo login --registry onedev <onedev_access_token>
    ParamExplanation
    <onedev_access_token>OneDev access token with package write permission over the project
  3. Publish package to the registry:

    $ cargo publish --registry onedev
  4. For CI/CD job, run below to add package registry via command step:

    # Use job token to tell OneDev the build publishing the package
    # Job secret 'access-token' should be defined in project build setting as an access token with package write permission

    mkdir -p $HOME/.cargo
    cat << EOF >> $HOME/.cargo/config.toml
    [registries.onedev]
    index = "sparse+https://onedev.example.com/<project path>/~cargo/"
    credential-provider = "cargo:token"
    EOF

    cat << EOF >> $HOME/.cargo/credentials.toml
    [registries.onedev]
    token = "@job_token@:@secret:access-token@"
    EOF
    ParamExplanation
    <project path>same as above

Consume Published Cargo Package

The package detail page contains instructions on how to consume published package.