FS#70258 - [python-pycryptodome] Somehow avoid running gcc at import time

Attached to Project: Community Packages
Opened by Mantas Mikulėnas (grawity) - Thursday, 01 April 2021, 19:25 GMT
Last edited by Toolybird (Toolybird) - Tuesday, 09 May 2023, 03:50 GMT
Task Type Feature Request
Category Packages
Status Closed
Assigned To Ike Devolder (BlackEagle)
Felix Yan (felixonmars)
Johannes Löthberg (demize)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

With Cryptodome 3.10, doing `import Crypto.Cipher.AES` will spawn gcc ~18 times *during import*, i.e. every time the program starts up. This takes ~500ms, so in my case importing Crypto takes several times longer than running the actual program that uses it.

(Apparently this was not the case in Cryptodome 3.9.)

According to #python, this is done by cffi. Is it possible to make it do the necessary things at package build time, instead of import time? (I mean, without uninstalling python-cffi, because I have other packages which need it.)
This task depends upon

Closed by  Toolybird (Toolybird)
Tuesday, 09 May 2023, 03:50 GMT
Reason for closing:  Fixed
Additional comments about closing:  python-pycryptodome 3.10.4-1
Comment by Eli Schwartz (eschwartz) - Thursday, 01 April 2021, 19:44 GMT
It's not "done by cffi" as it turns out. In Crypto.Util._raw_api

load_lib() tries to cffi.FFI().dlopen() the full path to a filename, and if it fails because the filename does not exist, it runs the compiler weirdly, does nothing with it, and raises OSError.

load_pycryptodome_raw_lib() tries to load several different possible versions of any given *.so filename, and in the process uses a try/except for load_lib() which succeeds after a couple different filenames.
Comment by Eli Schwartz (eschwartz) - Thursday, 01 April 2021, 19:52 GMT
Should apply to both pycryptodome and pycryptodomex, not sure of the solution.

The upstream import shim looks... nuts...

Loading...