Skip to content

ENH: implement support for build-details.json (PEP 739) (continued) - #829

Open
mgorny wants to merge 2 commits into
mesonbuild:mainfrom
mgorny:pep-739-cross
Open

ENH: implement support for build-details.json (PEP 739) (continued)#829
mgorny wants to merge 2 commits into
mesonbuild:mainfrom
mgorny:pep-739-cross

Conversation

@mgorny

@mgorny mgorny commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

This a continuation of #779. For a start, I just did a dumb rebase to rerun the tests.

@mgorny mgorny changed the title WIP: ENH: implement support for build-details.json (PEP 739) WIP: ENH: implement support for build-details.json (PEP 739) (continued) Jan 8, 2026
@rgommers rgommers added the enhancement New feature or request label Jun 28, 2026
@rgommers

Copy link
Copy Markdown
Contributor

I closed gh-779. Copying over the main comment from that PR discussion:

Good point. Yes, there isn't any reason that build-details.json cannot be used for a native build. So we should support that as well. That said, there isn't a benefit from the user passing in such a file explicitly; we can start reading it automatically for Python >=3.14, but I'm a bit hesitant to do that right away since it's so new. We can start doing that at any point in the future if it helps simplify our internal code, since it's a backwards-compatible change.

So for now in this PR we can distinguish three cases, with the user passing:

  1. Only a cross file (or multiple cross files)
  2. Only a build-details.json file
  3. Both a cross file and a build-details.json file

I focused on (3) first and have a TODO in here already to add (1); I should add (2) as well.

@dnicolodi dnicolodi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had a quick look at this. Found some possible improvements.

Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/__init__.py Outdated
return mesonpy._tags.Tag('py3', 'none', None)
return mesonpy._tags.Tag(None, self._stable_abi, None)
return mesonpy._tags.Tag('py3', 'none', None, self._build_details)
return mesonpy._tags.Tag(None, self._stable_abi, None, self._build_details)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a mesonpy._tags.Tag.from_build_details() API would work better. This would avoid to have to pass the build details object to a bunch of functions that do close to nothing when the Python interpreter description is available from build-details.json.

BTW: build-details.json is really a ugly name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this point. The JSON file does not provide a "ready" wheel tag, and we still need all of the "postprocessing" these functions do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have been looking at this a bit more, and I still don't like how we need to handle the case where build_details are available vs when we need to introspect the interpreter. One practical thing, is that it is not clear at a first glance that all the information used in deriving the tag really comes from build_details and not from the current platform. Mixing the two is obviously wrong.

Therefore, I propose to turn this around: have a mesonpy._tags.BuildDetails dictionary populated with introspection data when the required info does not come from a build-details.json file, pass that around, and remove all conditional handling.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Working on that. Also, uh, I just discovered a direct mesonpy._tags.get_abi_tag() in build_editable() that didn't account for build-details.json. I suppose it's not really critical since it only determines the build directory, but still.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just discovered a direct mesonpy._tags.get_abi_tag() in build_editable() that didn't account for build-details.json. I suppose it's not really critical since it only determines the build directory, but still.

cross-built editable wheels are not a thing: they wheel is installed in the same environment where the build is running without ever been exposed as a build artifact. Thus that does not need to be changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, done that. I've split the macosx/ios logic into two functions: one that performs tasks specific to getting current platform, and another that performs postprocessing using the data from BuildDetails (which may be the current platform or build-details.json). This also implies that passing BuildDetails to the functions is required.

I have left build_editable()'s build-dir use current system, given that implementing build-details.json support there would involve quite a bit of duplication, and it doesn't seem a major issue to solve anyway.

Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/__init__.py Outdated
@mgorny

mgorny commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I'm going to rebase it now, and make changes later when I find more time.

@mgorny
mgorny force-pushed the pep-739-cross branch 2 times, most recently from f22d77f to 7758d1c Compare July 3, 2026 15:36
@mgorny

mgorny commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased now.

Comment thread mesonpy/__init__.py Outdated
Comment thread tests/test_tags.py Outdated
Comment thread tests/test_tags.py Outdated
Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/__init__.py Outdated
@dnicolodi
dnicolodi marked this pull request as ready for review July 5, 2026 17:14
@dnicolodi dnicolodi changed the title WIP: ENH: implement support for build-details.json (PEP 739) (continued) ENH: implement support for build-details.json (PEP 739) (continued) Jul 5, 2026
@dnicolodi
dnicolodi force-pushed the pep-739-cross branch 3 times, most recently from 3e48d47 to bba067e Compare July 5, 2026 17:38
@dnicolodi

Copy link
Copy Markdown
Member

I tied up some loose ends. I think this is ready to be merged now. @rgommers, do you want to take a look?

It would be nice to have an integration test for this, but I don't know how hard it is to get a suitable environment setup on GitHub Actions.

@mgorny

mgorny commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Actually, I think it was in Draft because we wanted to make an integration test, but we were blocked on build-details.json problems in conda packages. I need to recheck if we resolved them all now.

@rgommers

rgommers commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Sounds great! Indeed, that integration test would be nice. IIRC conda-forge/python-feedstock#858 should have solved the one issue in conda-forge that was blocking for a cross-compile test.

@dnicolodi
dnicolodi force-pushed the pep-739-cross branch 3 times, most recently from 3fe11bd to 5ced90e Compare July 6, 2026 12:31
Comment thread mesonpy/_tags.py Outdated

@thesamesam thesamesam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks reasonable to me but I don't touch the meson-python side of things often at all.

@mgorny
mgorny force-pushed the pep-739-cross branch 3 times, most recently from 2b989fd to aee6205 Compare August 24, 2026 15:41
Comment thread mesonpy/__init__.py
# passing the with the `-Dpython.build_config=` option to `meson
# setup`. Extract the value passed to this option and use the details
# in the `build-details.json` file to compute the wheel tag.
self._build_details: mesonpy._tags.BuildDetails | None = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This annotation is now wrong: self._build_details cannot be None. Also, now that we use this attribute to always store information on the interpreter we can consider to name it in a less confusing way (now, at a first look it could seem that this attribute contains information about the build of the Meson project). Maybe self._info is not too bad of a name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is None temporarily. Unless you want me to undo the optimization and set the default value unconditionally, then override if python_build_config arg is provided.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't mind renaming it, though info sounds a bit unclear. Maybe tag_info? Should I also rename the classes and the argument elsewhere?

Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/__init__.py Outdated
Comment thread mesonpy/_tags.py
Comment on lines +51 to +66
# Python built with older macOS SDK on macOS 11, reports an
# nonexistent macOS 10.16 version instead of the real version.
#
# The packaging module introduced a workaround
# https://github.com/pypa/packaging/commit/67c4a2820c549070bbfc4bfbf5e2a250075048da
#
# This results in packaging versions up to 21.3 generating
# platform tags like "macosx_10_16_x86_64" and later versions
# generating "macosx_11_0_x86_64". Using the latter would be more
# correct but prevents the resulting wheel from being installed on
# systems using packaging 21.3 or earlier (pip 22.3 or earlier).
#
# Fortunately packaging versions carrying the workaround still
# accepts "macosx_10_16_x86_64" as a compatible platform tag. We
# can therefore ignore the issue and generate the slightly
# incorrect tag.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about the code this comments refers to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that this comment is saying that we don't need any code to handle that case. It was followed by empty line, then another comment. I've figured out it's better to move it where we get the platform, since it applied to what the system gives us.

Comment thread mesonpy/_tags.py Outdated
Comment thread mesonpy/_tags.py Outdated
Comment thread mesonpy/_tags.py Outdated
Comment thread mesonpy/_tags.py Outdated
Comment thread mesonpy/_tags.py Outdated
Comment thread mesonpy/_tags.py Outdated
pass

return f'ios_{version[0]}_{version[1]}_{multiarch}'
return f'{platform_os}_{version.replace('.', '_')}_{multiarch.replace('-', '_')}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, why join the version with . to replace it with _ here? Overall, I liked how this was written before much more, among other things because it was symmetric to what is done for macos.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've written it under the assumption that we should have the same input whether it's taken from the platform or from build-details.json. Since the latter uses dots, I've used the same here. Ofc, it practically doesn't matter, so I can go with underscores, but the conversion will still be necessary for build-details.json.

@mgorny

mgorny commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

When I'm done addressing feedback, I'm going to add more tests for the tag logic.

Signed-off-by: Michał Górny <mgorny@quansight.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants