As of now, it doesn’t seem like there’s any specified way to link against another extension module, meaning you can’t expose symbols from an extension to other extensions.
The current solution is to use capsules, which for those of you unfamiliar with the C API, simply transports a void*
. To build a public extension API right now, you give an extension module a capsule object, and then write some header files that import your module, extract an array of function pointers from the capsule, and then populate local function pointers.
The biggest problem with this approach is that you force developers to use those headers. A Rust program, for example could not really use your API (without quite a bit of reverse engineering, at least) since the symbols used are not actually exported in the compiled object. They would have to manually rewrite your initialization function and figure out how to use functions extracted from a void**
(including writing all the typedefs as well).
It would be much nicer if extension modules could directly link against another extension’s shared object file. For example, with setuptools
, maybe it could look something like:
Extension("whatever", […], py_libraries=["some_installed_extension"])
I think part of the problem is that there’s a limited number of people who work with both the C API and packaging. I know very little about packaging specifications, so I would be happy to hear issues with this approach and/or previous discussions about this topic.