-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Prepend Pybind11Extension flags rather than appending them. #2808
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
Conversation
This allows users to set e.g. `extra_compile_args=["-g"]` (temporarily, for debugging purposes) and not have that get overridden by Pybind11Extension's default `-g0`. In order to minimize "order inversion" (not that it really matters, though) I chose to collect all flags and add them at once (hence the dropping of `*args`). I also dropped flag deduplication, which seems unneeded.
if flag not in self.extra_link_args: | ||
self.extra_link_args.append(flag) | ||
def _add_cflags(self, flags): | ||
self.extra_compile_args[:0] = flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I did not know this was valid! But it is, even back in 2.7!
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Nov 23 2020, 08:01:20)
[GCC Apple LLVM 12.0.0 (clang-1200.0.30.4) [+internal-os, ptrauth-isa=sign+stri on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [1,2,3]
>>> a[:0] = [4,5,6]
>>> a
[4, 5, 6, 1, 2, 3]
Even can be used in the middle:
>>> a[5:5] = [10]
>>> a
[4, 5, 6, 1, 2, 10, 3]
Maybe this is common knowledge, but it surprised me. :)
self._add_cflags(cflags) | ||
self._add_ldflags(ldflags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason these are prepended? This may happen at the beginning (if it is manually specified), at an arbitrary point (if assigned to, in Python 3), or at the end (if left to "automatic"). The order of these particular flags shouldn't really matter, in theory, I'd expect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to just prepend everything to simplify the explanation ("pybind11 puts all its flags at the beginning") (also, perhaps someone really wants to override one of the -Wflags...), but admittedly the only thing I personally really care about is -g
, so I can revert the changes on this specific part if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, it's the most consistent (I think) if this gets triggered at different times.
Question you might be able to answer: do you know how to get setuptools to put the user includes before the system includes? Setuptools adds the main directory in front of the user includes (specifically, the pybind11 one), so if you have a system install of pybind11, it might override the local one if it's in the same places as the Python include. I'm not sure of this, where I've seen the bug is for boost - my system install of boost was overriding the local one I was trying to provide in Pybind11Extension. I fixed this in CMake, but don't know how to fix it in setuptools at the moment. |
Just to be clear, this is unrelated to this PR? I can have a look, but perhaps we can move the discussion to a separate issue? In any case I'm not sure what's the behavior you're mentioning, as trying e.g. to compile
so here it's indeed the local install that comes first. |
Yes, it's a separate issue. I'll try to test it a bit more in the near future, and I'll refer back here if I can show it again. Thanks! |
feel free to ping me as needed. |
Description
This allows users to set e.g.
extra_compile_args=["-g"]
(temporarily,for debugging purposes) and not have that get overridden by
Pybind11Extension's default
-g0
.In order to minimize "order inversion" (not that it really matters,
though) I chose to collect all flags and add them at once (hence the
dropping of
*args
). I also dropped flag deduplication, which seemsunneeded.
Suggested changelog entry: