Overview
The X Recommendation Algorithm uses Bazel as its build system. Bazel provides fast, reproducible builds and manages dependencies across the entire monorepo.The repository includes Bazel BUILD files for most components, but not a top-level BUILD or WORKSPACE file. A more complete build and test system is planned for the future.
Understanding Bazel
Bazel is a build system that builds code from source using BUILD files that define build rules and dependencies.Key Concepts
- BUILD files - Define build targets and their dependencies
- BUILD.bazel files - Bazel-specific BUILD files (used in this project)
- Targets - A buildable unit (binary, library, test, etc.)
- Labels - Identify build targets (e.g.,
//home-mixer:bin)
Common Build Rules
jvm_binary- Builds a JVM executablejvm_app- Packages a JVM application with resourcesscala_library- Compiles Scala source filesjava_library- Compiles Java source filespy_binary- Builds a Python executablerust_binary- Builds a Rust executable
Building Components
Build a Specific Component
To build a specific component, use thebazel build command with the target label:
Build All Targets in a Directory
Example: Building Home Mixer
Build the Home Mixer Binary
- Compiles all Scala source files
- Resolves and downloads dependencies
- Creates an executable binary
Building Machine Learning Models
Many ML models are in Python and located undersrc/python/ and component-specific directories:
Building Navi (Rust)
The Navi model serving component is written in Rust:Testing
Running Tests
Run tests usingbazel test:
Test Targets
Test targets are typically located insrc/test/ directories:
Running a Test Suite
Querying the Build Graph
Find Build Targets
Usebazel query to explore the build graph:
Visualize Dependencies
Generate a dependency graph:Build Options and Optimization
Common Build Flags
Incremental Builds
Bazel automatically performs incremental builds by caching results:Clean Build Cache
If you need to clean the build cache:Building Specific Products
For You Timeline
The For You Timeline requires multiple components:Recommended Notifications
Troubleshooting
Build Failures
Missing dependencies
Missing dependencies
If Bazel reports missing dependencies, try:
Out of memory errors
Out of memory errors
Limit Bazel’s memory usage:
Stale build artifacts
Stale build artifacts
Clean and rebuild:
Java version mismatch
Java version mismatch
Ensure Java 11 is being used:
Performance Tips
- Use remote caching - If available, configure Bazel remote cache for faster builds
- Build specific targets - Avoid building
//...unless necessary - Use incremental builds - Don’t clean unless you have to
- Leverage parallelism - Use
--jobs=autoto utilize all CPU cores - Monitor build times - Use
--profileto identify slow build steps
Next Steps
- Read the contributing guidelines to submit changes
- Explore component-specific README files in the repository
- Check the architecture documentation for system design details