|
4 | 4 | import versioneer |
5 | 5 | import platform |
6 | 6 | import subprocess |
7 | | -from pathlib import Path |
| 7 | +# from pathlib import Path |
8 | 8 |
|
9 | 9 | from distutils.version import LooseVersion |
10 | 10 | from setuptools import setup, find_packages, Extension |
11 | 11 | from setuptools.command.build_ext import build_ext |
12 | 12 |
|
13 | 13 |
|
14 | | -# def patch_zlib_fdopen(build_temp: str) -> None: |
| 14 | +# def patch_grpc_basic_seq(build_temp: str) -> None: |
15 | 15 | # """ |
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. |
18 | 19 | # """ |
19 | 20 | # 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")) |
21 | 22 |
|
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) |
24 | 25 | # return |
25 | 26 |
|
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(" |
82 | 29 |
|
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: |
101 | 31 | # try: |
102 | | -# text = png_c.read_text() |
| 32 | +# text = hdr.read_text() |
103 | 33 | # 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}") |
105 | 35 | # continue |
106 | 36 |
|
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}") |
110 | 39 | # continue |
111 | 40 |
|
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) |
120 | 42 | # 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}") |
123 | 45 | # 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}") |
160 | 47 |
|
161 | 48 |
|
162 | 49 | class CMakeExtension(Extension): |
@@ -227,15 +114,9 @@ def build_extension(self, ext): |
227 | 114 | ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env |
228 | 115 | ) |
229 | 116 |
|
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) |
239 | 120 |
|
240 | 121 | if platform.system() == "Linux": |
241 | 122 | rl = r"s/^#ifdef __has_builtin$/#if defined(__has_builtin)" |
|
0 commit comments