Environment:Tensorflow Serving Build Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Build_System |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Linux build environment requiring Bazel 7.4.1, C++17, GCC 10, and OpenJDK 8 for compiling TensorFlow Serving from source.
Description
This environment provides the toolchain and dependencies required to build TensorFlow Serving from source using the Bazel build system. The build requires C++17 for LLVM/MLIR/TF compatibility, uses GCC 10 as the primary compiler for CPU builds (Clang 17 for GPU builds), and requires OpenJDK 8 for the Bazel build system. The build is Linux-only for official binary production. Release builds are optimized with AVX and SSE4.2 instructions, with optional native optimization via `--config=nativeopt`.
Usage
Use this environment when building TensorFlow Serving from source. This is required if you need custom compile-time optimizations (e.g., native CPU instruction set targeting), custom op support, or building the GPU-enabled variant. Pre-built Docker images and pip packages are available for users who do not need custom builds.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux (Ubuntu 20.04 LTS recommended) | "Currently we only support building binaries that run on Linux" (setup.md) |
| Build System | Bazel 7.4.1 | Strict minimum; enforced via `versions.check("7.4.1")` in WORKSPACE |
| Compiler (CPU) | GCC 10 | `gcc-10`, `g++-10` |
| Compiler (GPU) | Clang 17 | `clang-17`, `llvm-17`, `lld-17` for CUDA builds |
| C++ Standard | C++17 | Required for LLVM/MLIR/TF compatibility |
| Java | OpenJDK 8 | `openjdk-8-jdk`, `openjdk-8-jre-headless` for Bazel |
| RAM | Configurable | Limit with `--local_ram_resources=2048` if constrained |
Dependencies
System Packages
- `gcc-10` / `g++-10` (CPU builds)
- `clang-17` / `llvm-17` / `lld-17` (GPU builds)
- `openjdk-8-jdk`
- `git`
- `python3` >= 3.9
Build Tool
- `bazel` = 7.4.1
Build Flags
- Release: `--copt=-mavx --copt=-msse4.2`
- Native: `--config=nativeopt` uses `-march=native`
- C++ ABI: `-D_GLIBCXX_USE_CXX11_ABI=0` (parity with TensorFlow)
Credentials
No credentials required for building. Source is open-source under Apache 2.0.
Quick Install
# Ubuntu 20.04 build prerequisites
sudo apt-get update && sudo apt-get install -y \
gcc-10 g++-10 openjdk-8-jdk git python3 python3-pip
# Install Bazel 7.4.1 (via Bazelisk recommended)
# See https://github.com/bazelbuild/bazelisk
# Build TensorFlow Serving
git clone https://github.com/tensorflow/serving
cd serving
bazel build -c opt tensorflow_serving/...
Code Evidence
Bazel version enforcement from `WORKSPACE:41`:
versions.check("7.4.1")
C++17 requirement from `.bazelrc:77-79`:
# LLVM, MLIR and TF requires C++17.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
C++ ABI compatibility from `.bazelrc:81-84`:
# Adding "--cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0" creates parity with TF
# compilation options. It also addresses memory use due to
# copy-on-write semantics of std::strings of the older ABI.
build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0
Release optimization flags from `.bazelrc:1-3`:
# Optimizations used for TF Serving release builds.
build:release --copt=-mavx
build:release --copt=-msse4.2
Python version constraint from `setup.py:83`:
python_requires='>=3.9',
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ERROR: Minimum Bazel version is 7.4.1` | Bazel version too old | Install Bazel >= 7.4.1 (use Bazelisk for automatic version management) |
| `Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA` | Binary not optimized for host CPU | Rebuild with `--config=nativeopt` or `--copt=-march=native` |
| Build OOM during compilation | Insufficient RAM for parallel compilation | Add `--local_ram_resources=2048` and `--local_cpu_resources=4` to limit parallelism |
Compatibility Notes
- Linux only: Official builds only support Linux. macOS and Windows are not supported for building production binaries.
- macOS: Uses standard synchronization primitives instead of ABSL concurrency due to ODR violation (configured in `.bazelrc:97-99`).
- MKL: MKL on macOS or Windows is not supported. Set `TF_MKL_ROOT` for local MKL installation.
- ARM (aarch64): Supported via `--config=mkl_aarch64` with `-march=armv8.2-a`. Uses oneDNN with Compute Library for Arm Architecture (ACL), inference-only mode.