Bazel Toolchains and Platforms Training
Master Bazel platform definitions, toolchain resolution, hermetic toolchains, and cross-compilation patterns in 2 days.
Master Bazel's platform and toolchain system for portable, hermetic, and cross-compilable builds. This 2-day training covers the constraint system, toolchain resolution algorithm, hermetic toolchain packaging, cross-compilation workflows, and platform-conditional build logic with select() and config_setting.
Training Details
| Duration | 2 days (16 hours) |
| Level | Advanced |
| Delivery | In-person, Live online, Hybrid |
| Certification | N/A |
Who Is This For?
- Build engineers designing portable build configurations
- Platform engineers managing compiler and SDK toolchains
- Embedded systems developers needing cross-compilation support
- Infrastructure engineers packaging hermetic build environments
- Release engineers supporting multi-platform artifact generation
Learning Outcomes
After completing this training, participants will be able to:
- Define custom platforms with constraint_setting and constraint_value
- Implement and register toolchains using the toolchain resolution protocol
- Package hermetic toolchains that bundle compilers and SDKs within Bazel
- Configure cross-compilation builds targeting different OS and CPU architectures
- Use select() with config_setting for platform-conditional dependencies and sources
- Distinguish exec platforms from target platforms and configure each correctly
Detailed Agenda
Day 1: Platform System and Toolchain Resolution
Module 1: Platforms Concept and Constraint System
- The platform problem: host vs target vs exec differences
- constraint_setting: defining dimensions (OS, CPU, libc, GPU)
- constraint_value: specific values within a dimension (linux, macos, x86_64, aarch64)
- platform() rule: combining constraint values into a concrete platform definition
- Built-in constraints: @platforms//os, @platforms//cpu
- Hands-on: Define custom platforms for Linux x86_64, Linux ARM64, macOS ARM64, and a custom embedded target
Module 2: Toolchain Resolution Protocol
- toolchain_type(): declaring a type of toolchain (e.g., @rules_cc//cc:toolchain_type)
- toolchain() rule: target_compatible_with, exec_compatible_with, toolchain attribute
- register_toolchains() in MODULE.bazel and WORKSPACE
- Resolution algorithm: matching target platform + exec platform against registered toolchains
- Toolchain resolution debugging: --toolchain_resolution_debug flag
- Hands-on: Implement a custom toolchain type, register multiple toolchain implementations, debug resolution order
Module 3: Hermetic Toolchains
- Why hermetic: reproducibility across machines, CI/CD consistency
- Packaging compilers: downloading pre-built toolchains via http_archive
- Hermetic C++ toolchain: cc_toolchain, cc_toolchain_config, feature_configuration
- Hermetic JDK: remote_java_repository, java_toolchain
- Hermetic Python: python_register_toolchains from rules_python
- Hermetic Go: go_register_toolchains with GOROOT bundled
- Hands-on: Set up a hermetic C++ toolchain that downloads a specific Clang version and uses it for all cc_* targets
Module 4: Toolchain Configuration and Features
- cc_toolchain_config_info: tool_paths, features, action_configs
- Feature model: enabled_by, implies, requires, flag_sets
- Compiler flags per-feature: optimization levels, sanitizers, debug info
- Linker configuration: dynamic linking, static linking, shared objects
- Toolchain config generation: Bazel's cc_configure vs manual configuration
- Hands-on: Configure a C++ toolchain with feature flags for debug, release, and sanitizer builds
Day 2: Cross-Compilation and Platform Logic
Module 5: Cross-Compilation Patterns
- Target platform specification: --platforms flag on command line
- Multi-platform builds: building the same target for multiple architectures
- Sysroot configuration for cross-compilation: --host_crosstool_top, sysroot attribute
- Cross-compiling Go: GOOS and GOARCH via platform constraints
- Cross-compiling Rust: target triples via platform mapping
- Hands-on: Cross-compile a Go binary for Linux ARM64 from a macOS x86_64 host using platform constraints
Module 6: select() and Platform-Conditional Logic
- select() function: config_setting keys to value mapping
- config_setting: define matching criteria with values, flag_values, constraint_values
- config_feature_flag: user-defined boolean and string flags
- Selectable attributes: deps, srcs, copts, linkopts, data
- Multiple select() conditions: selects.config_setting_group with match_any and match_all
- no_match_error for required platform coverage
- Hands-on: Build a library that uses platform-specific source files, dependencies, and compiler flags via select()
Module 7: Exec Platforms and Execution Strategy
- Exec platform vs target platform: where actions run vs what they produce
- --extra_execution_platforms and --host_platform flags
- Execution groups (exec_groups): different exec platforms for different actions within one rule
- exec_compatible_with on targets for overriding exec platform selection
- Remote execution platform constraints: OSFamily, container-image, Pool
- Hands-on: Configure exec groups for a rule that runs code generation on one platform and compilation on another
Module 8: Platform Migration and Capstone
- Platform migration: --incompatible_enable_cc_toolchain_resolution
- target_compatible_with for declaring platform restrictions on targets
- Incompatible target skipping: targets silently skipped on incompatible platforms
- Platform mapping: --platform_mappings file for gradual migration
- Legacy flags to platform migration: --cpu, --crosstool_top mapped to platforms
- Hands-on: Capstone project — design a multi-platform build system with hermetic C++ and Go toolchains, cross-compile binaries for three architectures, and use select() for platform-conditional features
Prerequisites
- Bazel Fundamentals and Starlark Rule Development training or equivalent experience
- Understanding of compilation toolchains (compilers, linkers, sysroots)
- Familiarity with CPU architectures (x86_64, ARM64) and operating systems
- Experience with cross-compilation concepts
Delivery Formats
| Format | Description |
|---|---|
| In-Person | On-site at your company's location, hands-on with direct interaction |
| Live Online | Interactive virtual sessions with screen sharing and real-time labs |
| Hybrid | Combination of on-site and remote sessions, flexible scheduling |
All formats include hands-on labs, course materials, and post-training support.
Prerequisites
- Bazel Fundamentals and Starlark Rule Development or equivalent
- Understanding of compilation toolchains and cross-compilation concepts
Ready to get started?
Request a training quote for your team — in-person, live-online, or hybrid.