kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
759 stars 238 forks source link

`pyrebase4` needs `pycryptodome`, which doesn't have a recipe #701

Open nkehoe opened 2 years ago

nkehoe commented 2 years ago

Versions

Describe the bug I am trying to add pyrebase to my build to connect my firebase database.

To Reproduce python toolchain.py pip install pyrebase4

Expected behavior install pyrebase

Logs

[DEBUG   ]       building 'Crypto.Hash._MD2' extension
[DEBUG   ]       creating build/temp.macosx-12.3-arm64-3.9
[DEBUG   ]       creating build/temp.macosx-12.3-arm64-3.9/src
[DEBUG   ]       /bin/false -DPYCRYPTO_LITTLE_ENDIAN -DSYS_BITS=64 -DLTC_NO_ASM -Isrc/ -I/Users/noelkehoe/kivy-ios/dist/hostpython3/include/python3.9 -c src/MD2.c -o build/temp.macosx-12.3-arm64-3.9/src/MD2.o
[DEBUG   ]       error: command '/bin/false' failed: No such file or directory
[DEBUG   ]       [end of output]
[DEBUG   ]   
[DEBUG   ]   note: This error originates from a subprocess, and is likely not a problem with pip.
[DEBUG   ] error: legacy-install-failure
[DEBUG   ] 
[DEBUG   ] ? Encountered error while trying to install package.
[DEBUG   ] ??> pycryptodome
[DEBUG   ] 
[DEBUG   ] note: This is an issue with the package mentioned above, not pip.
[DEBUG   ] hint: See above for output from the failure.
[DEBUG   ] 
Exception in thread background thread for pid 99657:
Traceback (most recent call last):
  File "/Users/noelkehoe/opt/anaconda3/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/Users/noelkehoe/opt/anaconda3/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 1683, in wrap
    fn(*rgs, **kwargs)
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 2662, in background_thread
    handle_exit_code(exit_code)
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 2349, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/noelkehoe/kivy-ios/dist/hostpython3/bin/pip3 install --isolated --prefix /Users/noelkehoe/kivy-ios/dist/root/python3 pyrebase4

  STDOUT:
Collecting pyrebase4
  Using cached Pyrebase4-4.5.0-py3-none-any.whl (8.9 kB)
Requirement already satisfied: requests-toolbelt>=0.7.1 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (0.9.1)
Requirement already satisfied: requests>=2.19.1 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (2.27.1)
Requirement already satisfied: oauth2client>=4.1.2 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (4.1.3)
Requirement already satisfied: gcloud>=0.18.3 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (0.18.3)
Collecting python-jwt>=2.0.1
  Using cached python_jwt-3.3.2-py2.py3-none-any.whl (6.8 kB)
Collecting pycryptodome>=3.6.4
  Using cached pycryptodome-3.14.1.tar.gz (... (35985 more, please see e.stdout)

  STDERR:

Traceback (most recent call last):
  File "/Users/noelkehoe/kivy-ios/toolchain.py", line 3, in <module>
    main()
  File "/Users/noelkehoe/kivy-ios/kivy_ios/toolchain.py", line 1555, in main
    ToolchainCL()
  File "/Users/noelkehoe/kivy-ios/kivy_ios/toolchain.py", line 1299, in __init__
    getattr(self, args.command)()
  File "/Users/noelkehoe/kivy-ios/kivy_ios/toolchain.py", line 1514, in pip
    _pip(sys.argv[2:])
  File "/Users/noelkehoe/kivy-ios/kivy_ios/toolchain.py", line 1186, in _pip
    shprint(pip_cmd, *args, _env=pip_env)
  File "/Users/noelkehoe/kivy-ios/kivy_ios/toolchain.py", line 56, in shprint
    for line in cmd:
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 953, in next
    self.wait()
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 879, in wait
    self.handle_command_exit_code(exit_code)
  File "/Users/noelkehoe/venv/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/noelkehoe/kivy-ios/dist/hostpython3/bin/pip3 install --isolated --prefix /Users/noelkehoe/kivy-ios/dist/root/python3 pyrebase4

  STDOUT:
Collecting pyrebase4
  Using cached Pyrebase4-4.5.0-py3-none-any.whl (8.9 kB)
Requirement already satisfied: requests-toolbelt>=0.7.1 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (0.9.1)
Requirement already satisfied: requests>=2.19.1 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (2.27.1)
Requirement already satisfied: oauth2client>=4.1.2 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (4.1.3)
Requirement already satisfied: gcloud>=0.18.3 in ./dist/root/python3/lib/python3.9/site-packages (from pyrebase4) (0.18.3)
Collecting python-jwt>=2.0.1
  Using cached python_jwt-3.3.2-py2.py3-none-any.whl (6.8 kB)
Collecting pycryptodome>=3.6.4
  Using cached pycryptodome-3.14.1.tar.gz (... (35985 more, please see e.stdout)

  STDERR:

Screenshots

Additional context Add any other context about the problem here.

misl6 commented 2 years ago

Unfortunately pyrebase needs pycryptodome, which needs a recipe in order to build.

Writing a recipe for pycryptodome may be trivial and will need a lot of patching, as it dynamically loads shared libraries via load_pycryptodome_raw_lib.

mrtruongleo commented 1 year ago

Hi @misl6, any update on this issue?

pakal commented 10 months ago

If I understand correctly, kivy-ios "hacks" the production of .so/.pyd files (they are empty at the end), and generates .a files that can be compiled statically in Xcode, instead.

I don't know anything about this part, would the same hack be usable on pycryptodome?

Then the next part, I guess, would be to patch the cryptodome function below so that it opens "self" (the current process) instead of a separate .so/.pyd.

    def load_lib(name, cdecl):
        """Load a shared library and return a handle to it.

        @name,  either an absolute path or the name of a library
                in the system search path.

        @cdecl, the C function declarations.
        """

        if hasattr(ffi, "RTLD_DEEPBIND") and not os.getenv('PYCRYPTODOME_DISABLE_DEEPBIND'):
            lib = ffi.dlopen(name, ffi.RTLD_DEEPBIND)
        else:
            lib = ffi.dlopen(name)
        ffi.cdef(cdecl)
        return lib