Skip to content
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::get() broken inside our proc macro crates when cross-compiling #4579

Open
davidhewitt opened this issue Sep 26, 2024 · 0 comments
Labels

Comments

@davidhewitt
Copy link
Member

davidhewitt commented Sep 26, 2024

Related:

The current implementation of pyo3_build_config::get() relies on (in order):

  1. looking at DEP_PYTHON_PYO3_CONFIG environment variable (only set by cargo for build.rs files of crates which are direct dependents of pyo3-ffi)
  2. looking at TARGET and reading a cross-compile config from a corresponding subpath of pyo3-build-config's OUT_DIR
  3. use contents of PYO3_CONFIG_FILE, if set (inlined into pyo3-build-config as part of its build.rs)
  4. use the automatically located Python installation (inlined into pyo3-build-config as part of its build.rs)

In step 2, the cross-compile config is generated by pyo3-ffi is written to pyo3-build-config's OUT_DIR. Using pyo3-build-config's OUT_DIR was chosen because we wanted to share this resolved information across all downstream uses, and only pyo3-build-config is the common dependency for pyo3_build_config::get(). However, this has problems:

  • It breaks reproducible builds when doing distributed builds (root of the buck issue above)
  • It breaks when the OUT_DIR is a temporary sandbox; it's not really well specified that we should ever be abusing OUT_DIR in this way (root of the bazel issue above)

Really, all we need is a mechanism to generate a cross-compile configuration and re-use it across builds. At the moment we can't do this at the same time we inline options 3 and 4 because pyo3-build-config's build.rs doesn't know the final compilation target (pyo3-build-config is always built for the host target as a build dependency).

Unless we can think of a better mechanism to pass data from pyo3-ffi's build.rs to downstream uses in the proc macros and other crates, the only option I can think of is to add extra PYO3_CROSS_ environment variables (maybe PYO3_CROSS_TARGET) which can be used by pyo3-build-config to inline a complete config. maturin and setuptools-rust might at least be able to set these automatically.

Possibly there's an upstream feature request for cargo here which could solve the problem more cleanly in the future. But we need a solution for existing MSRV as well :(

Minor aside, Step 1 is also probably a redundant optimization because it's likely rarely hit and when present should resolve to whichever of 2, 3, or 4 was selected by pyo3-ffi's build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant