Skip to content

1995parham-learning/hello-bazel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hello Bazel

A collection of simple Bazel examples demonstrating how to build projects in different programming languages using modern Bzlmod.

Contents

  1. Go Example (//hello-go:hello-go)

    • Web server using Fuego framework
    • Internal package structure
    • Unit tests with go_test
  2. Python Example (//hello-py:hello)

    • Python binary example
    • Demonstrates py_binary rule

Prerequisites

  • Bazel 7.x or later (uses Bzlmod)
  • Go toolchain (auto-downloaded by Bazel)
  • Python 3.x (for Python examples)

Building

# Build all targets
bazel build //...

# Build specific targets
bazel build //hello-go:hello-go
bazel build //hello-py:hello

Running

# Run Go server (starts on :9999)
bazel run //hello-go:hello-go

# Run Python example
bazel run //hello-py:hello

Testing

# Run all tests
bazel test //...

# Run Go tests only
bazel test //hello-go/...

# Run with verbose output
bazel test //... --test_output=all

Development

Regenerate BUILD Files

# Update BUILD files from Go source
bazel run //:gazelle

# Update dependencies from go.mod
bazel run //:gazelle-update-repos

IDE Setup (VS Code / GoLand)

For Go IDE integration with Bazel, set the GOPACKAGESDRIVER environment variable:

export GOPACKAGESDRIVER="$(pwd)/tools/gopackagesdriver.sh"

See rules_go Editor Setup for details.

Static Analysis

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.

CI/CD

GitHub Actions workflow runs on push and PR:

  • Builds all targets with optimizations
  • Runs all tests
  • Uses Bazel caching for fast builds

Project Structure

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

About

Hello Bazel πŸ‘‹

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •