Skip to content

Prototype support for PEP 739 (continued) #14657

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented May 28, 2025

This is a continuation of work from #13945, see #13945 (comment). For a start, just rebased it against fresh git head.

@mgorny mgorny force-pushed the pep-739-prototype branch 2 times, most recently from f02c282 to 6c6ad29 Compare June 10, 2025 19:40
@mgorny mgorny force-pushed the pep-739-prototype branch from 88fa2cc to e716a1f Compare June 24, 2025 13:12
@bruchar1 bruchar1 added the modules:python Issues specific to the python module label Jun 25, 2025
@mgorny mgorny force-pushed the pep-739-prototype branch 2 times, most recently from a587516 to 0559b4a Compare July 8, 2025 17:24
@mgorny mgorny marked this pull request as ready for review July 9, 2025 17:55
@mgorny mgorny requested a review from jpakkane as a code owner July 9, 2025 17:55
@mgorny
Copy link
Contributor Author

mgorny commented Jul 9, 2025

Okay, I think this is as far as I can go on my own.

Few final points:

  • I've disabled it on macOS, since — at least judging by the existing code — we need to hack around frameworks, and the relevant data is not available in build-details.json. I don't have a macOS system to work on this properly. I think it's good enough to focus on getting it right for the more general POSIX case first.
  • The remaining CI failures don't seem to be related to these changes.
  • I've been able to successfully cross-compile NumPy with these changes.

Copy link
Contributor

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see it's ready for testing!

You may want to rewrite history already, since it's required in Meson development to have self-contained orthogonal commits before merging.

A few initial comments; I'll try to find time to test this asap!

class PythonBuildConfig:
"""PEP 739 build-details.json config file."""

"""Schema version currently implemented."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be a regular code comment (# ) it looks like. Same comment for 2 lines lower.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it was meant as a docstring, but according to PEP 258, attribute docstrings go below the assignment, not above. While it was rejected, it seems that tools support this convention and I see it used e.g. in mesonbuild/cargo/manifest.py, so I'll just fix the location.

self.variables = python_holder.info['variables']
self.build_config = python_holder.build_config

if self.build_config:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I look at the multiple if self.build_config ... else I wondered if it isn't better to combined build_config and info into the same structure in a single place. I bet you considered it though and decided against doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I haven't given it much thought, but they certainly do trigger different code paths, and contain slightly different information. I don't think trying to combine them would make the code more readable.

@rgommers
Copy link
Contributor

rgommers commented Jul 9, 2025

I've been able to successfully cross-compile NumPy with these changes.

Do you happen to have a reusable recipe for this?

@rgommers
Copy link
Contributor

This seems to work as expected, here is a set of CI jobs that cross-compiles SciPy from x86-64 to aarch64 in the first job, and then uses an aarch64 runner in the second job to download the built wheel and run the test suite:

I think there was a script to generate the build-details.json file; couldn't find it so quickly so I hardcoded the paths for now. Overall this was pretty smooth though. I handwrote the json file by taking the example from PEP 739 and just modifying for the target interpreter, took only a minute or two to do that.

@mgorny
Copy link
Contributor Author

mgorny commented Jul 10, 2025

I've been able to successfully cross-compile NumPy with these changes.

Do you happen to have a reusable recipe for this?

Not really reusable, no. I've used Gentoo's crossdev to get the needed dependencies, i.e.:

crossdev aarch64-unknown-linux-gnu
aarch64-unknown-linux-gnu-emerge -1v openblas python:3.14

As a result, I've been able to test on a build-details.json from a real Python installation, which amounted to:

`build-details.json`
{
  "schema_version": "1.0",
  "base_prefix": "/usr",
  "base_interpreter": "/usr/bin/python3.14",
  "platform": "linux-aarch64",
  "language": {
    "version": "3.14",
    "version_info": {
      "major": 3,
      "minor": 14,
      "micro": 0,
      "releaselevel": "beta",
      "serial": 3
    }
  },
  "implementation": {
    "name": "cpython",
    "cache_tag": "cpython-314",
    "version": {
      "major": 3,
      "minor": 14,
      "micro": 0,
      "releaselevel": "beta",
      "serial": 3
    },
    "hexversion": 51249331,
    "_multiarch": "aarch64-linux-gnu"
  },
  "abi": {
    "flags": [],
    "extension_suffix": ".cpython-314-aarch64-linux-gnu.so",
    "stable_abi_suffix": ".abi3.so"
  },
  "suffixes": {
    "source": [
      ".py"
    ],
    "bytecode": [
      ".pyc"
    ],
    "extensions": [
      ".cpython-314-x86_64-linux-gnu.so",
      ".abi3.so",
      ".so"
    ]
  },
  "libpython": {
    "dynamic": "/usr/lib/libpython3.14.so",
    "dynamic_stableabi": "/usr/lib/libpython3.so",
    "link_extensions": false
  },
  "c_api": {
    "headers": "/usr/include/python3.14",
    "pkgconfig_path": "/usr/lib/pkgconfig"
  }
}

Created a cross file:

meson --cross-file
[binaries]
c = 'aarch64-unknown-linux-gnu-gcc'
cpp = 'aarch64-unknown-linux-gnu-g++'
pkg-config = 'aarch64-unknown-linux-gnu-pkg-config'

[properties]
sys_root = '/usr/aarch64-unknown-linux-gnu'
pkg_config_libdir = '/usr/aarch64-unknown-linux-gnu/usr/lib/pkgconfig'
needs_exe_wrapper = true
longdouble_format = 'IEEE_QUAD_LE'

[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

Merged this branch with #14773, copied mesonbuild/modules/features from NumPy and run:

./meson.py setup --python.build-config /usr/aarch64-unknown-linux-gnu/usr/lib/python3.14/build-details.json --cross-file ~/tmp/meson-cross.txt ../numpy/build ../numpy

@rgommers
Copy link
Contributor

I opened mesonbuild/meson-python#779 for the needed meson-python changes that go with this. With this PR and that one, I could remove all the hacks and cross-compile SciPy correctly.

@mgorny mgorny force-pushed the pep-739-prototype branch from a8bbbb1 to 9071816 Compare July 19, 2025 19:18
Signed-off-by: Filipe Laíns <lains@riseup.net>
Signed-off-by: Michał Górny <mgorny@quansight.com>
@mgorny mgorny force-pushed the pep-739-prototype branch from 9071816 to 1232ec1 Compare July 21, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules:python Issues specific to the python module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants