A collection of simple Bazel examples demonstrating how to build projects in different programming languages using modern Bzlmod.
-
Go Example (
//hello-go:hello-go)- Web server using Fuego framework
- Internal package structure
- Unit tests with go_test
-
Python Example (
//hello-py:hello)- Python binary example
- Demonstrates py_binary rule
- Bazel 7.x or later (uses Bzlmod)
- Go toolchain (auto-downloaded by Bazel)
- Python 3.x (for Python examples)
# Build all targets
bazel build //...
# Build specific targets
bazel build //hello-go:hello-go
bazel build //hello-py:hello# Run Go server (starts on :9999)
bazel run //hello-go:hello-go
# Run Python example
bazel run //hello-py:hello# Run all tests
bazel test //...
# Run Go tests only
bazel test //hello-go/...
# Run with verbose output
bazel test //... --test_output=all# Update BUILD files from Go source
bazel run //:gazelle
# Update dependencies from go.mod
bazel run //:gazelle-update-reposFor Go IDE integration with Bazel, set the GOPACKAGESDRIVER environment variable:
export GOPACKAGESDRIVER="$(pwd)/tools/gopackagesdriver.sh"See rules_go Editor Setup for details.
This project uses nogo for static analysis during builds:
- Go vet checks (enabled by default)
- Nilness analysis (detect nil pointer dereferences)
- Shadow analysis (detect shadowed variables)
- Unused result analysis (detect ignored return values)
Analysis runs automatically on every build - no separate step needed.
GitHub Actions workflow runs on push and PR:
- Builds all targets with optimizations
- Runs all tests
- Uses Bazel caching for fast builds
hello-bazel/
βββ BUILD.bazel # Root gazelle targets
βββ MODULE.bazel # Bazel module configuration
βββ .bazelrc # Bazel settings
βββ hello-go/
β βββ BUILD.bazel # Go binary and nogo rules
β βββ main.go # Server entry point
β βββ go.mod # Go module
β βββ internal/handler/ # Internal packages
β βββ BUILD.bazel
β βββ hello.go
β βββ hello_test.go
βββ hello-py/
β βββ BUILD.bazel
β βββ main.py
βββ tools/
βββ gopackagesdriver.sh # IDE integration