Skip to content

Conversation

@czgdp1807
Copy link

Problem

Building tfx-bsl on macOS arm64 with Xcode Command Line Tools (clang 17) fails due to several incompatibilities:

  1. Linker error: ThinLTO assumes Apple's libLTO.dylib, causing failures with conda-provided compilers
  2. zlib compilation: Macro conflicts between zlib 1.2.11 and modern macOS SDK headers
  3. Module symbols: Python 2-era extension symbols cause linker failures on Python 3
  4. Dependency mismatch: tensorflow-serving-api version drift from tensorflow 2.17

Solution

This PR addresses all macOS-specific build failures:

Changes

.bazelrc

  • Disable ThinLTO on macOS/macOS arm64 to avoid linker errors with conda compilers
  • Define HAVE_UNISTD_H=1 for zlib compatibility with modern macOS headers

WORKSPACE

  • Update zlib to version 1.3.1 (from implicit 1.2.11)
  • Define explicit http_archive for zlib before tensorflow dependency loads it
  • Prevents fdopen macro conflicts with macOS SDK _stdio.h

setup.py

  • Pin tensorflow-serving-api to ==2.17.1
  • Updated all selectors: default, nightly, and git_master branches
  • Ensures consistent protobuf/grpc versions across all build configurations

tfx_bsl/build_macros.bzl

  • Remove Python 2 module initialization symbols (init_*, init*)
  • Keep only PyInit_<module> for Python 3 compatibility
  • Fixes undefined symbol errors during extension module linking

Testing

Verified on: macOS arm64, Python 3.12, Bazel 6.5.0

  • Build completes without compiler or linker errors
  • tfx_bsl_extension.so correctly links
  • Package installs via pip install -e .

Impact

  • Enables macOS arm64 builds with conda environments
  • No changes to Linux/Windows builds (macos-specific flags)
  • Maintains Python 3.9+ compatibility
  • Drops Python 2 support (already EOL)

Related Issues

Fixes compilation errors on macOS when using conda's clang/clang++ toolchain instead of Apple's Xcode developer tools.

This commit addresses several build failures specific to macOS with
Xcode Command Line Tools clang 17:

- Disable ThinLTO on macOS to avoid libLTO.dylib mismatch errors
  between Bazel and conda-provided compilers
- Pin tensorflow-serving-api to version 2.17.1
- Update zlib to 1.3.1 and define HAVE_UNISTD_H to prevent fdopen
  macro conflicts with macOS SDK headers
- Remove deprecated Python 2 module initialization symbols (init_*),
  keeping only PyInit_* for Python 3 compatibility

These changes enable successful builds on macOS arm64 systems using
conda environments without requiring Apple's native toolchain.

Tested on: macOS arm64, Python 3.12, Bazel 6.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant