Bazel Build

Giztoy uses Bazel as its unified build system across all languages and platforms.

Why Bazel?

  1. Multi-language Support: Build Go, Rust, C/C++ with a single tool
  2. Hermetic Builds: Reproducible builds across different machines
  3. Cross-platform: Target multiple platforms from a single codebase
  4. 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

LanguageRules
Gorules_go + Gazelle
Rustrules_rust + crate_universe
C/C++Built-in cc_library, cc_binary
Shellrules_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

PlatformStatus
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

  1. Create the package in go/pkg/mypackage/
  2. Run Gazelle to generate BUILD file:
    bazel run //:gazelle
    

Adding a New Rust Crate

  1. Create the crate in rust/mypackage/
  2. Add to rust/Cargo.toml workspace members
  3. Create BUILD.bazel with rust_library rule

Adding a C/C++ Dependency

  1. Create config in third_party/libname/
  2. Add BUILD.bazel with cc_library rule
  3. 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