Python3 snap: Can't load cryptoauthlib

I’m trying to test out some crypto hardware on a device, and I need to make it a snap to run on Core18. I’ve managed to get a snap to build and install, but it’s throwing errors when it runs.

Traceback (most recent call last):
  File "/snap/crypto-test/x1/bin/crypto_test.py", line 6, in <module>
    from cryptoauthlib import *
  File "/snap/crypto-test/x1/lib/python3.6/site-packages/cryptoauthlib/__init__.py", line 16, in <module>
    load_cryptoauthlib()
  File "/snap/crypto-test/x1/lib/python3.6/site-packages/cryptoauthlib/library.py", line 83, in load_cryptoauthlib
    _CRYPTO_LIB = ctypes.cdll.LoadLibrary(os.path.join(curr_path, "libcryptoauth.so"))
  File "/snap/crypto-test/x1/usr/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "/snap/crypto-test/x1/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /snap/crypto-test/x1/lib/python3.6/site-packages/cryptoauthlib/libcryptoauth.so: undefined symbol: hid_open

I’ve tried including a whole slew of stuff in the snap to try to solve this with no success. Here is my part from snapcraft.yaml

crypto-test:
    source: .
    plugin: python
    python-version: 'python3'
    python-packages:
        - cryptoauthlib
        - hidapi
        - setuptools
    stage-packages:
        - libusb-dev
        - libhidapi-dev
        - libusb-1.0-0

Here is my setup.py

setup(
    name="crypto-test",
    version="0.1",
    packages=['bin'],
    scripts=['bin/crypto_test.py'],
    install_requires=['cryptoauthlib', 'hidapi'],
)

I’m building on a RasPi 4 targeting an armhf device.

Has anyone tried to use cryptoauthlib in a snap before? How does one solve this issue? Best guess right now is that I’m missing some kind, variety, or flavor of a hid library.

you probably want to make the first two build-packages: instead of stage-packages:

I’ve tried them in both positions, to no avail, but yea I guess those probably should be in build :smile:

The website mentions some packages you don’t have here for building:

and there seems to be a caching issue if you did not build correctly initially, https://github.com/MicrochipTech/cryptoauthlib/issues/136 (try snapcraft clean crypto-test which essentially wipes the cache)

1 Like

Interesting. Guess I need to RTFM more. Trying it out now…

EDIT: No dice :c

What on earth am I missing? It’s gotta be some dumb hid library or something, right?