Skip to content

inline python-for-build wrapper generation#1177

Open
jjhelmus wants to merge 1 commit into
mainfrom
jjh/inline_python-for-build
Open

inline python-for-build wrapper generation#1177
jjhelmus wants to merge 1 commit into
mainfrom
jjh/inline_python-for-build

Conversation

@jjhelmus

@jjhelmus jjhelmus commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Generate the python-for-build wrapper build-cpython.sh using a Makefile fragment to avoid patching CPython. This functionality is only used post-install. It is not needed during the build.

closes #959

Generate the python-for-build wrapper build-cpython.sh using a Makefile
gragment to avoid patching CPython.
@jjhelmus jjhelmus added the platform:linux Specific to the Linux platform label Jul 10, 2026
@zanieb

zanieb commented Jul 13, 2026

Copy link
Copy Markdown
Member

Why is this better?

@jjhelmus

Copy link
Copy Markdown
Contributor Author

The primary benefit of this change is to the patches which modify Makefile.pre.in while maintaining the same functionality. This patch has a small maintenance burden since it may need to be updated when upstream changes Makefile.pre.in.

Additionally, since this wrapper is unique to python-build-standalone there is no need to upstream it. Removing the patch make this clear (?). The wrapper is only used after CPython is built and installed, it is a post-build requirement when cross-compiling.

I would not consider this change critical. If the patch is more clear this should not be merged.

@zanieb

zanieb commented Jul 14, 2026

Copy link
Copy Markdown
Member

Perhaps we should back up a little, what is this for?

@jjhelmus

Copy link
Copy Markdown
Contributor Author

After building and installing CPython, an interpreter is needed to:

  • Install pip, and setuptools for Python 3.10/3.11.
  • Modify sysconfig.
  • Generate metadata for PYTHON.json.
  • Update shebang lines.

In a native build, the newly installed Python interpreter can be used for these tasks.

When cross-compiling, the new interpreter targets a different architecture and may not run on the build system (for example, a RISC-V interpreter on an x86-64 host). CPython handles this during the build using the PYTHON_FOR_BUILD Make variable, which invokes the host interpreter with the target environment, including sysconfig, platform tags, and ABI flags.

The previous patches, and now the inline Makefile snippet, create a python-for-build wrapper from the expanded PYTHON_FOR_BUILD value so the same environment can be used for the post-install tasks. Running the host interpreter directly would select incorrect paths, platform tags, ABI flags, and other target-specific configuration.

@zanieb

zanieb commented Jul 14, 2026

Copy link
Copy Markdown
Member

Why is this only useful to us and not other redistributors?

@jjhelmus

Copy link
Copy Markdown
Contributor Author

Why is this only useful to us and not other redistributors?

I was just writing this up 😄

There is also an argument for this wrapper to be upstreamed to CPython as other projects that do cross-builds and then run Python tooling against the the target install would benefit from this wrapper. That said, this is a narrow use-case which may not warrant upstream-support.

@jjhelmus

jjhelmus commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

This change is not tied to upstreaming the patch. The addition can be done even if the project no longer carries the patch but rather introduces the wrapper via a Makefile snippet.

@jjhelmus
jjhelmus requested a review from zanieb July 21, 2026 15:07

@zanieb zanieb 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 don't find the logic here very compelling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform:linux Specific to the Linux platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge logic of write-python-for-build.patch in build-cpython.sh

2 participants