Skip to content

Commit ca25fdb

Browse files
author
Vasu Jaganath
committed
correctly build grpc
1 parent 619cea5 commit ca25fdb

File tree

4 files changed

+93
-206
lines changed

4 files changed

+93
-206
lines changed

.github/workflows/wheel_build.yml

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ jobs:
1717
MACOSX_DEPLOYMENT_TARGET: "10.15"
1818
strategy:
1919
matrix:
20-
os: [ubuntu-22.04, macos-15-intel, windows-latest]
21-
#os: [macos-15-intel]
20+
#os: [ubuntu-22.04, macos-15-intel, windows-latest]
21+
os: [macos-15-intel]
2222
cibw_archs: ["auto64"]
23-
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
23+
# cibw_build: ["cp310", "cp311", "cp312", "cp313"]
24+
cibw_build: ["cp310"]
2425

2526
steps:
2627
- uses: actions/checkout@v3
@@ -96,60 +97,60 @@ jobs:
9697
retention-days: 1
9798

9899

99-
build_wheels_apple_arm64:
100-
name: Build wheels on ${{ matrix.os }}
101-
runs-on: ${{ matrix.os }}
102-
continue-on-error: true
103-
env:
104-
MACOSX_DEPLOYMENT_TARGET: "11.0"
105-
strategy:
106-
matrix:
107-
os: [macos-14]
108-
cibw_archs: ["arm64"]
109-
cibw_build: ["cp310", "cp311", "cp312", "cp313"]
110-
111-
steps:
112-
- uses: actions/checkout@v3
113-
name: Check out
114-
115-
- uses: actions/setup-python@v4
116-
name: Install Python
117-
with:
118-
python-version: '3.11'
100+
# build_wheels_apple_arm64:
101+
# name: Build wheels on ${{ matrix.os }}
102+
# runs-on: ${{ matrix.os }}
103+
# continue-on-error: true
104+
# env:
105+
# MACOSX_DEPLOYMENT_TARGET: "11.0"
106+
# strategy:
107+
# matrix:
108+
# os: [macos-14]
109+
# cibw_archs: ["arm64"]
110+
# cibw_build: ["cp310", "cp311", "cp312", "cp313"]
111+
112+
# steps:
113+
# - uses: actions/checkout@v3
114+
# name: Check out
115+
116+
# - uses: actions/setup-python@v4
117+
# name: Install Python
118+
# with:
119+
# python-version: '3.11'
119120

120-
- name: Install cibuildwheel
121-
run: |
122-
python -m pip install cibuildwheel delocate wheel
123-
124-
- name: Building wheels
125-
run: |
126-
python -m cibuildwheel --output-dir dist
127-
env:
128-
CIBW_BUILD: ${{ matrix.cibw_build }}-*
129-
CIBW_BUILD_VERBOSITY: 3
130-
CIBW_ARCHS_MACOS: arm64
131-
CIBW_BEFORE_ALL_MACOS: brew install nasm &&
132-
brew uninstall --ignore-dependencies jpeg-turbo &&
133-
bash ci-utils/install_prereq_linux.sh &&
134-
mkdir -p /tmp/bfiocpp_bld &&
135-
cp -r local_install /tmp/bfiocpp_bld
121+
# - name: Install cibuildwheel
122+
# run: |
123+
# python -m pip install cibuildwheel delocate wheel
124+
125+
# - name: Building wheels
126+
# run: |
127+
# python -m cibuildwheel --output-dir dist
128+
# env:
129+
# CIBW_BUILD: ${{ matrix.cibw_build }}-*
130+
# CIBW_BUILD_VERBOSITY: 3
131+
# CIBW_ARCHS_MACOS: arm64
132+
# CIBW_BEFORE_ALL_MACOS: brew install nasm &&
133+
# brew uninstall --ignore-dependencies jpeg-turbo &&
134+
# bash ci-utils/install_prereq_linux.sh &&
135+
# mkdir -p /tmp/bfiocpp_bld &&
136+
# cp -r local_install /tmp/bfiocpp_bld
136137

137-
CIBW_ENVIRONMENT_MACOS: >-
138-
MACOSX_DEPLOYMENT_TARGET=11.0
139-
REPAIR_LIBRARY_PATH="/tmp/bfiocpp_bld/local_install/lib:/tmp/bfiocpp_bld/local_install/lib64"
140-
ON_GITHUB="TRUE"
141-
BFIOCPP_DEP_DIR="/tmp/bfiocpp_bld/local_install"
142-
CMAKE_ARGS="-DTENSORSTORE_USE_SYSTEM_JPEG=ON"
143-
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
144-
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
145-
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
146-
CIBW_ARCHS: ${{ matrix.cibw_archs }}
147-
CIBW_TEST_REQUIRES: "bfio requests numpy ome_zarr zarr"
148-
CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v
149-
150-
- name: Upload Artifact
151-
uses: actions/upload-artifact@v4
152-
with:
153-
name: bfiocpp-wheels-${{ matrix.os }}-${{ matrix.cibw_archs }}-${{ matrix.cibw_build }}
154-
path: dist/*.whl
155-
retention-days: 1
138+
# CIBW_ENVIRONMENT_MACOS: >-
139+
# MACOSX_DEPLOYMENT_TARGET=11.0
140+
# REPAIR_LIBRARY_PATH="/tmp/bfiocpp_bld/local_install/lib:/tmp/bfiocpp_bld/local_install/lib64"
141+
# ON_GITHUB="TRUE"
142+
# BFIOCPP_DEP_DIR="/tmp/bfiocpp_bld/local_install"
143+
# CMAKE_ARGS="-DTENSORSTORE_USE_SYSTEM_JPEG=ON"
144+
# CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
145+
# DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
146+
# DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
147+
# CIBW_ARCHS: ${{ matrix.cibw_archs }}
148+
# CIBW_TEST_REQUIRES: "bfio requests numpy ome_zarr zarr"
149+
# CIBW_TEST_COMMAND: python -W default -m unittest discover -s {project}/tests -v
150+
151+
# - name: Upload Artifact
152+
# uses: actions/upload-artifact@v4
153+
# with:
154+
# name: bfiocpp-wheels-${{ matrix.os }}-${{ matrix.cibw_archs }}-${{ matrix.cibw_build }}
155+
# path: dist/*.whl
156+
# retention-days: 1

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ FetchContent_Declare(
4242
)
4343

4444
# Additional FetchContent_Declare calls as needed...
45-
45+
set(TENSORSTORE_USE_SYSTEM_GRPC ON CACHE BOOL "")
4646
FetchContent_MakeAvailable(tensorstore)
4747

4848

ci-utils/install_prereq_linux.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,18 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
5151
make install -j4
5252
cd ../../
5353

54-
curl -L https://github.com/grpc/grpc/archive/refs/tags/v1.74.0.zip -o grpc174.zip
55-
unzip grpc174.zip
54+
git clone --branch v1.74.0 --depth 1 --recurse-submodules https://github.com/grpc/grpc.git grpc-1.74.0
5655
cd grpc-1.74.0
57-
mkdir build_man
58-
cd build_man
59-
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX=/usr/local ..
56+
mkdir -p cmake/build_man
57+
cd cmake/build_man
58+
cmake \
59+
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
60+
-DCMAKE_INSTALL_PREFIX=/usr/local \
61+
-DgRPC_INSTALL=ON \
62+
-DgRPC_BUILD_TESTS=OFF \
63+
../..
64+
6065
cmake --build .
6166
cmake --build . --target install
62-
cd ../../
67+
cd ../../../
6368
fi

setup.py

Lines changed: 22 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -4,159 +4,46 @@
44
import versioneer
55
import platform
66
import subprocess
7-
from pathlib import Path
7+
# from pathlib import Path
88

99
from distutils.version import LooseVersion
1010
from setuptools import setup, find_packages, Extension
1111
from setuptools.command.build_ext import build_ext
1212

1313

14-
# def patch_zlib_fdopen(build_temp: str) -> None:
14+
# def patch_grpc_basic_seq(build_temp: str) -> None:
1515
# """
16-
# Patch vendored zlib in the CMake build tree to remove the broken
17-
# fdopen macro that conflicts with macOS 15 / Xcode 16.x SDK headers.
16+
# Patch gRPC's basic_seq.h to drop the 'template' keyword from
17+
# Traits::template CallSeqFactory(...) which appears to upset
18+
# Apple Clang on macOS 15 / Xcode 16.
1819
# """
1920
# build_temp_path = Path(build_temp)
20-
# zutil_files = list(build_temp_path.rglob("zutil.h"))
21+
# basic_seq_files = list(build_temp_path.rglob("basic_seq.h"))
2122

22-
# if not zutil_files:
23-
# print("[patch_zlib_fdopen] No zutil.h found under", build_temp_path)
23+
# if not basic_seq_files:
24+
# print("[patch_grpc_basic_seq] No basic_seq.h found under", build_temp_path)
2425
# return
2526

26-
# for zutil in zutil_files:
27-
# try:
28-
# text = zutil.read_text()
29-
# except OSError as e:
30-
# print(f"[patch_zlib_fdopen] Failed to read {zutil}: {e}")
31-
# continue
32-
33-
# before = '# define fdopen(fd,mode) NULL /* No fdopen() */'
34-
# if before in text:
35-
# after = '/* patched out fdopen macro for macOS ' \
36-
# '(was: define fdopen(fd,mode) NULL) */'
37-
# text = text.replace(before, after)
38-
# try:
39-
# zutil.write_text(text)
40-
# print(f"[patch_zlib_fdopen] Patched fdopen macro in {zutil}")
41-
# except OSError as e:
42-
# print(f"[patch_zlib_fdopen] Failed to write {zutil}: {e}")
43-
# else:
44-
# print(f"[patch_zlib_fdopen] fdopen macro not found in {zutil}")
45-
46-
47-
# def patch_png_fp(build_temp: str) -> None:
48-
# """
49-
# Patch vendored libpng in the CMake build tree to remove the include
50-
# of the obsolete <fp.h> header on macOS 15+ SDKs.
51-
# """
52-
# build_temp_path = Path(build_temp)
53-
54-
# # --- 1. Remove obsolete <fp.h> include from pngpriv.h ---
55-
# pngpriv_files = list(build_temp_path.rglob("pngpriv.h"))
56-
57-
# if not pngpriv_files:
58-
# print("[patch_png_fp] No pngpriv.h found under", build_temp_path)
59-
# else:
60-
# pattern_fp = re.compile(r"#\s*include\s+<fp\.h>")
61-
# for pngpriv in pngpriv_files:
62-
# try:
63-
# text = pngpriv.read_text()
64-
# except OSError as e:
65-
# print(f"[patch_png_fp] Failed to read {pngpriv}: {e}")
66-
# continue
67-
68-
# new_text, n_subs = pattern_fp.subn(
69-
# "/* patched out include of obsolete <fp.h> for macOS */", text
70-
# )
71-
# if n_subs > 0:
72-
# try:
73-
# pngpriv.write_text(new_text)
74-
# print(
75-
# f"[patch_png_fp] Patched <fp.h> include in {pngpriv} "
76-
# f"(replaced {n_subs} line(s))"
77-
# )
78-
# except OSError as e:
79-
# print(f"[patch_png_fp] Failed to write {pngpriv}: {e}")
80-
# else:
81-
# print(f"[patch_png_fp] <fp.h> include not matched in {pngpriv}")
27+
# pattern = "Traits::template CallSeqFactory("
28+
# replacement = "Traits::CallSeqFactory("
8229

83-
84-
# def patch_png_math(build_temp: str) -> None:
85-
# """
86-
# Ensure libpng's png.c has #include <math.h> so frexp/modf/floor/pow
87-
# are properly declared when compiling with modern C standards.
88-
# """
89-
# build_temp_path = Path(build_temp)
90-
# # libpng sources are typically named png*.c
91-
# png_c_files = list(build_temp_path.rglob("png*.c"))
92-
93-
# if not png_c_files:
94-
# print("[patch_png_math] No png*.c found under", build_temp_path)
95-
# return
96-
97-
# # Heuristics: only patch files that actually use the math functions
98-
# math_funcs = ("frexp", "modf", "floor", "pow")
99-
100-
# for png_c in png_c_files:
30+
# for hdr in basic_seq_files:
10131
# try:
102-
# text = png_c.read_text()
32+
# text = hdr.read_text()
10333
# except OSError as e:
104-
# print(f"[patch_png_math] Failed to read {png_c}: {e}")
34+
# print(f"[patch_grpc_basic_seq] Failed to read {hdr}: {e}")
10535
# continue
10636

107-
# # Skip if math.h already there
108-
# if "<math.h>" in text:
109-
# print(f"[patch_png_math] math.h already referenced in {png_c}")
37+
# if pattern not in text:
38+
# print(f"[patch_grpc_basic_seq] Pattern not found in {hdr}")
11039
# continue
11140

112-
# # Skip if file doesn't use any math function we're fixing
113-
# if not any(f in text for f in math_funcs):
114-
# # keep log to know we saw it
115-
# print(f"[patch_png_math] No math functions to patch in {png_c}")
116-
# continue
117-
118-
# # Prepend include at top of file
119-
# new_text = '#include <math.h>\n' + text
41+
# new_text = text.replace(pattern, replacement)
12042
# try:
121-
# png_c.write_text(new_text)
122-
# print(f"[patch_png_math] Injected #include <math.h> into {png_c}")
43+
# hdr.write_text(new_text)
44+
# print(f"[patch_grpc_basic_seq] Patched CallSeqFactory in {hdr}")
12345
# except OSError as e:
124-
# print(f"[patch_png_math] Failed to write {png_c}: {e}")
125-
126-
127-
def patch_grpc_basic_seq(build_temp: str) -> None:
128-
"""
129-
Patch gRPC's basic_seq.h to drop the 'template' keyword from
130-
Traits::template CallSeqFactory(...) which appears to upset
131-
Apple Clang on macOS 15 / Xcode 16.
132-
"""
133-
build_temp_path = Path(build_temp)
134-
basic_seq_files = list(build_temp_path.rglob("basic_seq.h"))
135-
136-
if not basic_seq_files:
137-
print("[patch_grpc_basic_seq] No basic_seq.h found under", build_temp_path)
138-
return
139-
140-
pattern = "Traits::template CallSeqFactory("
141-
replacement = "Traits::CallSeqFactory("
142-
143-
for hdr in basic_seq_files:
144-
try:
145-
text = hdr.read_text()
146-
except OSError as e:
147-
print(f"[patch_grpc_basic_seq] Failed to read {hdr}: {e}")
148-
continue
149-
150-
if pattern not in text:
151-
print(f"[patch_grpc_basic_seq] Pattern not found in {hdr}")
152-
continue
153-
154-
new_text = text.replace(pattern, replacement)
155-
try:
156-
hdr.write_text(new_text)
157-
print(f"[patch_grpc_basic_seq] Patched CallSeqFactory in {hdr}")
158-
except OSError as e:
159-
print(f"[patch_grpc_basic_seq] Failed to write {hdr}: {e}")
46+
# print(f"[patch_grpc_basic_seq] Failed to write {hdr}: {e}")
16047

16148

16249
class CMakeExtension(Extension):
@@ -227,15 +114,9 @@ def build_extension(self, ext):
227114
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env
228115
)
229116

230-
if platform.system() == "Darwin":
231-
# print("--------------- Applying zlib fdopen patch on macOS")
232-
# patch_zlib_fdopen(self.build_temp)
233-
# print("--------------- Applying libpng fp.h patch on macOS")
234-
# patch_png_fp(self.build_temp)
235-
# print("--------------- Applying libpng math.h patch on macOS")
236-
# patch_png_math(self.build_temp)
237-
print("--------------- Applying gRPC basic_seq patch on macOS")
238-
patch_grpc_basic_seq(self.build_temp)
117+
# if platform.system() == "Darwin":
118+
# print("--------------- Applying gRPC basic_seq patch on macOS")
119+
# patch_grpc_basic_seq(self.build_temp)
239120

240121
if platform.system() == "Linux":
241122
rl = r"s/^#ifdef __has_builtin$/#if defined(__has_builtin)"

0 commit comments

Comments
 (0)