From cb74ae289ccb6361bd129b98e6bc4f2e612966e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E4=BD=B3=E9=98=B3?= Date: Wed, 5 Aug 2026 16:48:35 +0800 Subject: [PATCH] fix/issue-4108-Error-building-TF-Serving-from-source --- tools/build.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tools/build.sh diff --git a/tools/build.sh b/tools/build.sh new file mode 100755 index 00000000000..2da65c5d319 --- /dev/null +++ b/tools/build.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# Copyright 2025 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Convenience wrapper to build TensorFlow Serving inside Docker. +# Automatically applies known compatibility patches before building. + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +WORKSPACE_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" + +function apply_compatibility_patches() { + echo "== Applying compatibility patches for XLA / GCC..." + + # Patch xla/shape.cc to fix noexcept mismatch with newer GCC versions + local shape_cc="${WORKSPACE_ROOT}/external/local_xla/xla/shape.cc" + if [[ -f "$shape_cc" ]]; then + if grep -q 'Shape::Shape(Shape&&) noexcept = default;' "$shape_cc"; then + sed -i 's/Shape::Shape(Shape&&) noexcept = default;/Shape::Shape(Shape&&) = default;/' "$shape_cc" + echo " Patched: shape.cc (move ctor)" + fi + if grep -q 'Shape& Shape::operator=(Shape&&) noexcept = default;' "$shape_cc"; then + sed -i 's/Shape& Shape::operator=(Shape&&) noexcept = default;/Shape& Shape::operator=(Shape&&) = default;/' "$shape_cc" + echo " Patched: shape.cc (move assign)" + fi + fi + + # Also patch shape.h if it exists to keep declaration/definition consistent + local shape_h="${WORKSPACE_ROOT}/external/local_xla/xla/shape.h" + if [[ -f "$shape_h" ]]; then + sed -i 's/Shape(Shape&&) noexcept;/Shape(Shape&&);/' "$shape_h" 2>/dev/null || true + sed -i 's/operator=(Shape&&) noexcept;/operator=(Shape&&);/' "$shape_h" 2>/dev/null || true + fi + + # Recursively find shape.cc if external/ not yet at expected path + find "${WORKSPACE_ROOT}" -path '*/xla/shape.cc' -not -path '*/.git/*' -print0 2>/dev/null | \ + while IFS= read -r -d '' file; do + sed -i 's/Shape::Shape(Shape&&) noexcept = default;/Shape::Shape(Shape&&) = default;/' "$file" 2>/dev/null || true + sed -i 's/Shape& Shape::operator=(Shape&&) noexcept = default;/Shape& Shape::operator=(Shape&&) = default;/' "$file" 2>/dev/null || true + done +} + +function usage() { + echo "Usage:" + echo " $(basename $0) [bazel build flags] " + echo "" + echo "Examples:" + echo " $(basename $0) -c opt tensorflow_serving/model_servers:tensorflow_model_server" + echo " $(basename $0) --config=nativeopt tensorflow_serving/..." + exit 1 +} + +# Ensure external/ deps are available before patching +echo "== Fetching dependencies..." +"${SCRIPT_DIR}/run_in_docker.sh" bazel fetch //tensorflow_serving/... 2>/dev/null || true + +# Apply patches in the local workspace +apply_compatibility_patches + +# Forward everything to run_in_docker.sh for the actual build +echo "== Starting build via run_in_docker.sh..." +exec "${SCRIPT_DIR}/run_in_docker.sh" bazel build "$@"