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.88 (released around 2025-06-26). 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 testOur repository is too large to build all the packages. The previous commands only build the default set of packages.
If you make a large change, for example, use a new version of the generator, consider testing all the packages:
cargo test --workspace
cargo fmt && cargo clippy --profile=test -- --deny warnings && cargo test
git status # Shows any diffs created by `cargo fmt`Note
If you are modifying handwritten crates, note that our CI runs stricter lints
(such as missing documentation checks and exhaustive enums). You can run these
checks locally using the cargo clippy-strict alias. See
.cargo/config.toml for the exact definition.
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-llvm-cov:
cargo install cargo-llvm-cov --lockedcargo llvm-covYou may want to use a different output format. For example, many IDEs can use cobertura files:
cargo llvm-cov --cobertura --output-path cobertura.xmlUnfortunately llvm-cov does not exclude the test modules, nor the generated
code. Keep that in mind as you analyze the results.
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.
To run integration tests, you need to set up resources like Firestore, KMS keys, and service accounts in a Google Cloud Project.
We recommend using Terraform to automate this setup. See the instructions in .gcb/builds/README.md for a safe way to set up these resources in your personal test project without affecting the shared project.
Use 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_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 --locked typos-cli@1.45.0We 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.21.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