Skip to content

Commit e39066b

Browse files
authored
Update Protobuf Bazel Workspace (#7094)
## Summary This PR updates TensorBoard’s local Bazel/protobuf build stack to stay compatible with the TensorFlow 2.21 ecosystem changes that this branch needs: - Bazel 6.5.0 -> 7.7.0 - protobuf build/runtime alignment to 6.31.1 - related Bazel repo-loading, packaging, and test fixes needed for local source builds and CI The goal of this PR is to keep the smallest working set of changes needed to make the branch build, test, and package correctly with the upgraded toolchain. ## What changed ### Bazel / workspace updates - update `.bazelversion` and Bazel version guards to 7.7.0 - update workspace dependencies and repository wiring needed for Bazel 7 - keep existing repo setup model (`WORKSPACE`) rather than switching this PR to bzlmod ### Protobuf 6.31.1 alignment - update the Bazel-side protobuf dependency to 6.31.1 - add the small compatibility shims/patches needed for protobuf’s Bazel build in this repo - regenerate/update checked-in generated artifacts where required ### rules_closure / Soy compatibility - keep TensorBoard’s existing Closure/Soy toolchain working with protobuf 6 - vendor `third_party/safe_html_types` as a build-time Java dependency override for the existing Soy toolchain - explicitly prevent `rules_closure_dependencies(...)` from re-introducing conflicting older transitive copies ### Packaging and test fixes - keep `tensorboard.compat` package exports working correctly in Bazel runfiles and wheel/runtime smoke tests - keep `test_pip_package` and local Bazel test flows working under the upgraded toolchain - reduce PR-specific drift where possible by reverting summary modules back toward upstream import structure ## Vendored code This PR vendors `third_party/safe_html_types`, which is the main true vendored code in this branch. Why it is needed: - TensorBoard still uses the Closure/Soy Java toolchain during Bazel builds - the older transitive safe-html-types classes pulled by that toolchain were not working for this protobuf 6.31.1 upgrade path - this vendored copy is used as a build-time dependency override so the branch can stay on the upgraded Bazel/protobuf stack Why this is safe: - it is build-time Java tooling support, not TensorBoard Python runtime logic - it is not intended to change TensorBoard user-facing behavior - it is scoped to keeping the existing Soy/Closure path working with protobuf 6 We investigated avoiding vendoring here, but the straightforward `http_archive` alternatives we tried did not work for this branch’s current dependency combination. ## Review-driven cleanup in this PR In response to review, this PR now also: - adds clearer comments for patches and Bazel helper/shim files - documents the vendored `safe_html_types` dependency more explicitly - keeps optional cleanup/refactor work out of scope where possible - simplifies some summary-module changes back toward upstream shape ## Validation Validated through the local/container workflow used for this branch, including: - Bazel repo loading / fetch - focused and full Bazel test runs - pip package build - `test_pip_package` smoke validation - TensorBoard import/runtime verification against TensorFlow 2.21 ## Follow-up work The following are better handled in follow-up PRs rather than expanding this one further: - CI/setup-python cleanup and container-specific Python setup simplification - any future move to bzlmod - further dependency-management cleanup in `third_party/repo.bzl` - splitting this large change into smaller independently reviewable PRs once the full working baseline is settled
1 parent 2e19048 commit e39066b

87 files changed

Lines changed: 9121 additions & 125 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.bazel-user-root
2+
.bazelisk-home

.bazelrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
common --noenable_bzlmod
2+
# Let the OS-specific sections below (`common:linux`, `common:macos`, etc.)
3+
# take effect so one `.bazelrc` can carry the required per-platform C++ flags.
4+
common --enable_platform_specific_config
15
common --experimental_repo_remote_exec # from TensorFlow
6+
# Bazel-generated Python package init files can shadow TensorBoard's real
7+
# compat package init at test runtime; keep this test-only so pip packaging
8+
# still copies the intended package tree.
9+
test --incompatible_default_to_explicit_init_py
210

311
# Use C++ backing implementations for Python proto parsing and deserialization,
412
# which is much faster (~10x).
513
build --define=use_fast_cpp_protos=true
14+
15+
# Protobuf 6.31.1 requires C++17 in this build. Keep the host and target
16+
# language level aligned across supported platforms.
17+
common:linux --cxxopt=-std=c++17
18+
common:linux --host_cxxopt=-std=c++17
19+
common:macos --cxxopt=-std=c++17
20+
common:macos --host_cxxopt=-std=c++17
21+
common:windows --cxxopt=/std:c++17
22+
common:windows --host_cxxopt=/std:c++17
23+
24+
# Local shells and virtualenvs can leak Python import state into Bazel tests,
25+
# which then import from the wrong environment instead of the test runfiles.
26+
test --test_env=PYTHONPATH=
27+
test --test_env=PYTHONHOME=
28+
test --test_env=PYTHONSTARTUP=
29+
test --test_env=PYTHONSAFEPATH=
30+
test --test_env=PYTHONNOUSERSITE=1
31+
test --test_env=PYTHONUSERBASE=
32+
test --test_env=BUILD_WORKSPACE_DIRECTORY=
33+
test --test_env=BUILD_WORKING_DIRECTORY=

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.5.0
1+
7.7.0

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
* text=auto
2+
*.bzl text eol=lf
3+
*.sh text eol=lf
4+
.bazel* text eol=lf
5+
BUILD text eol=lf
6+
BUILD.bazel text eol=lf
7+
WORKSPACE text eol=lf
8+
MODULE.bazel text eol=lf
9+
110
third_party/rust/** -diff -merge linguist-generated=true

.github/workflows/ci.yml

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ permissions:
2525
env:
2626
# Keep this Bazel version in sync with the `versions.check` directive
2727
# in our WORKSPACE file.
28-
BAZEL_VERSION: '6.5.0'
29-
BAZEL_SHA256SUM: 'a40ac69263440761199fcb8da47ad4e3f328cbe79ffbf4ecc14e5ba252857307'
28+
BAZEL_VERSION: '7.7.0'
29+
BAZEL_SHA256SUM: 'fe7e799cbc9140f986b063e06800a3d4c790525075c877d00a7112669824acbf'
3030
BUILDTOOLS_VERSION: '3.0.0'
3131
BUILDIFIER_SHA256SUM: 'e92a6793c7134c5431c58fbc34700664f101e5c9b1c1fcd93b97978e8b7f88db'
3232
BUILDOZER_SHA256SUM: '3d58a0b6972e4535718cdd6c12778170ea7382de7c75bc3728f5719437ffb84d'
@@ -48,7 +48,7 @@ jobs:
4848
fail-fast: false
4949
matrix:
5050
tf_version_id: ['tf', 'notf']
51-
python_version: ['3.9']
51+
python_version: ['3.10']
5252
steps:
5353
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
5454
- uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984 # v4.3.0
@@ -65,6 +65,11 @@ jobs:
6565
run: |
6666
python -m pip install -U pip
6767
pip install "${TENSORFLOW_VERSION}"
68+
# tf-nightly currently pulls in tb-nightly as a dependency. Bazel's
69+
# source-tree tests must import TensorBoard from runfiles rather than
70+
# from site-packages, otherwise tests that rely on local-only modules
71+
# like `tensorboard.test` resolve against the installed wheel and fail.
72+
pip uninstall -y tensorboard tb-nightly || true
6873
if: matrix.tf_version_id != 'notf'
6974
- name: 'Install Python dependencies'
7075
run: |
@@ -73,14 +78,85 @@ jobs:
7378
-r ./tensorboard/pip_package/requirements.txt \
7479
-r ./tensorboard/pip_package/requirements_dev.txt \
7580
;
76-
- name: 'Install Chrome dependencies'
81+
- name: 'Install system dependencies'
7782
run: |
83+
py_abi="python${{ matrix.python_version }}"
7884
sudo apt-get update
79-
sudo apt-get install -y libgbm-dev libxss1 libasound2
85+
sudo apt-get install -y "${py_abi}-dev" libgbm-dev libxss1 libasound2
86+
# Bazel's system_python repository resolves headers relative to the
87+
# interpreter installed by actions/setup-python. The self-hosted
88+
# ml-build container does not provide Python.h under that prefix, so
89+
# copy the system headers into the managed interpreter include dir.
90+
# A real directory copy is more robust here than a symlink because
91+
# Bazel's repository setup may materialize or traverse this path in
92+
# ways that do not preserve symlink behavior.
93+
sudo mkdir -p "${pythonLocation}/include"
94+
sudo rm -rf "${pythonLocation}/include/${py_abi}"
95+
sudo mkdir -p "${pythonLocation}/include/${py_abi}"
96+
sudo cp -a "/usr/include/${py_abi}/." "${pythonLocation}/include/${py_abi}/"
97+
includepy="$(python - <<'PY'
98+
import sysconfig
99+
print(sysconfig.get_config_var("INCLUDEPY"))
100+
PY
101+
)"
102+
# upb's system_python repository rule shells out to `python3` and
103+
# uses sysconfig.get_config_var("INCLUDEPY"), which under
104+
# actions/setup-python inside this container points at
105+
# /opt/hostedtoolcache/... rather than ${pythonLocation}. Materialize
106+
# that INCLUDEPY path too so Bazel's @system_python repo can symlink
107+
# real headers into external/system_python/python.
108+
sudo mkdir -p "$(dirname "${includepy}")"
109+
sudo rm -rf "${includepy}"
110+
sudo cp -a "${pythonLocation}/include/${py_abi}" "${includepy}"
111+
test -f "${pythonLocation}/include/${py_abi}/Python.h"
112+
test -f "${includepy}/Python.h"
113+
- name: 'Debug Python toolchain'
114+
run: |
115+
py_abi="python${{ matrix.python_version }}"
116+
echo "pythonLocation=${pythonLocation}"
117+
echo "PATH=${PATH}"
118+
which python
119+
python --version
120+
command -v python3.10-config || true
121+
python3.10-config --includes || true
122+
python - <<'PY'
123+
import os
124+
import pathlib
125+
import sys
126+
import sysconfig
127+
128+
print("sys.executable =", sys.executable)
129+
for key in ("include", "platinclude", "stdlib", "platstdlib", "scripts", "data"):
130+
print(f"{key} =", sysconfig.get_path(key))
131+
for key in ("INCLUDEPY", "CONFINCLUDEPY", "LIBDIR", "LDLIBRARY", "MULTIARCH"):
132+
print(f"{key} =", sysconfig.get_config_var(key))
133+
include_dir = pathlib.Path(sysconfig.get_path("include"))
134+
print("include_dir exists =", include_dir.exists(), include_dir)
135+
print("Python.h exists =", (include_dir / "Python.h").exists())
136+
print("pythonLocation =", os.environ.get("pythonLocation"))
137+
PY
138+
ls -la "${pythonLocation}" || true
139+
ls -la "${pythonLocation}/include" || true
140+
ls -la "${pythonLocation}/include/${py_abi}" || true
80141
- name: 'Check Pip state'
81142
run: pip freeze --all
82143
- name: 'Bazel: fetch'
83144
run: bazel fetch //tensorboard/...
145+
- name: 'Debug Bazel system_python repo'
146+
run: |
147+
output_base="$(bazel info output_base)"
148+
echo "output_base=${output_base}"
149+
find "${output_base}/external/system_python" -maxdepth 3 \
150+
\( -name 'Python.h' -o -name 'BUILD.bazel' -o -name 'WORKSPACE' \) \
151+
-print | sort || true
152+
if [ -f "${output_base}/external/system_python/BUILD.bazel" ]; then
153+
sed -n '1,200p' "${output_base}/external/system_python/BUILD.bazel"
154+
fi
155+
if [ -d "${output_base}/external/system_python/python" ]; then
156+
ls -la "${output_base}/external/system_python/python"
157+
else
158+
echo "system_python/python directory not found"
159+
fi
84160
- name: 'Bazel: build'
85161
# Note we suppress a flood of warnings from the proto compiler.
86162
# Googlers see b/222706811 & b/182876485 discussion and preconditions
@@ -98,13 +174,21 @@ jobs:
98174
if: matrix.tf_version_id == 'notf'
99175
- name: 'Bazel: run Pip package test (with TensorFlow support)'
100176
run: |
101-
bazel run //tensorboard/pip_package:test_pip_package -- \
177+
# `bazel run` has been flaky under this self-hosted container runner
178+
# even when the smoke test itself completes successfully. Build the
179+
# launcher target, invoke the generated binary directly, then shut
180+
# down the Bazel server so the step exits cleanly.
181+
bazel build //tensorboard/pip_package:test_pip_package
182+
./bazel-bin/tensorboard/pip_package/test_pip_package \
102183
--tf-version "${TENSORFLOW_VERSION}"
184+
bazel shutdown
103185
if: matrix.tf_version_id != 'notf'
104186
- name: 'Bazel: run Pip package test (non-TensorFlow only)'
105187
run: |
106-
bazel run //tensorboard/pip_package:test_pip_package -- \
188+
bazel build //tensorboard/pip_package:test_pip_package
189+
./bazel-bin/tensorboard/pip_package/test_pip_package \
107190
--tf-version notf
191+
bazel shutdown
108192
if: matrix.tf_version_id == 'notf'
109193
- name: 'Bazel: run manual tests'
110194
run: |

0 commit comments

Comments
 (0)