This guide is intended for contributors to the google-cloud-rust SDK. It will
walk you through the steps necessary to set up your development workstation to
compile the code, run the unit tests, and formatting miscellaneous files.
We recommend that you follow the Getting Started guide.
Once you have cargo and rustup installed the rest is relatively easy.
You will need rust >= 1.87 (released around 2025-05-15). Check the version you have installed with:
rustc --versionIf you need to upgrade, consider:
rustup updateThe code generator is implemented in Go. Follow the Download and install guide to install Golang.
Whatever works for you. Several team members use Visual Studio Code, but Rust can be used with many IDEs.
The default configuration for VS Code is to cargo check all the code when you
save a file. As the project is rather large (almost 200 crates, over 1 million
lines of code), this can be rather slow. We recommend you override these
defaults in your settings.json file:
{
"rust-analyzer.cargo.buildScripts.overrideCommand": [
"cargo",
"check",
"--quiet",
"--profile=test",
"--message-format=json",
"--keep-going"
],
"rust-analyzer.check.workspace": false
}Just use cargo:
cargo buildcargo testcargo fmt && cargo clippy --profile=test -- --deny warnings && cargo test
git status # Shows any diffs created by `cargo fmt`If you are seeing errors when running locally that are not present in the CI, you may need to update your local rust version.
We use mdBook to generate a user guide: a series of short "how-to" documents.
Install the tool using cargo install:
cargo install mdbookThen generate the documents with mdbook build:
mdbook build guideYou will find the generated book in guide/book. You can also test any code
snippets in the documentation using:
mdbook test guideSome of the samples are integration tests, you can verify they build using:
cargo build --package user-guide-samplesand verify they run using the instructions in the Integration Tests section.
To format the example code in the user guide, run the following command:
cargo fmt -p user-guide-samplesIf you are working on the user guide you may find this handy:
mdbook serve guideThis will serve the documentation on a local HTTP server (usually at
http://localhost:3000/). It will also automatically rebuild the documentation
as you modify it.
You will need to install cargo-tarpaulin:
cargo install cargo-tarpaulinOn macOS you need to enable an extra feature:
cargo install cargo-tarpaulin --features vendored-opensslcargo tarpaulin --out xmlGenerated code and test helpers are excluded by default. The configuration is in
the top level .tarpaulin.toml.
This guide assumes you are familiar with the Google Cloud CLI, you have access to an existing Google Cloud Project, and have enough permissions on that project.
We use Secret Manager, Workflows, Firestore, Speech-to-Text, and KMS to run integration tests. Follow the Enable the Secret Manager API guide to, as it says, enable the API and make sure that billing is enabled in your projects. To enable the APIs you can run this command:
gcloud services enable workflows.googleapis.com firestore.googleapis.com speech.googleapis.com cloudkms.googleapis.comVerify this is working with something like:
gcloud firestore databases list
gcloud secrets list
gcloud workflows listIt is fine if the list is empty, you just don't want an error.
The integration tests need a service account (SA) in your project. This service account is used to:
- Run tests that perform IAM operations, temporarily granting this service account some permissions.
- Configure the service account used for test workflows.
For a test project, just create the SA using the CLI:
gcloud iam service-accounts create rust-sdk-test \
--display-name="Used in SA testing" \
--description="This SA gets assigned to roles on short-lived resources during integration tests"For extra safety, disable the service account:
GOOGLE_CLOUD_PROJECT="$(gcloud config get project)"
gcloud iam service-accounts disable rust-sdk-test@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.comThe integration tests need the default Firestore database in your project. You can create this database using:
gcloud firestore databases create --location=us-central1If the database already exists you should verify that this is a Firestore native database:
gcloud firestore databases describe --format='value(type)'
# Expected output:
# FIRESTORE_NATIVEWe use KMS keys with storage. The Use customer-managed encryption keys guide covers how to create and configure a crypto key for use with Cloud Storage. We recommend you name the key ring after its location, but feel free to use a different naming convention:
GOOGLE_CLOUD_PROJECT="$(gcloud config get project)"
gcloud kms keyrings create us-central1 --location=us-central1
gcloud kms keys create storage-examples \
--keyring=us-central1 \
--location=us-central1 \
--purpose=encryption \
--rotation-period=10d --next-rotation-time=+p10d
gcloud storage service-agent --project=${GOOGLE_CLOUD_PROJECT} \
--authorize-cmek=projects/${GOOGLE_CLOUD_PROJECT}/locations/us-central1/keyRings/us-central1/cryptoKeys/storage-examplesUse cargo test to run the tests. The run-integration-tests features enables
running the integration tests. The default is to only run unit tests:
GOOGLE_CLOUD_PROJECT="$(gcloud config get project)"
env \
GOOGLE_CLOUD_RUST_TEST_SERVICE_ACCOUNT=rust-sdk-test@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com \
GOOGLE_CLOUD_RUST_TEST_WORKFLOWS_RUNNER=rust-sdk-test@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com \
GOOGLE_CLOUD_RUST_TEST_STORAGE_KMS_RING=us-central1 \
GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} \
cargo test --features run-integration-tests --package integration-tests --package user-guide-samplesOptionally, add the feature log-integration-tests to the test command to log
tracing information.
There are (at the moment) six integration tests. All using secret manager. We test the OpenAPI-generated client, the OpenAPI-generated client with locational endpoints, and the Protobuf generated client. For each version we run the tests with logging enabled and with logging disabled.
We use a number of tools to format non-Rust code. The CI builds enforce formatting, you can fix any formatting problems manually (using the CI logs), or may prefer to install these tools locally to fix formatting problems.
Typically we do not format these files for generated code, so local runs requires skipping the generated files.
We use taplo to format the hand-crafted TOML files. Install with:
cargo install taplo-cliuse with:
git ls-files -z -- \
'*.toml' ':!:**/testdata/**' ':!:**/generated/**' | \
xargs -0 taplo fmtWe use typos to detect typos. Install with:
cargo install typos-cliWe use mdformat to format hand-crafted markdown files. Install with:
python -m venv .venv
source .venv/bin/activate # Or whatever is the right command for your shell
pip install -r ci/requirements.txtuse with:
git ls-files -z -- \
'*.md' ':!:**/testdata/**' ':!:**/generated/**' | \
xargs -0 mdformatWe use yamlfmt to format hand-crafted YAML files (mostly GitHub Actions).
Install and use with:
go install github.com/google/yamlfmt/cmd/yamlfmt@v0.13.0use with:
git ls-files -z -- \
'*.yaml' '*.yml' ':!:**/testdata/**' ':!:**/generated/**' | \
xargs -0 yamlfmtWe use terraform to format .tf files. You will rarely have any need to edit
these files. If you do, you probably know how to install terraform.
Format the files using:
git ls-files -z --
'*.tf' ':!:**/testdata/**' ':!:**/generated/**' | \
xargs -0 terraform fmt