This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients brett.cannon, christian.heimes, ned.deily, twouters
Date 2021-11-10.12:00:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1636545622.33.0.622478666161.issue45573@roundup.psfhosted.org>
In-reply-to
Content
We can detect majority of our dependencies with pkg-config. The use of pkg-config has some benefits:

* Distro's provide the .pc files in their -dev / -devel packages. The presence of a .pc file indicates that all development dependencies are available.

* pkg-config does the right thing for non-standard include and libraries directories as well as multiarch builds. In case a library or header is not on the default search path, pkg-config returns necessary -I and -L flags.

* At least the pkgconf implementation of pkg-config standard search /usr/local and ~/.local/ directories for .pc files. Cases like https://github.com/python/cpython/pull/29507 are handled correctly. On FreeBSD "pkgconf sqlite3 --cflags --libs" returns "-I/usr/local/include -L/usr/local/lib -lsqlite3".

* pkg-config understands dependencies. For example "pkg-config --libs tk" returns linker flags for TK *and* TCL.

* pkg-config can check for module version, e.g. "pkg-config sqlite3 --atleast-version=3.7.15"


pkg-config modules:

  readline, libedit
  ncursesw, ncurses, panel, tinfo
  sqlite3
  zlib
  bzip2
  liblzma
  expat
  uuid (Linux's util-linux uuid)
  libffi
  libnsl, libtirpc
  libcrypt
  tcl, tk
  openssl, libssl, libcrypto
  
modules / libraries without pkg-config modules:

  decimal: libmpdec
  gdbm: gdbm
  dbm: gdbm_compat, ndbm, libdb (bdb)


To simplify use of flags in Modules/Setup, I propose to add two make variables for each module that needs cflags and ldflags:

  f"MODULE_{ext.name.upper()}_CFLAGS"
  f"MODULE_{ext.name.upper()}_LDFLAGS"

e.g. for the _ssl module:

  MODULE__SSL_CFLAGS=
  MODULE__SSL_LDFLAGS=-lssl -lcrypto

Then use the flags from Makefile in setup.py:

    def update_extension_flags(self, ext):
        name = ext.name.upper()
        cflags = sysconfig.get_config_var(f"MODULE_{name}_CFLAGS")
        if cflags:
            ext.extra_compile_args.extend(shlex.split(cflags))
        ldflags = sysconfig.get_config_var(f"MODULE_{name}_LDFLAGS")
        if ldflags:
            ext.extra_link_args.extend(shlex.split(ldflags))
        return ext

Finally update Modules/makesetup to use the new variables, too.
History
Date User Action Args
2021-11-10 12:00:22christian.heimessetrecipients: + christian.heimes, twouters, brett.cannon, ned.deily
2021-11-10 12:00:22christian.heimessetmessageid: <1636545622.33.0.622478666161.issue45573@roundup.psfhosted.org>
2021-11-10 12:00:22christian.heimeslinkissue45573 messages
2021-11-10 12:00:21christian.heimescreate