Skip to content

Request: Cross-compile PyCryptodome for iOS (arm64) #907

@plia7

Description

@plia7

Hello,

I’m trying to run a Python script on iPhone using Python 3.9.9-1. I have pip3 installed, clang, and have placed the iPhoneOS.sdk for iOS 14.4.1.

When installing it with pip, the package manager downloads a precompiled binary built for macOS, not iOS. Although both platforms use the Mach-O format, iOS will not load binaries compiled for macOS, which is why Python reports that the module was found but “not built for platform iOS.” For the script to work, the native .so modules in pycryptodome must be compiled specifically for the iOS platform. Since PyPI generally does not provide iOS-compiled wheels for such packages, the library cannot run on the device unless someone builds the binaries for iOS (either directly on the device or through cross-compilation).

When I attempt to run my script, which depends on PyCryptodome, I get the following error:

iPhone: ~ mobile% python test2.py
Traceback (most recent call last):
  File "/private/var/mobile/test2.py", line 1, in <module>
    from g4f.client import Client
  ...
  File "/var/mobile/.local/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 315, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Cipher._raw_ecb': Not found '_raw_ecb.cpython-39-darwin.so',
Cannot load '_raw_ecb.abi3.so': dlopen(/private/var/mobile/.local/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so): no suitable image found. 
Did find: /private/var/mobile/.local/lib/python3.9/site-packages/Crypto/Cipher/_raw_ecb.abi3.so: mach-o, but not built for platform iOS

Essentially, the .so binaries included in PyCryptodome are compiled for macOS, not iOS, so Python cannot load them on the device.

Since the library relies on native compiled modules (C extensions), it cannot be used on iOS unless someone cross-compiles the .so modules for the iOS platform (arm64). Ideally, a single iOS binary should work across multiple iOS versions, so targeting a specific version (e.g., 14.4.1) is not strictly necessary, what matters is that it’s built for iOS and arm64 architecture.

Could the maintainers or the community provide a precompiled PyCryptodome binary for iOS, or guidance for cross-compiling it? This would enable Python scripts that depend on PyCryptodome to run natively on iOS.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions