Skip to navigation

Publishing to crates.io

View as Markdown
Enterprise feature

This feature is available only for the Enterprise plan. To get started, reach out to support@buildwithfern.com.

Publish your public-facing Fern Rust SDK to the crates.io registry. After following the steps on this page, you’ll have a versioned crate published on crates.io. To distribute the SDK internally instead, generate to the local file system (optionally self-hosted) and build a .crate file with fern generate --package.

This page assumes that you have:

  • An initialized fern folder, a GitHub repository for your Rust SDK, and a Rust target in sdk-config.yml. See Generating an SDK (Rust).
Versioned package published on crates.io

Configure sdk-config.yml

Update the Rust target in sdk-config.yml to configure the crate name, client name, and publishing destination. Your sdk-config.yml should live in your source repository (or on your local machine), not the repository that contains your Rust SDK code.

1

Add a unique crate name

Your crate name must be unique in the crates.io registry, otherwise publishing your SDK will fail.

sdk-config.yml
targets:
- language: rust
package:
packageName: your-crate-name
2

Configure the client name

The generation.naming.clientName option controls the name of the generated client struct. This is the name users will use when instantiating your SDK client.

sdk-config.yml
targets:
- language: rust
package:
packageName: your-crate-name
generation:
naming:
clientName: YourClientName
3

Configure GitHub delivery and crates.io publishing

Set output.delivery to github, add the path to your GitHub repository, and set output.publish.registry to crates:

sdk-config.yml
targets:
- language: rust
package:
packageName: your-crate-name
generation:
naming:
clientName: YourClientName
output:
delivery: github
github:
repository: your-org/company-rust
publish:
registry: crates

Set up crates.io publishing authentication

1

Log into crates.io

Log into crates.io using your GitHub account.

3

Create a new API token

  1. Click New Token.
  2. Name your token (e.g., “Fern SDK Publishing”).
  3. Under Scopes, select publish-new to publish new crates and publish-update to update existing crates.
  4. Click Generate Token.
Create a new API token on crates.io
Save your new token immediately. It won’t be displayed again after you leave the page.
4

Configure crates.io authentication token

Add token: ${CRATES_IO_API_KEY} to output.publish to tell Fern to use the CRATES_IO_API_KEY environment variable for authentication when publishing to crates.io.

sdk-config.yml
targets:
- language: rust
package:
packageName: your-crate-name
generation:
naming:
clientName: YourClientName
output:
delivery: github
github:
repository: your-org/company-rust
publish:
registry: crates
token: ${CRATES_IO_API_KEY}

Publish your SDK

Decide how you want to publish your SDK to crates.io. You can use GitHub workflows for automated releases or publish directly via the CLI.

1

Set crates.io environment variable

Set the CRATES_IO_API_KEY environment variable on your local machine:

export CRATES_IO_API_KEY=your-actual-rust-token
2

Regenerate and release your SDK

Regenerate your SDK, specifying the version:

fern generate --target rust --version <version>

The rest of the release process depends on your chosen mode:

  • Release mode (default): If you didn’t specify a mode or set mode: release, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository.

  • Pull request or push mode: If you set mode: pull-request or mode: push, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request) or branch (push), then tag a new release to initiate the publishing workflow in your SDK repository.

Once the workflow completes, you can view your new release by logging into crates.io, navigating to Dashboard, and looking under My Crates.