Language Ecosystems
Each programming language comes with its own ecosystem of tools, practices, and expectations. This guide explores how modern Bazel (with Bzlmod) integrates with various language ecosystems.
Go Ecosystem
Modern Go Integration
Module Configuration
python# MODULE.bazel bazel_dep(name = "rules_go", version = "0.46.0") bazel_dep(name = "gazelle", version = "0.35.0") # Configure Go toolchain go_sdk = use_extension("@rules_go//go:extension.bzl", "go_sdk") go_sdk.download(version = "1.21.5")Gazelle Integration
python# BUILD.bazel gazelle( name = "gazelle", prefix = "example.com/myproject", )
Development Workflow
Adding Dependencies
bash# Add dependency to go.mod go get github.com/example/pkg # Update Bazel dependencies bazel run //:gazelleIDE Integration
- gopls works with go.work
- VSCode/IntelliJ support
- Seamless debugging
Rust Ecosystem
Modern Rust Integration
Module Configuration
python# MODULE.bazel bazel_dep(name = "rules_rust", version = "0.40.0") # Configure Rust toolchain rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( edition = "2021", versions = ["1.75.0"], )Crates Management
python# BUILD.bazel rust_binary( name = "app", srcs = ["src/main.rs"], deps = [ "@crates//:serde", "@crates//:tokio", ], edition = "2021", )
Development Experience
Dependency Management
- Direct crates.io integration
- Feature flag support
- Platform-specific deps
IDE Support
- rust-analyzer compatibility
- Integrated debugging
- Test runner support
JavaScript/TypeScript Ecosystem
Modern JS/TS Integration
Module Configuration
python# MODULE.bazel bazel_dep(name = "aspect_rules_js", version = "1.34.0") bazel_dep(name = "aspect_rules_ts", version = "2.1.0") npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm") npm.npm_translate_lock( name = "npm", pnpm_lock = "//:pnpm-lock.yaml", verify_node_modules_ignored = "//:.npmignore", )Build Configuration
python# BUILD.bazel ts_project( name = "app", srcs = glob(["src/**/*.ts"]), deps = [ "//:node_modules/@types/node", "//:node_modules/express", ], )
Modern Development Flow
Package Management
- pnpm for deterministic installs
- Direct npm registry access
- Lockfile synchronization
Build Tools
- esbuild for fast builds
- SWC for transpilation
- Modern bundling support
Cross-Language Projects
Shared Dependencies
Proto Files
python# MODULE.bazel bazel_dep(name = "rules_proto", version = "6.0.0") # Proto generation for multiple languages proto = use_extension("@rules_proto//proto:extensions.bzl", "proto") proto.toolchain()Generated Code
python# BUILD.bazel proto_library( name = "api_proto", srcs = ["api.proto"], ) go_proto_library( name = "api_go_proto", protos = [":api_proto"], ) rust_proto_library( name = "api_rust_proto", protos = [":api_proto"], )
Best Practices
Module Organization
- Clear dependency boundaries
- Version alignment
- Platform compatibility
Development Flow
- Language-native tools for iteration
- Bazel for production builds
- Consistent toolchain versions
Common Patterns
1. Development Mode
bash
# Go development
go test ./...
bazel test //...
# Rust development
cargo check
bazel build //...
# TypeScript development
pnpm run dev
bazel run //app:dev2. Production Builds
bash
# Cross-platform build
bazel build //... --platforms=@rules_rust//rust/platform:linux_amd64
bazel build //... --platforms=@rules_rust//rust/platform:darwin_arm64IDE Integration
VSCode Setup
Extensions
- Bazel extension
- Language servers
- Debugger support
Settings
json{ "bazel.buildFlags": ["--config=dev"], "bazel.testFlags": ["--test_output=streamed"] }
Conclusion
Modern Bazel with Bzlmod provides:
Simplified Dependencies
- Direct registry integration
- Version resolution
- Platform support
Better Integration
- Native tool compatibility
- IDE support
- Development workflows
Cross-platform Support
- Consistent toolchains
- Platform-specific builds
- Reproducible results
The key is leveraging Bzlmod's modern features while maintaining compatibility with language-native development workflows.
