| 1 |
From: Boyuan Yang <[email protected]> |
| 2 |
Date: Tue, 13 Jan 2026 18:04:57 -0500 |
| 3 |
Subject: setup.py: Handle python binding instead of cmake |
| 4 |
|
| 5 |
Link the extension against the libopencc.so built by the cmake pass in |
| 6 |
$OPENCC_BUILD_DIR/src. Only -L (library_dirs) is set on purpose: adding |
| 7 |
runtime_library_dirs would bake the (build-time-only) build directory into |
| 8 |
DT_RUNPATH, and even deleting that entry afterwards leaves the build path |
| 9 |
behind in .dynstr (lintian: file-references-package-build-path). The |
| 10 |
installed extension resolves libopencc.so.1.4 through the regular linker |
| 11 |
search path instead; debian/rules sets LD_LIBRARY_PATH for the test run. |
| 12 |
|
| 13 |
Forwarded: not-needed |
| 14 |
--- |
| 15 |
setup.py | 21 ++++++++++++++++----- |
| 16 |
1 file changed, 16 insertions(+), 5 deletions(-) |
| 17 |
|
| 18 |
Index: opencc/setup.py |
| 19 |
=================================================================== |
| 20 |
--- opencc.orig/setup.py |
| 21 |
+++ opencc/setup.py |
| 22 |
@@ -9,6 +9,8 @@ import setuptools |
| 23 |
import setuptools.command.build_ext |
| 24 |
import wheel.bdist_wheel |
| 25 |
|
| 26 |
+import pybind11 |
| 27 |
+ |
| 28 |
_this_dir = os.path.dirname(os.path.abspath(__file__)) |
| 29 |
_build_dir = os.path.join(_this_dir, 'build', 'python') |
| 30 |
|
| 31 |
@@ -148,10 +150,12 @@ class OpenCCExtension(setuptools.Extensi |
| 32 |
|
| 33 |
class BuildExtCommand(setuptools.command.build_ext.build_ext, object): |
| 34 |
def build_extension(self, ext): |
| 35 |
- if self.inplace: |
| 36 |
- output_path = os.path.join(_this_dir, 'python', 'opencc', 'clib') |
| 37 |
- else: |
| 38 |
- output_path = os.path.abspath(os.path.join(self.build_lib, 'opencc', 'clib')) |
| 39 |
+ project_root = os.path.abspath(_this_dir) |
| 40 |
+ build_dir = os.environ.get('OPENCC_BUILD_DIR', 'obj-x86_64-linux-gnu') |
| 41 |
+ lib_path = os.path.join(project_root, build_dir, 'src') |
| 42 |
+ ext.include_dirs.append(pybind11.get_include()) |
| 43 |
+ ext.include_dirs.append('src') |
| 44 |
+ ext.library_dirs = [lib_path] |
| 45 |
if isinstance(ext, OpenCCExtension): |
| 46 |
build_libopencc(output_path) |
| 47 |
else: |
| 48 |
@@ -215,7 +220,14 @@ setuptools.setup( |
| 49 |
|
| 50 |
packages=packages, |
| 51 |
package_dir={'opencc': 'python/opencc'}, |
| 52 |
- ext_modules=[OpenCCExtension('opencc.clib.opencc_clib', 'python')], |
| 53 |
+ ext_modules=[ |
| 54 |
+ setuptools.Extension( |
| 55 |
+ 'opencc.clib.opencc_clib', |
| 56 |
+ sources=['src/py_opencc.cpp'], |
| 57 |
+ libraries=['opencc'], |
| 58 |
+ language='c++' |
| 59 |
+ ) |
| 60 |
+ ], |
| 61 |
cmdclass={ |
| 62 |
'build_ext': BuildExtCommand, |
| 63 |
'bdist_wheel': BDistWheelCommand, |