-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python: compiling libraries against Limited API in addition to extensions? #13824
Comments
Option 2 does seem nice and useful. Perhaps even nicer (or do both): add the Option 1 I don't like as much. Something like that can already be done with py = import('python').find_installation()
py_dep = py.dependency()
py_dep = declare_dependency(
dependencies: py_dep,
compile_args: '-DPy_LIMITED_API='0x030100',
) The |
@rgommers The suggestion of adding I regret not implementing it that way from the start as it's definitely a better API than having it be on It's an API change, so users will have to be informed, but it's relatively recent functionality so there's probably not yet many who would be affected (a priori). |
I don't think it needs to be an API change, right? It's only a new keyword for |
I think that having the kwarg be on It's fundamentally not about what kind of dependency you retrieve from your own upstreams, but rather about what kind of artifacts you yourself create. |
find_installation I could hear inasmuch as all it would do is change the default value of the limited API when invoking extension_module. Just like how pure works -- you can always override it per installed object. Ultimately it is data tied to the installed object, not the py_installation. |
Exactly, that - it's a close analogy. Just like for
Sure, agreed. |
In terms of implementation, would it be okay for the logic that generates the |
This is what I meant by a better API: having it be a default but overridable. And also having its behaviour be like
I was envisaging situations where we might need to detect if a user set a pymod = import('python')
py3_inst = pymod.find_installation(
limited_api: '3.10'
)
# 'limited_api' unspecified, defaults to 3.10 from the installation.
my_mod = py3_inst.extension_module(
'my_mod.c'
)
# manually overriden to 3.8
my_other_mod = py3_inst.extension_module(
'my_other_mod.c',
limited_api: '3.8'
) Huh, maybe this is perfectly fine in fact, now that I've written it out and read it back to myself. |
Is there any progress on this? I've stumbled across this issue because we are struggling to get PostgreSQL compiled with the Python limited API on Windows. PostgreSQL embeds the Python interpreter, so it uses Is there a workaround for this issue? |
I think someone just needs to add support for detecting the limited API to It shouldn't be too hard, just nobody has both needed this and had spare cycles to devote to it I guess. |
Yes, I just haven't needed it urgently enough to work on it. I may get to it in the next few weeks, but if someone else has spare cycles now and wants to jump on it, that's fine with me! |
This is a continuation of mesonbuild/wrapdb#1758, but @eli-schwartz suggested the correct fix is a modification of Meson itself rather than the nanobind wrapper, so I thought I'd open an issue here for visibility/discussion.
The question is how a library like nanobind that has a Python dependency, but is not a Python extension, can target the Limited API. This requires a define like
-DPy_LIMITED_API=0x030c0000
that encodes the API version. Currently,limited_api
is only exposed as a kwarg forpy.extension_module()
.Based on my limited (pun intended) Meson experience, I can see two options:
python_installation
. For example:limited_api
as a kwarg ofpy.dependency()
. The dependency object can add the hex define internally to itscompile_args
. For example:Option 1 seems simpler to implement, it would just be exposing a string. It's also more flexible, in case someone needs the define without expressing a proper dependency on Python (seems niche though).
Option 2 seems more elegant, and seems less error prone in the sense that a user doesn't need to remember to add the define to every library that targets Python.
In terms of possibly implementing Option 2, it looks like
py.extension_module
already generates apython_dependency
internally (here). I think this means that the logic that currently resides in theextension_module
for targeting the Limited API (here) could mostly be moved upstream to the dependency. Then anything that targets apython_dependency
—anextension_module
implicitly or a library explicitly—could inherit the right define.What do others think? Is either of these solutions on the right track?
The text was updated successfully, but these errors were encountered: