Publishing to crates.io

View as Markdown

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.

Versioned package published on crates.io

This page assumes that you have:

Configure generators.yml

1

Configure output location

Change the output location in generators.yml from local-file-system (the default) to crates to indicate that Fern should publish your crate directly to the crates.io registry:

generators.yml
1groups:
2 rust-sdk:
3 generators:
4 - name: fernapi/fern-rust-sdk
5 version: 0.13.3
6 output:
7 location: crates
2

Add a unique crate name

Your crate name must be unique in the crates.io registry, otherwise publishing your SDK will fail. Update your crate name if you haven’t done so already:

generators.yml
1groups:
2 rust-sdk:
3 generators:
4 - name: fernapi/fern-rust-sdk
5 version: 0.13.3
6 output:
7 location: crates
8 package-name: your-crate-name
3

Configure clientClassName

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

generators.yml
1groups:
2 rust-sdk:
3 generators:
4 - name: fernapi/fern-rust-sdk
5 version: 0.13.3
6 output:
7 location: crates
8 package-name: your-crate-name
9 config:
10 clientClassName: YourClientName # must be PascalCase
4

Add repository location

Add the path to your GitHub repository to generators.yml:

generators.yml
1groups:
2 rust-sdk:
3 generators:
4 - name: fernapi/fern-rust-sdk
5 version: 0.13.3
6 output:
7 location: crates
8 package-name: your-crate-name
9 config:
10 clientClassName: YourClientName
11 github:
12 repository: your-org/your-rust-sdk

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 generators.yml to tell Fern to use the CRATES_IO_API_KEY environment variable for authentication when publishing to crates.io.

generators.yml
1groups:
2 rust-sdk:
3 generators:
4 - name: fernapi/fern-rust-sdk
5 version: 0.13.3
6 output:
7 location: crates
8 package-name: your-crate-name
9 token: ${CRATES_IO_API_KEY}
10 config:
11 clientClassName: YourClientName
12 github:
13 repository: your-org/your-rust-sdk

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 --group rust-sdk --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.