From: Boyuan Yang Date: Tue, 13 Jan 2026 18:04:57 -0500 Subject: setup.py: Handle python binding instead of cmake Link the extension against the libopencc.so built by the cmake pass in $OPENCC_BUILD_DIR/src. Only -L (library_dirs) is set on purpose: adding runtime_library_dirs would bake the (build-time-only) build directory into DT_RUNPATH, and even deleting that entry afterwards leaves the build path behind in .dynstr (lintian: file-references-package-build-path). The installed extension resolves libopencc.so.1.4 through the regular linker search path instead; debian/rules sets LD_LIBRARY_PATH for the test run. Forwarded: not-needed --- setup.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) Index: opencc/setup.py =================================================================== --- opencc.orig/setup.py +++ opencc/setup.py @@ -9,6 +9,8 @@ import setuptools import setuptools.command.build_ext import wheel.bdist_wheel +import pybind11 + _this_dir = os.path.dirname(os.path.abspath(__file__)) _build_dir = os.path.join(_this_dir, 'build', 'python') @@ -148,10 +150,12 @@ class OpenCCExtension(setuptools.Extensi class BuildExtCommand(setuptools.command.build_ext.build_ext, object): def build_extension(self, ext): - if self.inplace: - output_path = os.path.join(_this_dir, 'python', 'opencc', 'clib') - else: - output_path = os.path.abspath(os.path.join(self.build_lib, 'opencc', 'clib')) + project_root = os.path.abspath(_this_dir) + build_dir = os.environ.get('OPENCC_BUILD_DIR', 'obj-x86_64-linux-gnu') + lib_path = os.path.join(project_root, build_dir, 'src') + ext.include_dirs.append(pybind11.get_include()) + ext.include_dirs.append('src') + ext.library_dirs = [lib_path] if isinstance(ext, OpenCCExtension): build_libopencc(output_path) else: @@ -215,7 +220,14 @@ setuptools.setup( packages=packages, package_dir={'opencc': 'python/opencc'}, - ext_modules=[OpenCCExtension('opencc.clib.opencc_clib', 'python')], + ext_modules=[ + setuptools.Extension( + 'opencc.clib.opencc_clib', + sources=['src/py_opencc.cpp'], + libraries=['opencc'], + language='c++' + ) + ], cmdclass={ 'build_ext': BuildExtCommand, 'bdist_wheel': BDistWheelCommand,