version = m.group(1)
+def get_config(what: str) -> str:
+ try:
+ out = sp.run(["pg_config", f"--{what}"], stdout=sp.PIPE, check=True)
+ except Exception as e:
+ log.error("cannot build C module: %s", e)
+ raise
+ else:
+ return out.stdout.strip().decode("utf8")
+
+
class psycopg_build_ext(build_ext):
def finalize_options(self) -> None:
self._setup_ext_build()
if os.path.exists("psycopg_c/_psycopg.pyx"):
from Cython.Build import cythonize
- # Add the include dir for the libpq.
- try:
- out = sp.run(
- ["pg_config", "--includedir"], stdout=sp.PIPE, check=True
- )
- except Exception as e:
- log.error("cannot build C module: %s", e)
- raise
-
- includedir = out.stdout.strip().decode("utf8")
+ # Add include and lib dir for the libpq.
+ includedir = get_config("includedir")
+ libdir = get_config("libdir")
for ext in self.distribution.ext_modules:
ext.include_dirs.append(includedir)
+ ext.library_dirs.append(libdir)
if cythonize is not None:
for ext in self.distribution.ext_modules: