Support to build Python module without pkg-config
authorKentaro Hayashi <kenhys@gmail.com>
Sat, 17 Jun 2023 13:39:14 +0000 (22:39 +0900)
committerKentaro Hayashi <kenhys@xdump.org>
Sat, 19 Aug 2023 08:14:56 +0000 (09:14 +0100)
Gbp-Pq: Name support-python-module-in-place.patch

python/setup.py

index 54112313b54983cac136c3ad1e2f5a6f9213b6f1..631a8c45805715587ef3fd6cbe1e495cac7040a9 100755 (executable)
@@ -77,23 +77,29 @@ class build_ext(_build_ext):
   """Override build_extension to run cmake."""
 
   def build_extension(self, ext):
-    cflags, libs = get_cflags_and_libs('../build/root')
-
-    if len(libs) == 0:
-      if is_sentencepiece_installed():
-        cflags = cflags + run_pkg_config('cflags')
-        libs = run_pkg_config('libs')
-      else:
-        subprocess.check_call(['./build_bundled.sh', __version__])
-        cflags, libs = get_cflags_and_libs('./build/root')
+    # cflags, libs = get_cflags_and_libs('../build/root')
+    # if len(libs) == 0:
+    #   cflags, libs = get_cflags_and_libs('./bundled/root')
+
+    # if len(libs) == 0:
+    #   if is_sentencepiece_installed():
+    #     cflags = cflags + run_pkg_config('cflags')
+    #     libs = run_pkg_config('libs')
+    #   else:
+    #     subprocess.check_call(['./build_bundled.sh', __version__])
+    #     cflags, libs = get_cflags_and_libs('./bundled/root')
 
     # Fix compile on some versions of Mac OSX
     # See: https://github.com/neulab/xnmt/issues/199
-    if sys.platform == 'darwin':
-      cflags.append('-mmacosx-version-min=10.9')
-    else:
-      cflags.append('-Wl,-strip-all')
-      libs.append('-Wl,-strip-all')
+    # if sys.platform == 'darwin':
+    #   cflags.append('-mmacosx-version-min=10.9')
+    # else:
+    #   cflags.append('-Wl,-strip-all')
+    #   libs.append('-Wl,-strip-all')
+    cflags = ['-I../src']
+    cmd = "dpkg-architecture -q DEB_BUILD_GNU_TYPE"
+    arch = subprocess.check_output(cmd, shell=True).decode("utf-8").strip().split()[0]
+    libs = ["-L../obj-%s/src" % arch, "-lsentencepiece", "-lsentencepiece_train"]
     print('## cflags={}'.format(' '.join(cflags)))
     print('## libs={}'.format(' '.join(libs)))
     ext.extra_compile_args = cflags