From 178e2f9d715d1b45e14df48d453e6230a8cc856c Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Tue, 20 Jan 2026 15:17:06 +0530 Subject: [PATCH 1/2] Add native macOS build support Enable native macOS compilation by fixing platform-specific issues: - Use relative path for workspace status command - Configure macOS deployment target (10.13) and aligned allocation - Disable C++ modules to avoid dependency resolution errors - Override conda tools with system binaries - Increase repository fetch timeouts for Boost - Disable Boost recursive submodules to prevent timeouts - Add conda environment.yml for build dependencies Fixes build on Apple Silicon macOS systems. --- .bazelrc | 26 ++++++++++++++++++++++++-- environment.yml | 19 +++++++++++++++++++ tensorflow_serving/workspace.bzl | 2 +- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 environment.yml diff --git a/.bazelrc b/.bazelrc index d8e7993683c..b94d4d2bf92 100644 --- a/.bazelrc +++ b/.bazelrc @@ -83,7 +83,7 @@ build --host_cxxopt=-std=c++17 # copy-on-write semantics of std::strings of the older ABI. build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 -build --workspace_status_command=/proc/self/cwd/tools/gen_status_stamp.sh +build --workspace_status_command=tools/gen_status_stamp.sh build --experimental_repo_remote_exec @@ -96,7 +96,17 @@ build --define=use_tensorflow_io=1 # TensorFlow Decision Forests does not use Absl concurrency primitives on MacOs. # Reason: TensorFlow/ABSL ODR violation (b/214189609) # copybara:strip -build:macos --define std_synchronization_primitives=1 +# DISABLED for native macOS build due to C++20 std::latch compatibility issues +# build:macos --define std_synchronization_primitives=1 + +# macOS-specific build configuration for native compilation +build:macos --cxxopt=-mmacosx-version-min=10.13 +build:macos --cxxopt=-faligned-allocation +build:macos --host_cxxopt=-mmacosx-version-min=10.13 +build:macos --host_cxxopt=-faligned-allocation +# Disable C++ modules to avoid indirect dependency issues +build:macos --features=-use_module_maps +build:macos --features=-layering_check # Taken from https://github.com/openxla/xla/blob/99559d7a4f7c55490f46385ad29a3cbf9c3911af/warnings.bazelrc#L6 # We silence warnings for code in `external`. @@ -111,3 +121,15 @@ build --copt=-Wno-unused-but-set-variable # due to `ifdefs` in ml_dtypes # and disable Bzlmod. common --enable_bzlmod=false common --noincompatible_enable_cc_toolchain_resolution + +# Increase timeout for repository fetches (especially for Boost with submodules) +fetch --repository_cache_hardlinks=false +fetch --http_timeout_scaling=10.0 +common --experimental_repository_downloader_retries=3 +common --experimental_scale_timeouts=10.0 + +# macOS: Use system tools instead of conda environment tools +build:macos --action_env AR=/usr/bin/ar +build:macos --action_env LD=/usr/bin/ld +build:macos --action_env LIBTOOL=/usr/bin/libtool +build:macos --action_env NM=/usr/bin/nm diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000000..a4808773390 --- /dev/null +++ b/environment.yml @@ -0,0 +1,19 @@ +name: tf-serving-build +channels: + - conda-forge + - defaults +dependencies: + - python=3.11 + - automake + - autoconf + - libtool + - make + - cmake + - git + - pkg-config + - wget + - curl + - patch + - unzip + - zip + - clang=18.1.1 diff --git a/tensorflow_serving/workspace.bzl b/tensorflow_serving/workspace.bzl index c7b7a8966b7..e6bd9c2d21d 100644 --- a/tensorflow_serving/workspace.bzl +++ b/tensorflow_serving/workspace.bzl @@ -128,6 +128,6 @@ def tf_serving_workspace(): commit = "b7b1371294b4bdfc8d85e49236ebced114bc1d8f", # boost-1.75.0 build_file = "//third_party/boost:BUILD", init_submodules = True, - recursive_init_submodules = True, + recursive_init_submodules = False, # Disabled to avoid timeout - Boost submodules don't have nested submodules remote = "https://github.com/boostorg/boost", ) From 16f73f0366ead1f232584422516c4f213e20d402 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Wed, 21 Jan 2026 20:31:46 +0530 Subject: [PATCH 2/2] Add Bazelisk installation instructions to environment.yml Include steps for installing Bazelisk, with guidance on version management via USE_BAZEL_VERSION. --- environment.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/environment.yml b/environment.yml index a4808773390..6ce8a156cf5 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,15 @@ name: tf-serving-build + +# Bazelisk is the recommended way to manage Bazel versions (automatically downloads and uses the right version). +# To install Bazelisk: +# 1. Create directory: mkdir -p ~/.local/bin +# 2. Download: curl -L https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-darwin-arm64 -o ~/.local/bin/bazel +# (use bazelisk-darwin-amd64 for Intel Macs) +# 3. Make executable: chmod +x ~/.local/bin/bazel +# 4. Add to PATH: export PATH="$HOME/.local/bin:$PATH" (add to ~/.zshrc or ~/.bash_profile) +# 5. Optional: Set specific Bazel version with export USE_BAZEL_VERSION=x.y.z +# 6. Verify: bazel --version + channels: - conda-forge - defaults