This guide explains how to contribute to the TypeSpec Rust emitter project, including how to build, test, and develop the codebase.
- Node.js (>=20.0.0) - Required for the TypeScript emitter
- pnpm (10.10.0) - Package manager for Node.js dependencies
- Rust (1.80+) - Required for building and testing generated Rust code
- Git - Version control
This project is a TypeSpec emitter that generates Rust SDK code from TypeSpec specifications:
/packages/typespec-rust/- Main TypeScript emitter package/packages/typespec-rust/src/- TypeScript emitter source code/packages/typespec-rust/test/- Generated Rust test crates and TypeScript unit tests/packages/typespec-rust/test/spector/- Integration test crates generated from spector specs/packages/typespec-rust/test/sdk/- SDK test crates/eng/- Build and CI/CD pipeline configuration
The project has two build phases: building the TypeScript emitter and building the generated Rust code.
Navigate to the emitter package directory:
cd packages/typespec-rustInstall dependencies:
pnpm installBuild the TypeScript emitter:
pnpm buildThis compiles the TypeScript source code to JavaScript in the dist/ directory.
The project includes extensive test suites generated from TypeSpec specifications. When you modify the emitter or need to update tests, regenerate them:
cd packages/typespec-rust
pnpm run tspcompileTo regenerate only specific test crates (useful during development):
pnpm run tspcompile --filter=<pattern>For example, to regenerate only tests containing "oauth":
pnpm run tspcompile --filter=oauthThe tspcompile script:
-
Compiles TypeSpec specifications from:
@typespec/http-specs(standard HTTP specifications)@azure-tools/azure-http-specs(Azure-specific specifications)- Local test specifications in
test/tsp/
-
Generates Rust crates in:
test/spector/- Integration tests from spector specificationstest/sdk/- SDK tests from custom TypeSpec filestest/other/- Additional test scenarios
-
Updates the workspace
Cargo.tomlwith all generated crates
Each generated crate includes:
Cargo.toml- Rust package configurationsrc/lib.rs- Entry point (usually not regenerated to preserve customizations)src/generated/- Generated Rust client code (fully regenerated)tests/- Integration test files that use the generated client
After generating Rust test crates (as described above), you can build the Rust code:
cd packages/typespec-rust/test
cargo buildThis builds all generated Rust crates in the workspace.
Run the emitter's TypeScript unit tests:
cd packages/typespec-rust
pnpm testFor CI with coverage:
pnpm run test-ciFirst, ensure all Rust test crates compile:
cd packages/typespec-rust/test
cargo buildMost integration tests require the spector test server running on localhost:3000. The integration tests make HTTP calls to this server to validate the generated Rust client code.
Start the spector server:
cd packages/typespec-rust
pnpm spector --startIn another terminal, run the Rust tests:
cd packages/typespec-rust/test/spector
cargo test --no-fail-fastStop the spector server when done:
cd packages/typespec-rust
pnpm spector --stopNote: Integration tests connect to the test server and make real HTTP requests to validate that the generated client code works correctly with the expected API responses.
To test a specific generated crate:
cd packages/typespec-rust/test/spector/<test-name>
cargo testTo run a specific test within a crate:
cd packages/typespec-rust/test/spector/<test-name>
cargo test <test-function-name>To see detailed test output:
cargo test -- --nocaptureDebugging Test Failures: If tests fail, check:
- That the spector server is running (
pnpm spector --start) - That the generated code compiled successfully (
cargo build) - Review the test output for HTTP errors or assertion failures
- Check if the TypeSpec specification changed and regeneration is needed
cd packages/typespec-rust
pnpm eslintcd packages/typespec-rust/test
cargo clippy --workspace --all-features --all-targets --keep-going --no-depsFor strict linting (CI mode):
RUSTFLAGS='-Dwarnings' cargo clippy --workspace --all-features --all-targets --keep-going --no-depscd packages/typespec-rust/test
cargo fmt --all-
Make changes to the TypeScript emitter code in
packages/typespec-rust/src/ -
Build the emitter:
cd packages/typespec-rust pnpm buildFor continuous development, use watch mode:
pnpm watch
-
Regenerate test crates to test your changes:
pnpm run tspcompile
-
Build generated Rust code:
cd test cargo build
-
Run tests:
# TypeScript tests cd packages/typespec-rust pnpm test # Rust integration tests pnpm spector --start cd test/spector cargo test cd ../../ pnpm spector --stop
-
Run linting:
# TypeScript linting cd packages/typespec-rust pnpm eslint # Rust linting cd test cargo clippy --workspace --all-features --all-targets
When making changes to the emitter, follow these versioning guidelines:
Increment the patch version for:
- Bug fixes that don't change the public API
- Internal refactoring or improvements
- Documentation updates
- Minor improvements to generated code quality
- Performance improvements
Increment the minor version for:
- New features or capabilities in the emitter
- Support for new TypeSpec constructs or decorators
- Breaking changes to generated Rust code structure
- Changes that require users to update their generated code
- New configuration options or emitter settings
Increment the major version for:
- Breaking changes to the emitter's public API
- Changes that require TypeSpec specification updates
- Fundamental changes to the emitter architecture
- Removal of deprecated features
Update the version in packages/typespec-rust/package.json and document changes in packages/typespec-rust/CHANGELOG.md.
The CI pipeline runs the following checks on every pull request:
- Build - Compiles TypeScript emitter
- Lint - Runs ESLint on TypeScript code
- Test - Runs TypeScript unit tests with coverage
- Regenerate - Regenerates all test crates and verifies no changes
- Compile - Builds all generated Rust crates
- Clippy - Runs Rust linting on generated code
- Integration Tests - Runs spector integration tests
Ensure all these checks pass before submitting a pull request.
- Check existing issues and discussions
- Review the TypeSpec documentation
- Look at the generated code in
test/directories for examples - Examine the CI pipeline in
/eng/pipelines/for the complete build process