From bfde2eb30fb84464dc839dca22bd20ca17350990 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 22 May 2026 12:07:26 +0000 Subject: [PATCH] py3-pygraphviz: fix for ABI break in Graphviz 14 to unbreak with llvm22 gvRenderData()'s fourth argument changed from unsigned int * to size_t *, which makes llvm22 unhappy. Adjust prototype and use SWIG to generate the binding wrap.c. Based on upstream PR #523. --- math/py-pygraphviz/Makefile | 7 +- .../patches/patch-pygraphviz_graphviz_i | 18 +++++ math/py-pygraphviz/patches/patch-setup_py | 70 +++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 math/py-pygraphviz/patches/patch-pygraphviz_graphviz_i create mode 100644 math/py-pygraphviz/patches/patch-setup_py diff --git a/math/py-pygraphviz/Makefile b/math/py-pygraphviz/Makefile index d28241584c7..81b2601b813 100644 --- a/math/py-pygraphviz/Makefile +++ b/math/py-pygraphviz/Makefile @@ -4,7 +4,7 @@ MODPY_DISTV = 1.14 DISTNAME = pygraphviz-${MODPY_DISTV} PKGNAME = py-${DISTNAME} CATEGORIES = math -REVISION = 0 +REVISION = 1 HOMEPAGE = https://pygraphviz.github.io/ @@ -19,9 +19,14 @@ MODPY_PI = Yes MODPY_PYBUILD = setuptools MODPY_TEST_LINK_SO = Yes +BUILD_DEPENDS += devel/swig + LIB_DEPENDS += math/graphviz CFLAGS += -I${LOCALBASE}/include LDFLAGS += -L${LOCALBASE}/lib +post-patch: + ${SUBST_CMD} ${WRKSRC}/setup.py + .include diff --git a/math/py-pygraphviz/patches/patch-pygraphviz_graphviz_i b/math/py-pygraphviz/patches/patch-pygraphviz_graphviz_i new file mode 100644 index 00000000000..28aba0144a0 --- /dev/null +++ b/math/py-pygraphviz/patches/patch-pygraphviz_graphviz_i @@ -0,0 +1,18 @@ +https://github.com/pygraphviz/pygraphviz/pull/573/ + +Index: pygraphviz/graphviz.i +--- pygraphviz/graphviz.i.orig ++++ pygraphviz/graphviz.i +@@ -338,7 +338,12 @@ int gvRenderFilename(GVC_t *gvc, Agraph_t* g, char *fo + /* three lines are straight from the SWIG manual. */ + %include + %include ++#if GRAPHVIZ_VERSION_MAJOR >= 14 ++%cstring_output_allocate_size(char **result, size_t* size, free(*$1)); ++int gvRenderData(GVC_t *gvc, Agraph_t* g, char *format, char **result, size_t *size); ++#else + %cstring_output_allocate_size(char **result, unsigned int* size, free(*$1)); + int gvRenderData(GVC_t *gvc, Agraph_t* g, char *format, char **result, unsigned int *size); ++#endif + /* Free memory allocated and pointed to by *result in gvRenderData */ + extern void gvFreeRenderData (char* data); diff --git a/math/py-pygraphviz/patches/patch-setup_py b/math/py-pygraphviz/patches/patch-setup_py new file mode 100644 index 00000000000..b8418039ac6 --- /dev/null +++ b/math/py-pygraphviz/patches/patch-setup_py @@ -0,0 +1,70 @@ +https://github.com/pygraphviz/pygraphviz/pull/573 + +Index: setup.py +--- setup.py.orig ++++ setup.py +@@ -1,15 +1,55 @@ + import sys ++import os ++import re + from setuptools import setup, Extension + ++def get_graphviz_version(): ++ """ ++ Reads GRAPHVIZ_VERSION_MAJOR from the header file. ++ Assumes the header is available at a known path during setup. ++ """ ++ # NOTE: You may need to adjust this path based on your environment ++ # or rely on the build system to have already installed it. ++ header_path = '${LOCALBASE}/include/graphviz/graphviz_version.h' ++ ++ if not os.path.exists(header_path): ++ # Fallback/default if header file cannot be read during setup. ++ # This should match your expected target version. ++ raise RuntimeError(f"Graphviz header file not found at {header_path}.") ++ ++ with open(header_path, 'r') as f: ++ content = f.read() ++ match = re.search(r'#define\s+GRAPHVIZ_VERSION_MAJOR\s+(\d+)', content) ++ if match: ++ return str(int(match.group(1))) ++ else: ++ match = re.search(r'#define\s+PACKAGE_VERSION\s+"([0-9.]+)"', ++ content) ++ if match: ++ maj_ver = match.group(1).split('.')[0] ++ return str(int(maj_ver)) ++ ++ raise RuntimeError( ++ "GRAPHVIZ_VERSION_MAJOR macro not found in the header file!") ++ + if __name__ == "__main__": + define_macros = [("SWIG_PYTHON_STRICT_BYTE_CHAR", None)] + if sys.platform == "win32": + define_macros.append(("GVDLL", None)) + ++ # Get the target version number ++ gv_major_version = get_graphviz_version() ++ ++ define_macros = [] ++ swig_options = [] ++ ++ swig_options.append("-DGRAPHVIZ_VERSION_MAJOR={}".format(gv_major_version)) ++ print(f"Defining GRAPHVIZ_VERSION_MAJOR as: {gv_major_version}") ++ + extension = [ + Extension( + name="pygraphviz._graphviz", +- sources=["pygraphviz/graphviz_wrap.c"], ++ sources=["pygraphviz/graphviz.i"], + include_dirs=[], + library_dirs=[], + # cdt does not link to cgraph, whereas cgraph links to cdt. +@@ -20,6 +60,7 @@ if __name__ == "__main__": + # undefined symbol errors. seen under PyPy on Linux.) + libraries=["cdt", "cgraph", "gvc"], + define_macros=define_macros, ++ swig_opts=swig_options, + ) + ] +