-
Notifications
You must be signed in to change notification settings - Fork 262
Add support for building Android wheels #2349
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
base: main
Are you sure you want to change the base?
Changes from all commits
3a3caec
578c181
c720392
e33235d
8e03e87
4428868
f3084f0
e715aa4
4234013
f2048b7
ec1a6c5
be664be
d56114b
13003df
71ba70d
e1ef58f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,10 @@ repos: | |
- id: mypy | ||
name: mypy 3.11 on cibuildwheel/ | ||
args: ["--python-version=3.11"] | ||
exclude: ^cibuildwheel/resources/_cross_venv.py$ # Requires Python 3.13 or later | ||
additional_dependencies: &mypy-dependencies | ||
- bracex | ||
- build | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the discussion in pyproject.toml. |
||
- dependency-groups>=1.2 | ||
- nox>=2025.2.9 | ||
- orjson | ||
|
@@ -47,7 +49,6 @@ repos: | |
- validate-pyproject | ||
- id: mypy | ||
name: mypy 3.13 | ||
exclude: ^cibuildwheel/resources/.*py$ | ||
args: ["--python-version=3.13"] | ||
additional_dependencies: *mypy-dependencies | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,41 @@ | |
"macos": "macOS", | ||
"windows": "Windows", | ||
"pyodide": "Pyodide", | ||
"android": "Android", | ||
"ios": "iOS", | ||
} | ||
|
||
ARCH_SYNONYMS: Final[list[dict[PlatformName, str | None]]] = [ | ||
{"linux": "x86_64", "macos": "x86_64", "windows": "AMD64"}, | ||
{"linux": "x86_64", "macos": "x86_64", "windows": "AMD64", "android": "x86_64"}, | ||
{"linux": "i686", "macos": None, "windows": "x86"}, | ||
{"linux": "aarch64", "macos": "arm64", "windows": "ARM64"}, | ||
{"linux": "aarch64", "macos": "arm64", "windows": "ARM64", "android": "arm64_v8a"}, | ||
] | ||
|
||
|
||
def arch_synonym(arch: str, from_platform: PlatformName, to_platform: PlatformName) -> str | None: | ||
for arch_synonym in ARCH_SYNONYMS: | ||
if arch == arch_synonym.get(from_platform): | ||
return arch_synonym.get(to_platform, arch) | ||
|
||
return arch | ||
|
||
|
||
def native_platform() -> PlatformName: | ||
if sys.platform.startswith("linux"): | ||
return "linux" | ||
elif sys.platform == "darwin": | ||
return "macos" | ||
elif sys.platform == "win32": | ||
return "windows" | ||
else: | ||
msg = ( | ||
'Unable to detect platform from "sys.platform". cibuildwheel doesn\'t ' | ||
"support building wheels for this platform. You might be able to build for a different " | ||
"platform using the --platform argument. Check --help output for more information." | ||
) | ||
raise errors.ConfigurationError(msg) | ||
|
||
|
||
Comment on lines
+39
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we move this to |
||
def _check_aarch32_el0() -> bool: | ||
"""Check if running armv7l natively on aarch64 is supported""" | ||
if not sys.platform.startswith("linux"): | ||
|
@@ -42,7 +67,7 @@ | |
|
||
@typing.final | ||
class Architecture(StrEnum): | ||
# mac/linux archs | ||
# mac/linux/android archs | ||
x86_64 = auto() | ||
|
||
# linux archs | ||
|
@@ -65,6 +90,9 @@ | |
# WebAssembly | ||
wasm32 = auto() | ||
|
||
# android archs | ||
arm64_v8a = auto() | ||
|
||
# iOS "multiarch" architectures that include both | ||
# the CPU architecture and the ABI. | ||
arm64_iphoneos = auto() | ||
|
@@ -123,15 +151,12 @@ | |
# we might need to rename the native arch to the machine we're running | ||
# on, as the same arch can have different names on different platforms | ||
if host_platform != platform: | ||
for arch_synonym in ARCH_SYNONYMS: | ||
if native_machine == arch_synonym.get(host_platform): | ||
synonym = arch_synonym[platform] | ||
|
||
if synonym is None: | ||
# can't build anything on this platform | ||
return None | ||
synonym = arch_synonym(native_machine, host_platform, platform) | ||
if synonym is None: | ||
# can't build anything on this platform | ||
return None | ||
|
||
native_architecture = Architecture(synonym) | ||
native_architecture = Architecture(synonym) | ||
|
||
return native_architecture | ||
|
||
|
@@ -173,6 +198,7 @@ | |
"macos": {Architecture.x86_64, Architecture.arm64, Architecture.universal2}, | ||
"windows": {Architecture.x86, Architecture.AMD64, Architecture.ARM64}, | ||
"pyodide": {Architecture.wasm32}, | ||
"android": {Architecture.x86_64, Architecture.arm64_v8a}, | ||
"ios": { | ||
Architecture.x86_64_iphonesimulator, | ||
Architecture.arm64_iphonesimulator, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -58,6 +58,22 @@ def _split_config_settings(config_settings: str) -> list[str]: | |||||
return [f"-C{setting}" for setting in config_settings_list] | ||||||
|
||||||
|
||||||
# Based on build.__main__.main. | ||||||
def parse_config_settings(config_settings_str: str) -> dict[str, str | list[str]]: | ||||||
config_settings: dict[str, str | list[str]] = {} | ||||||
for arg in shlex.split(config_settings_str): | ||||||
setting, _, value = arg.partition("=") | ||||||
existing_value = config_settings.get(setting) | ||||||
if existing_value is None: | ||||||
config_settings[setting] = value | ||||||
elif isinstance(existing_value, str): | ||||||
config_settings[setting] = [existing_value] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks to me that
Suggested change
|
||||||
else: | ||||||
existing_value.append(value) | ||||||
|
||||||
return config_settings | ||||||
|
||||||
|
||||||
def get_build_frontend_extra_flags( | ||||||
build_frontend: BuildFrontendConfig, verbosity_level: int, config_settings: str | ||||||
) -> list[str]: | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this because
platform.android_ver
isn't defined, so it raises type errors? If so -# type: ignore[attr-defined]
on the single affected line is the pattern I've seen used elsewhere (including packaging and meson-python); that way we don't lost type checking on the whole file because of a single 3.13 feature.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, but when I tried to implement it there were complications. There are two mypy checks, one on 3.11 and one on 3.13. If I add the
ignore[attr-defined]
, then it passes on 3.11 but fails on 3.13 with the error "Unused "type: ignore" comment".I can make it pass both versions with
# type: ignore[attr-defined, unused-ignore]
, but that's a lot of clutter, which has to be repeated on 3 affected lines. And on top of that there would also need to be a human-readable comment explaining why it's necessary and when it can be removed.Given that this file will never be run on anything older than Python 3.13, the 3.11 type check doesn't actually add anything. So I think excluding it in the pre-commit-config is a simpler solution, and is far more likely to be cleaned up when 3.13 becomes cibuildwheel's minimum version.