-
Notifications
You must be signed in to change notification settings - Fork 779
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
pyo3-build-config: Make PYO3_CROSS_LIB_DIR
optional
#2241
Conversation
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.
Thanks; to check I understand the idea, it's that when PYO3_CROSS_LIB_DIR
is not set then (for unix extension modules at least) we can infer all we need from the abi3 and version settings?
Also, a fair number of functions have changed to be pub fn
. Was that necessary?
Yes, that's the general idea. I needed to make PYO3_CROSS_LIB_DIR optional to allow python3-dll-a to substitute its own library directory located somewhere inside OUT_DIR. In the process of doing that, I've realized it can also work for Unix-to-Unix cross compilation in many cases. It's not entirely viable yet though, because of Android as you've mentioned above and also projects embedding a Python interpreter on Unix need to link to a real libpython3*.so somehow. This can be solved for Windows and abi3, but not in the general case. This is a work in progress, and I need to add a clear error message for every currently accepted but broken configuration.
I've noticed that several PyO3 build scripts contained literal re-implementations of these functions, so I intended to unify them in later commits. This commit alone is getting way too big, perhaps I should further split it into the refactoring and the breaking change parts for easier review... Also the bug fix part needs to be split out. |
👍 makes sense, yes I think several commits (or even PRs) will be needed to get to the final goal for this one. These build scripts are quite fiddly, there's so many ways to distribute Python leading to lots of edge cases to handle! |
My current plan is to submit a new PR with It it OK to rebase and force push pull requests for this project, or do you prefer that I use merges and fixup commits, so that you can squash them yourself before the final merge? |
Rebase & force push is fine! Thanks 👍 |
05e7a12
to
7e39565
Compare
I'm resubmitting PR this as a set of smaller patches to get continuous feedback from the CI. It's still a work in progress, but feel free to review the commits I've added so far. I'm highly confident in these, so if changes are requested the sooner I learn about them the better. |
pyo3-build-config/src/impl_.rs
Outdated
self.os == "windows" | ||
} | ||
|
||
fn is_windows_mingw(&self) -> bool { |
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.
Why not is_windows_gnu
?
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.
That's the convention the existing code uses:
pyo3/pyo3-build-config/src/impl_.rs
Lines 209 to 211 in 9f60b67
print("calcsize_pointer", struct.calcsize("P")) | |
print("mingw", get_platform().startswith("mingw")) | |
"#; |
pyo3/pyo3-build-config/src/impl_.rs
Lines 1370 to 1380 in 9f60b67
version: PythonVersion, | |
implementation: PythonImplementation, | |
abi3: bool, | |
mingw: bool, | |
) -> String { | |
if abi3 && !implementation.is_pypy() { | |
WINDOWS_ABI3_LIB_NAME.to_owned() | |
} else if mingw { | |
// https://packages.msys2.org/base/mingw-w64-python | |
format!("python{}.{}", version.major, version.minor) | |
} else { |
I've just pushed version 2 of this PR, split into 5 smaller commits this time. Unresolved questions from the previous rounds of review (shortlist):
|
In my experience, build scripts tend to become choke points in parallel builds which is why I would be wary of adding more dependencies to build scripts. That said, |
More smaller PR are preferable IMHO. |
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.
Yes, I think this revision looks ok to me.
I had been wondering whether we would need to use target_lexicon
, it would definitely be worth having a go in a separate commit so we can see how much it helps 👍
Thanks!
I'll add this commit on top to evaluate the extent of the required changes, but I'd like to fold it in the first commit for the final revision to reduce useless code churn within the same PR. |
The issue with |
Right, yes I think that would make it a lot less lightweight than we were hoping. I guess you decided not to try using it as a result? Anything else to consider before merging this? |
I can still try to add it as an experiment. I haven't actually checked if it has any measurable impact on the build times.
Yes, updating user documentation and adding the changelog entry are still a TODO. |
I've added d787d2a on top of the current branch to evaluate the I think there's a demonstrable benefit from the code quality standpoint. The downsides:
In my opinion the build time cost is acceptable, and as for |
It was supposed to be used to replace the duplicated code in maturin, see PyO3/maturin#718 |
Can this code be adapted to the new |
I think it's ok.
I think it's fine to break that api since it was tailored for maturin anyway. |
Even if someone else using it is unlikely, I would still prefer not change I'm thinking to put out a 0.16.3 release in the next few days (just one last thing I'd like to add to it), and then I'd be happy to start merging breaking changes because I've got ideas anyway 😄 |
I can try to keep this function as is and try to create a somewhat correct implementation for it until it's deprecated/removed in v0.17. |
I've pushed the Here I'm trying to keep the existing If everyone is OK with moving on with |
Sounds good to me 👍 |
Rebased on top of #2253 |
Change the `CrossCompileConfig` structure definition and make the public `lib_dir` field optional to support more flexible cross-compilation configuration in the future. FIXME: This change breaks the public `pyo3-build-config` crate API. Update the sysconfigdata extraction functions to fall through when `lib_dir` field is not set. WIP: Add `unwrap()` stubs to the main cross compile switch.
Try to generalize `windows_hardcoded_cross_compile()` to all supported target platforms (when possible). Rename it to `default_cross_compile()` and add some unit tests. Rewrite `load_cross_compile_config()` to fall back to the default interpreter configuration when no other config information sources are available.
Rename `$OUT_DIR/pyo3-cross-compile-config.txt` to `$OUT_DIR/<triple>/pyo3-build-config.txt` to exclude the possibility of using stale build configuration data when the build target changes. Use the presence of the corresponding build configuration file in the `pyo3-build-config` build script output directory to detect whether we are cross compiling or not. This patch enables cross compilation without using any of `PYO3_CROSS_*` env variables in many cases.
Update Architecture.md to reflect the current cross compilation support state.
Rebased on main and reopened. |
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.
Thanks, looks good to me. Thanks all for reviewing on this; I didn't manage to find any time to look for a number of days.
Try to support most common extension module cross compilation targets
without requiring any of the
PYO3_CROSS_*
environment variables.This is a work in progress tangentially related to #2231
I'm creating this mostly to get some initial feedback from the
pyo3-build-config
maintainers.