Bazel Build
Giztoy uses Bazel as its unified build system across all languages and platforms.
Why Bazel?
- Multi-language Support: Build Go, Rust, C/C++ with a single tool
- Hermetic Builds: Reproducible builds across different machines
- Cross-platform: Target multiple platforms from a single codebase
- Incremental: Only rebuild what changed
Quick Start
Prerequisites
- Bazelisk (recommended) or Bazel 7.x+
- Go 1.24+ (for native Go builds)
- Rust 1.80+ (for native Rust builds)
Build Commands
# Build everything
bazel build //...
# Build specific targets
bazel build //go/cmd/minimax # Go CLI
bazel build //rust/cmd/minimax # Rust CLI
# Run tests
bazel test //...
# Run a binary
bazel run //go/cmd/minimax -- --help
Project Structure
graph LR
subgraph root["giztoy/"]
mod[MODULE.bazel]
build[BUILD.bazel]
bazelrc[.bazelrc]
ver[.bazelversion]
subgraph go["go/"]
go_build[BUILD.bazel]
go_cmd["cmd/<br/>Go CLI targets"]
go_pkg["pkg/<br/>Go library targets"]
end
subgraph rust["rust/"]
rust_build[BUILD.bazel]
rust_cmd["cmd/<br/>Rust CLI targets"]
rust_lib["*/<br/>Rust library crates"]
end
subgraph third["third_party/"]
opus[opus/]
portaudio[portaudio/]
soxr[soxr/]
end
end
Rules Used
| Language | Rules |
|---|---|
| Go | rules_go + Gazelle |
| Rust | rules_rust + crate_universe |
| C/C++ | Built-in cc_library, cc_binary |
| Shell | rules_shell |
Dependency Management
Go Dependencies
Go dependencies are managed via go/go.mod and synced with Gazelle:
# Update Go dependencies
cd go && go mod tidy
# Regenerate BUILD files
bazel run //:gazelle
Rust Dependencies
Rust dependencies are managed via rust/Cargo.toml and synced with crate_universe:
# Update Cargo.lock
cd rust && cargo update
# Bazel will automatically fetch crates on next build
C/C++ Dependencies
Third-party C libraries are configured in third_party/ with custom BUILD files.
Cross-Platform Builds
Supported Platforms
| Platform | Status |
|---|---|
| Linux (x86_64, arm64) | ✅ |
| macOS (x86_64, arm64) | ✅ |
| Android | ✅ |
| iOS | ✅ |
| HarmonyOS | ✅ |
| ESP32 | 🚧 |
Platform-specific Builds
# Android
bazel build --config=android //...
# iOS
bazel build --config=ios //...
Common Tasks
Adding a New Go Package
- Create the package in
go/pkg/mypackage/ - Run Gazelle to generate BUILD file:
bazel run //:gazelle
Adding a New Rust Crate
- Create the crate in
rust/mypackage/ - Add to
rust/Cargo.tomlworkspace members - Create
BUILD.bazelwithrust_libraryrule
Adding a C/C++ Dependency
- Create config in
third_party/libname/ - Add
BUILD.bazelwithcc_libraryrule - Reference from dependent targets
Troubleshooting
Clean Build
bazel clean --expunge
bazel build //...
Dependency Issues
# Refresh Go deps
bazel run //:gazelle -- update-repos -from_file=go/go.mod
# Refresh Rust deps
bazel clean --expunge # crate_universe re-fetches on next build