Skip to content

feat: Better support for cross-compilation #1050

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 5 commits into
base: main
Choose a base branch
from

Conversation

LecrisUT
Copy link
Collaborator

Mostly the cross-compilation works out-of-the-box with crossenv + CMAKE_TOOLCHAIN_FILE. There is only one adjustment needed for Python_ROOT_DIR to point to sys.base_exec_prefix, the rest is documentation of the change and adding support for CMAKE_TOOLCHAIN_FILE where needed.

I presume that under PEP720 the same workflow will be valid, primarily sys.base_exec_prefix would point to the target's implementation, otherwise the document should be clarified on what to expect. I have raised the issue for further clarification 1

Footnotes

  1. https://discuss.python.org/t/pep-720-cross-compiling-python-packages/29988/2

# ``wheel.py-api``. Each tag must be of the format
# {interpreter}-{abi}-{platform}. If not specified, these tags are automatically
# calculated.
wheel.tags = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like exposing this to the pyproject.toml. Maybe we should go ahead and add a way to specify an argument is only supported via the command line. I'd use that for D as a shortcut for cmake.define.

Edit: this might be useful for overrides, though. Maybe we should just mention that it should not be hard coded except in overrides or something like that.

Copy link
Collaborator Author

@LecrisUT LecrisUT May 8, 2025

Choose a reason for hiding this comment

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

I don't like exposing this to the pyproject.toml.

We could add a flag to the metadata.

I'd use that for D as a shortcut for cmake.define.

A bit confused on this. Still inside --config-settings you mean?

Edit: this might be useful for overrides, though.

We could have both and deny pyproject.toml without overrides specifically. I want a more restrictive check on the build.requires as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opened #1078 to handle those. Luckily there was fail as the first candidate for that feature.

CMake's guide on how to write the [toolchain file].

You can pass the toolchain file using the environment variable
`CMAKE_TOOLCHAIN_FILE`, or the `cmake.toolchain-file` pyproject option. You may
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
`CMAKE_TOOLCHAIN_FILE`, or the `cmake.toolchain-file` pyproject option. You may
`CMAKE_TOOLCHAIN_FILE`, or the `cmake.toolchain-file` config-settings option. You may

I'm not sure this is good to hard code? Though for this one (and the other), we could possibly allow it, but we probably shouldn't suggest it. It might be useful in overrides, though. Actually, maybe tags would be too.

LecrisUT added 3 commits May 14, 2025 10:07
`Python_ROOT_DIR` is used for the find hints for
- `Python_EXECUTABLE`: Unnecessary because we provide `Python_EXECUTABLE` as a cache variable and that has precedence
- `python-config`: should point to the target's variable. Generally this is a shell script which would be executable during cross-compilation (windows case unknown)
- `Python_LIBRARY`: should point to the target's library which would be on the

`crossenv` uses a fake environment so that `sys.base_*_prefix` variables point to the target's system. Presumably PEP720 would work the same.

Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
@LecrisUT LecrisUT force-pushed the feat/cross-compile branch from bc09cfe to dcb86bf Compare May 15, 2025 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants