Cross Compilation in Build Hook
Summary
What are the best practices for detecting the target architecture when cross-compiling a platform-specific wheel using a Hatch build script?
Background
I am building a wheel which includes a binary extension compiled using cffi. I have a custom build hook which performs the following steps:
- Detect the architecture, using
packaging'ssys_tags - Download the pre-compiled library for the target architecture
- Build the binary extension
I recently tried to enable support for Windows ARM builds; however, ran into issues when trying to build the wheels using cibuildwheel due to a mismatch between what sys_tags returns, and the actual target achitecture. I was wondering first whether it was an issue with cibuildwheel and asked the question over at
- pypa/cibuildwheel#1942.
Also from the cibuildwheel docs:
Cross-compilation on Windows relies on a supported build backend. Supported backends use an environment variable to specify their target platform (the one they are compiling native modules for, as opposed to the one they are running on), which is set in cibuildwheels/windows.py before building. Currently,
setuptools>=65.4.1andsetuptools_rustare the only supported backends.
It is unclear, at this stage, what should be changed. I can see a couple options:
cibuildwheelis updated to ensure compatibility withpackaging(or vice-versa),hatchexposes an API so that a build script can know what target is being built.
I do wonder whether you think (2) should be implemented regardless. Hatch evidently has some logic to determine the tags, but that is (afaik) hidden and not otherwise accessible.
https://hatch.pypa.io/latest/plugins/build-hook/reference/#hatchling.builders.hooks.plugin.interface.BuildHookInterface.target_name
It isn't obvious to me that target_name will give my the interpreter/ABI/platform triple 🤔.
If it does have all that information, it might be worth updating the docs and/or providing examples of values this target_name might take.
I'll take a look this afternoon though 👍
sorry that is correct, I skimmed and saw the word target which refers to something specific in Hatch-land, I will read this further tomorrow
I just did a really quick check, and I'm finding that target_name takes on the value 'wheel' which is not quite what I'm looking for :/
Appreciate you looking into this though!
Just following up on this ticket in case you identified anything useful?