-
Notifications
You must be signed in to change notification settings - Fork 777
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
Replace extension-module
feature with PYO3_MAKE_EXTENSION_MODULE
#1040
Conversation
(Test failures are expected and will be resolved after I update setuptools-rust. First I'd like someone to review this idea to confirm that it's a sensible proposal.) |
It seems weird to me that this is an environment variable. It seems like an inherent property of the project (which would go into per-project configuration), not something that you would ever want to configure in your environment by setting a variable. |
I agree with you regarding this statement. However, as discussed in #904 #771 the current design of using a feature as per-project configuration is problematic. I would argue that this proposed environment variable is the mechanism for pyo3 to build an extension module correctly, and the per-project configuration lives elsewhere:
|
Seems to be a reason for me to try out maturin :) |
@davidhewitt Understood, but I still don't think an environment variable is the right way to transmit this information to the compiler. This is something that, per-project, you either always want on, or never want on. If there's no way to transmit this information other than via environment variable, then I guess it's just a bit of a wart, but I think it's worth considering other options. What about some sort of configuration file other than a feature? I'm not super familiar with the I guess the one downside to this "configure it in a file" approach is that |
Unfortunately, this is exactly what turned out not to be true for And the same is true for tests - even unit tests written in
I could be wrong, but I came to the conclusion that any sort of static configuration falls to this same issue. We don't want the This is why I came to the conclusion that an evironment variable is the best way to go. FWIW, I agree it's a bit of a wart, but:
(EDIT: adding the missing not in the second paragraph.) |
Hmm... 🤔 |
Maybe it's just me, I feel it's exactly the job of tools to set this variable. We make the base package support all combinations users might want using configuration. Then tools manage as much of that configuration as possible to make users' lives easier. |
I agree with David - I don't think having it as a default feature is helpful. Somehow if the packaging tools can do the right thing that would be great. This seems like an alternative to PyO3/maturin#325 |
I believe that rust-lang/cargo#8441 would be the best solution and also the only one that consistently does the right thing (excluding proc macros that compile python to bytecode maybe, but that's some very special case). It should be possible to build cargo of that pull request and check if that works for pyo3. There should be some precaution against users defaulting to binary linking because they forgot to set the environment variable or use cargo through some tool/IDE. For maturin this change should be easy to implement, but you should also consider that there are many that use |
I took a go with rust-lang/cargo#8441. Sadly it appears that in its current form the linker flags don't get passed to dependencies, so this still won't help us here.
I have been thinking further on this point. I don't think it matters if the extension uses binary linking for local development? So as long as we document clearly how to package extensions properly (e.g. either set this env var when building, or use a supported too), then I think we have taken appropriate precaution. |
This seems to have been fixed after your comment in rust-lang/cargo@6382d8b |
Indeed it is, and it works beautifully. Closing this in favour of #1123 |
This is another try at an alternative to the
extension-module
feature.Inspired by PyO3/maturin#325, this changes the
extension-module
feature to instead be an environment variablePYO3_MAKE_EXTENSION_MODULE
.Users building extension modules are expected to set this during
cargo build
to turn off linkinglibpython
. I will updatematurin
andsetuptools-rust
to do this automatically. This way I hope 99% of users will no longer have linking errors, and everything should just work magically.