trezor / cython-hidapi

:snake: Python wrapper for the HIDAPI
Other
285 stars 110 forks source link

0.11.0.post3: issue with pep517 build #133

Closed kloczek closed 11 months ago

kloczek commented 2 years ago

Trying to build cython-hidapi using pep517 build procedure I found that it is not possible to pas corretly --with-system-hidapi param to the build execution. I've been trying to use exactly tehe same way odf passing params to the build which is working with zstd https://github.com/pypa/build/issues/417

+ /usr/bin/python3 -sBm build -w -C=--with-system-hidapi
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (Cython, wheel)
* Building wheel...
running bdist_wheel
running build
running build_ext
/tmp/build-env-gkeommwd/lib64/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/tkloczko/rpmbuild/BUILD/cython-hidapi-0.11.0.post3/hid.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
/tmp/build-env-gkeommwd/lib64/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/tkloczko/rpmbuild/BUILD/cython-hidapi-0.11.0.post3/hidraw.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/hidapi
creating build/temp.linux-x86_64-3.8/hidapi/libusb
/usr/bin/gcc -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/tmp/build-env-gkeommwd/include -I/usr/include/python3.8 -c hid.c -o build/temp.linux-x86_64-3.8/hid.o
hid.c:680:10: fatal error: hidapi.h: No such file or directory
  680 | #include "hidapi.h"
      |          ^~~~~~~~~~
compilation terminated.

I have installed necessary hidapi devel resources

[tkloczko@ss-desktop SPECS]$ rpm -ql hidapi-devel | grep include
/usr/include/hidapi
/usr/include/hidapi/hidapi.h
/usr/include/hidapi/hidapi_libusb.h
kloczek commented 2 years ago

ping .. FYI in the same build env as long as classic python setup.py build --with-system-hidapi is used everything is fine so definitelly looks like some work to make module pep517 ready needs to be done.

prusnak commented 2 years ago

I appreciate any help with this issue, ideally in the form of a pull request.

mcuee commented 1 year ago

I can reproduce this issue as well under macOS (Mac Mini M1 2020, macOS Ventura 13.3.1, Homebrew).

mcuee@mcuees-Mac-mini cython-hidapi % python3 -sBm build -w -C=--with-system-hidapi
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting build dependencies for wheel...
* Installing packages in isolated environment... (Cython, wheel)
* Building wheel...
running bdist_wheel
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
creating build
creating build/temp.macosx-13-arm64-cpython-311
creating build/temp.macosx-13-arm64-cpython-311/hidapi
creating build/temp.macosx-13-arm64-cpython-311/hidapi/mac
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -framework IOKit -framework CoreFoundation -framework AppKit -Ihidapi/hidapi -I/private/var/folders/zf/457r6vn50knfpnjgy1156llr0000gn/T/build-env-xqtz30dl/include -I/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c hid.c -o build/temp.macosx-13-arm64-cpython-311/hid.o
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework AppKit: 'linker' input unused [-Wunused-command-line-argument]
hid.c:745:10: fatal error: 'hidapi.h' file not found
#include "hidapi.h"
         ^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel
mcuee commented 1 year ago

Hmm, just plain build will fail as well. Maybe my issue is more related to #55.

The problem is that for homebrew under macOS Apple Silicon, the location should be detected using pkg-config and not hard-coded.

(py310venv) mcuee@mcuees-Mac-mini cython-hidapi % pkg-config --cflags hidapi
-I/opt/homebrew/Cellar/hidapi/0.13.1/include/hidapi
(py310venv) mcuee@mcuees-Mac-mini cython-hidapi % pkg-config --libs hidapi  
-L/opt/homebrew/Cellar/hidapi/0.13.1/lib -lhidapi

(py310venv) mcuee@mcuees-Mac-mini cython-hidapi % python setup.py install --with-system-hidapi
/Users/mcuee/build/python/py310venv/lib/python3.10/site-packages/setuptools/__init__.py:85: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`.
  dist.fetch_build_eggs(dist.setup_requires)
running install
/Users/mcuee/build/python/py310venv/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/Users/mcuee/build/python/py310venv/lib/python3.10/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
writing hidapi.egg-info/PKG-INFO
writing dependency_links to hidapi.egg-info/dependency_links.txt
writing requirements to hidapi.egg-info/requires.txt
writing top-level names to hidapi.egg-info/top_level.txt
reading manifest file 'hidapi.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'hidapi/hidapi/*.h'
warning: no files found matching 'hidapi/libusb/*.c'
warning: no files found matching 'hidapi/libusb/*.h'
warning: no files found matching 'hidapi/linux/*.c'
warning: no files found matching 'hidapi/linux/*.h'
warning: no files found matching 'hidapi/mac/*.c'
warning: no files found matching 'hidapi/mac/*.h'
warning: no files found matching 'hidapi/windows/*.c'
warning: no files found matching 'hidapi/windows/*.h'
adding license file 'LICENSE-bsd.txt'
adding license file 'LICENSE-gpl3.txt'
adding license file 'LICENSE-orig.txt'
adding license file 'LICENSE.txt'
writing manifest file 'hidapi.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-13-arm64/egg
running install_lib
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
creating build
creating build/temp.macosx-13-arm64-cpython-310
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -framework IOKit -framework CoreFoundation -framework AppKit -I/usr/include/hidapi -I/Users/mcuee/build/python/py310venv/include -I/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c hid.c -o build/temp.macosx-13-arm64-cpython-310/hid.o
clang: warning: -framework IOKit: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework CoreFoundation: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -framework AppKit: 'linker' input unused [-Wunused-command-line-argument]
hid.c:745:10: fatal error: 'hidapi.h' file not found
#include "hidapi.h"
         ^~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
mcuee commented 1 year ago

But I can reproduce the issue under Ubuntu Linux.

mcuee@UbuntuSwift3:~/build/hid/cython-hidapi$ pkg-config --cflags hidapi-hidraw
-I/usr/local/include/hidapi
mcuee@UbuntuSwift3:~/build/hid/cython-hidapi$ pkg-config --libs hidapi-hidraw
-L/usr/local/lib -lhidapi-hidraw

mcuee@UbuntuSwift3:~/build/hid/cython-hidapi$ python3 -sBm build -w -C=--with-system-hidapi
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting build dependencies for wheel...
* Installing packages in isolated environment... (Cython, wheel)
* Building wheel...
running bdist_wheel
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
skipping 'hidraw.c' Cython extension (up-to-date)
building 'hid' extension
creating build
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/hidapi
creating build/temp.linux-x86_64-cpython-38/hidapi/libusb
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Ihidapi/hidapi -I/usr/include/libusb-1.0 -I/tmp/build-env-2vbxnhwd/include -I/usr/include/python3.8 -c hid.c -o build/temp.linux-x86_64-cpython-38/hid.o
hid.c:745:10: fatal error: hidapi.h: No such file or directory
  745 | #include "hidapi.h"
      |          ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1

ERROR Backend subprocess exited when trying to invoke build_wheel
mcuee@UbuntuSwift3:~/build/hid/cython-hidapi$ python3 setup.py build --with-system-hidapi
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
skipping 'hidraw.c' Cython extension (up-to-date)
building 'hid' extension
creating build/temp.linux-x86_64-3.8
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/hidapi -I/usr/include/libusb-1.0 -I/usr/include/python3.8 -c hid.c -o build/temp.linux-x86_64-3.8/hid.o
creating build/lib.linux-x86_64-3.8
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/hid.o -lusb-1.0 -ludev -lrt -lhidapi-libusb -o build/lib.linux-x86_64-3.8/hid.cpython-38-x86_64-linux-gnu.so
building 'hidraw' extension
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/hidapi -I/usr/include/python3.8 -c hidraw.c -o build/temp.linux-x86_64-3.8/hidraw.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/hidraw.o -ludev -lrt -lhidapi-hidraw -o build/lib.linux-x86_64-3.8/hidraw.cpython-38-x86_64-linux-gnu.so
mcuee commented 1 year ago

No issues under Windows with Python,org Python 3.11, Tested under a Python 3.11 virtual env,

(py311x64venv) PS C:\work\libusb\cython-hidapi> python -sBm build -w -C=--with-system-hidapi
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting build dependencies for wheel...
* Installing packages in isolated environment... (Cython, wheel)
* Building wheel...
running bdist_wheel
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
creating build
creating build\temp.win-amd64-cpython-311
creating build\temp.win-amd64-cpython-311\Release
creating build\temp.win-amd64-cpython-311\Release\hidapi
creating build\temp.win-amd64-cpython-311\Release\hidapi\windows
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ihidapi\hidapi -IC:\Users\xiaof\AppData\Local\Temp\build-env-8w_00rtc\include -IC:\Users\xiaof\AppData\Local\Programs\Python\Python311\include -IC:\Users\xiaof\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tchid.c /Fobuild\temp.win-amd64-cpython-311\Release\hid.obj
hid.c
hid.c(1834): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
hid.c(2748): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -Ihidapi\hidapi -IC:\Users\xiaof\AppData\Local\Temp\build-env-8w_00rtc\include -IC:\Users\xiaof\AppData\Local\Programs\Python\Python311\include -IC:\Users\xiaof\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tchidapi\windows\hid.c /Fobuild\temp.win-amd64-cpython-311\Release\hidapi\windows\hid.obj
hid.c
creating C:\work\libusb\cython-hidapi\build\lib.win-amd64-cpython-311
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\xiaof\AppData\Local\Temp\build-env-8w_00rtc\libs /LIBPATH:C:\Users\xiaof\AppData\Local\Programs\Python\Python311\libs /LIBPATH:C:\Users\xiaof\AppData\Local\Programs\Python\Python311 /LIBPATH:C:\Users\xiaof\AppData\Local\Temp\build-env-8w_00rtc\PCbuild\amd64 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x64" setupapi.lib /EXPORT:PyInit_hid build\temp.win-amd64-cpython-311\Release\hid.obj build\temp.win-amd64-cpython-311\Release\hidapi\windows\hid.obj /OUT:build\lib.win-amd64-cpython-311\hid.cp311-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-311\Release\hid.cp311-win_amd64.lib
   Creating library build\temp.win-amd64-cpython-311\Release\hid.cp311-win_amd64.lib and object build\temp.win-amd64-cpython-311\Release\hid.cp311-win_amd64.exp
Generating code
Finished generating code
installing to build\bdist.win-amd64\wheel
running install
running install_lib
creating build\bdist.win-amd64
creating build\bdist.win-amd64\wheel
copying build\lib.win-amd64-cpython-311\hid.cp311-win_amd64.pyd -> build\bdist.win-amd64\wheel\.
running install_egg_info
running egg_info
creating hidapi.egg-info
writing hidapi.egg-info\PKG-INFO
writing dependency_links to hidapi.egg-info\dependency_links.txt
writing requirements to hidapi.egg-info\requires.txt
writing top-level names to hidapi.egg-info\top_level.txt
writing manifest file 'hidapi.egg-info\SOURCES.txt'
reading manifest file 'hidapi.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'hidapi\linux\*.h'
adding license file 'LICENSE-bsd.txt'
adding license file 'LICENSE-gpl3.txt'
adding license file 'LICENSE-orig.txt'
adding license file 'LICENSE.txt'
writing manifest file 'hidapi.egg-info\SOURCES.txt'
Copying hidapi.egg-info to build\bdist.win-amd64\wheel\.\hidapi-0.13.1-py3.11.egg-info
running install_scripts
C:\Users\xiaof\AppData\Local\Temp\build-env-8w_00rtc\Lib\site-packages\wheel\bdist_wheel.py:100: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
  if get_flag("Py_DEBUG", hasattr(sys, "gettotalrefcount"), warn=(impl == "cp")):
creating build\bdist.win-amd64\wheel\hidapi-0.13.1.dist-info\WHEEL
creating 'C:\work\libusb\cython-hidapi\dist\.tmp-_pmab4wb\hidapi-0.13.1-cp311-cp311-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'hid.cp311-win_amd64.pyd'
adding 'hidapi-0.13.1.dist-info/LICENSE-bsd.txt'
adding 'hidapi-0.13.1.dist-info/LICENSE-gpl3.txt'
adding 'hidapi-0.13.1.dist-info/LICENSE-orig.txt'
adding 'hidapi-0.13.1.dist-info/LICENSE.txt'
adding 'hidapi-0.13.1.dist-info/METADATA'
adding 'hidapi-0.13.1.dist-info/WHEEL'
adding 'hidapi-0.13.1.dist-info/top_level.txt'
adding 'hidapi-0.13.1.dist-info/RECORD'
removing build\bdist.win-amd64\wheel
Successfully built hidapi-0.13.1-cp311-cp311-win_amd64.whl
mcuee commented 1 year ago

I tend to believe the issue is partially because of #55 but there may be more issues than #55.

Build log under MSYS2 MinGW64 Python, under Windows 11.

1) pep517 build as per the above failed. 2) plain python setup.py build --with-system-hidapi also failed 3) plain python setup.py build is fine

$ pkg-config --cflags hidapi
-IC:/msys64/mingw64/include/hidapi

$ pkg-config --libs hidapi
-lhidapi

$ python -sBm build -w -C=--with-system-hidapi
* Creating virtualenv isolated environment...
* Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
* Getting build dependencies for wheel...
* Installing packages in isolated environment... (Cython, wheel)
* Building wheel...
running bdist_wheel
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')

ERROR Backend subprocess exited when trying to invoke build_wheel

$ python setup.py build --with-system-hidapi
C:/msys64/mingw64/lib/python3.10/site-packages/setuptools/__init__.py:85: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`.
  dist.fetch_build_eggs(dist.setup_requires)
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
creating build
creating build/temp.mingw_x86_64-3.10
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -I/usr/include/hidapi -IC:/msys64/mingw64/include/python3.10 -c hid.c -o build/temp.mingw_x86_64-3.10/hid.o
hid.c:745:10: fatal error: hidapi.h: No such file or directory
  745 | #include "hidapi.h"
      |          ^~~~~~~~~~
compilation terminated.
error: command 'C:\\msys64\\mingw64\\bin/gcc.exe' failed with exit code 1

$ python setup.py build
C:/msys64/mingw64/lib/python3.10/site-packages/setuptools/__init__.py:85: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated. Requirements should be satisfied by a PEP 517 installer. If you are using pip, you can try `pip install --use-pep517`.
  dist.fetch_build_eggs(dist.setup_requires)
running build
running build_ext
skipping 'hid.c' Cython extension (up-to-date)
building 'hid' extension
creating build/temp.mingw_x86_64-3.10/hidapi
creating build/temp.mingw_x86_64-3.10/hidapi/windows
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -Ihidapi/hidapi -IC:/msys64/mingw64/include/python3.10 -c hid.c -o build/temp.mingw_x86_64-3.10/hid.o
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -Ihidapi/hidapi -IC:/msys64/mingw64/include/python3.10 -c hidapi/windows/hid.c -o build/temp.mingw_x86_64-3.10/hidapi/windows/hid.o
In function 'register_string_error_to_buffer',
    inlined from 'register_string_error' at hidapi/windows/hid.c:303:2,
    inlined from 'hid_open_path' at hidapi/windows/hid.c:827:3:
hidapi/windows/hid.c:288:9: warning: array subscript 0 is outside array bounds of 'wchar_t *[0]' {aka 'short unsigned int *[]'} [-Warray-bounds]
  288 |         free(*error_buffer);
      |         ^~~~~~~~~~~~~~~~~~~
hidapi/windows/hid.c:289:23: warning: array subscript 0 is outside array bounds of 'wchar_t *[0]' {aka 'short unsigned int *[]'} [-Warray-bounds]
  289 |         *error_buffer = NULL;
      |                       ^
In function 'register_string_error_to_buffer',
    inlined from 'register_string_error_to_buffer' at hidapi/windows/hid.c:286:13,
    inlined from 'register_string_error' at hidapi/windows/hid.c:303:2,
    inlined from 'hid_open_path' at hidapi/windows/hid.c:827:3:
hidapi/windows/hid.c:292:31: warning: array subscript 0 is outside array bounds of 'wchar_t *[0]' {aka 'short unsigned int *[]'} [-Warray-bounds]
  292 |                 *error_buffer = _wcsdup(string_error);
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
writing build/temp.mingw_x86_64-3.10/hid.cp310-mingw_x86_64.def
creating build/lib.mingw_x86_64-3.10
gcc -shared -Wl,--enable-auto-image-base -pipe -pipe -s build/temp.mingw_x86_64-3.10/hid.o build/temp.mingw_x86_64-3.10/hidapi/windows/hid.o build/temp.mingw_x86_64-3.10/hid.cp310-mingw_x86_64.def -LC:/msys64/mingw64/lib/python3.10/config-3.10 -LC:/msys64/mingw64/lib -lsetupapi -lpython3.10 -lm -lversion -lshlwapi -o build/lib.mingw_x86_64-3.10/hid.cp310-mingw_x86_64.pyd
daemonspudguy commented 1 year ago

Wait this issue has been known about for a year and still hasn't been addressed?

desmphil commented 11 months ago

Same issue here with Debian 12 BookWorm Python3 3.11.2 Any fixes?

prusnak commented 11 months ago

Wait this issue has been known about for a year and still hasn't been addressed?

Are you paying for this or what makes you so entitled?

There are hundreds thousands users of this library, yet all the work is done for free by a single individual who doesn't even use it.

image

If you see something you don't like, spend some time on it and fix it. Welcome to open source!

prusnak commented 11 months ago

Should be fixed via https://github.com/trezor/cython-hidapi/pull/162 by @Youw 🎉

kloczek commented 11 months ago

Thank you. Just tested and looks like it works

+ /usr/bin/python3 -sBm build -w --no-isolation -C=--build-option=--with-libusb -C=--build-option=--with-system-hidapi
* Getting build dependencies for wheel...
Compiling hid.pyx because it changed.
Compiling hidraw.pyx because it changed.
[1/2] Cythonizing hid.pyx
[2/2] Cythonizing hidraw.pyx
running egg_info
creating hidapi.egg-info
writing hidapi.egg-info/PKG-INFO
writing dependency_links to hidapi.egg-info/dependency_links.txt
writing requirements to hidapi.egg-info/requires.txt
writing top-level names to hidapi.egg-info/top_level.txt
writing manifest file 'hidapi.egg-info/SOURCES.txt'
reading manifest file 'hidapi.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'hidapi/hidapi/*.h'
warning: no files found matching 'hidapi/libusb/*.c'
warning: no files found matching 'hidapi/libusb/*.h'
warning: no files found matching 'hidapi/linux/*.c'
warning: no files found matching 'hidapi/linux/*.h'
warning: no files found matching 'hidapi/mac/*.c'
warning: no files found matching 'hidapi/mac/*.h'
warning: no files found matching 'hidapi/windows/*.c'
warning: no files found matching 'hidapi/windows/*.h'
adding license file 'LICENSE-bsd.txt'
adding license file 'LICENSE-gpl3.txt'
adding license file 'LICENSE-orig.txt'
adding license file 'LICENSE.txt'
writing manifest file 'hidapi.egg-info/SOURCES.txt'
* Building wheel...
running bdist_wheel
running build
running build_ext
building 'hid' extension
creating build
creating build/temp.linux-x86_64-cpython-38
/usr/bin/gcc -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fPIC -I/usr/include/python3.8 -c hid.c -o build/temp.linux-x86_64-cpython-38/hid.o -I/usr/include/hidapi
creating build/lib.linux-x86_64-cpython-38
/usr/bin/gcc -shared -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none build/temp.linux-x86_64-cpython-38/hid.o -L/usr/lib64 -o build/lib.linux-x86_64-cpython-38/hid.cpython-38-x86_64-linux-gnu.so -lhidapi-libusb
building 'hidraw' extension
/usr/bin/gcc -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -D_GNU_SOURCE -fPIC -fwrapv -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -D_GNU_SOURCE -fPIC -fwrapv -ffat-lto-objects -fno-semantic-interposition -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fPIC -I/usr/include/python3.8 -c hidraw.c -o build/temp.linux-x86_64-cpython-38/hidraw.o -I/usr/include/hidapi
/usr/bin/gcc -shared -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none build/temp.linux-x86_64-cpython-38/hidraw.o -L/usr/lib64 -o build/lib.linux-x86_64-cpython-38/hidraw.cpython-38-x86_64-linux-gnu.so -lhidapi-hidraw
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/wheel
copying build/lib.linux-x86_64-cpython-38/hid.cpython-38-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/wheel
copying build/lib.linux-x86_64-cpython-38/hidraw.cpython-38-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/wheel
running install_egg_info
running egg_info
writing hidapi.egg-info/PKG-INFO
writing dependency_links to hidapi.egg-info/dependency_links.txt
writing requirements to hidapi.egg-info/requires.txt
writing top-level names to hidapi.egg-info/top_level.txt
reading manifest file 'hidapi.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'hidapi/hidapi/*.h'
warning: no files found matching 'hidapi/libusb/*.c'
warning: no files found matching 'hidapi/libusb/*.h'
warning: no files found matching 'hidapi/linux/*.c'
warning: no files found matching 'hidapi/linux/*.h'
warning: no files found matching 'hidapi/mac/*.c'
warning: no files found matching 'hidapi/mac/*.h'
warning: no files found matching 'hidapi/windows/*.c'
warning: no files found matching 'hidapi/windows/*.h'
adding license file 'LICENSE-bsd.txt'
adding license file 'LICENSE-gpl3.txt'
adding license file 'LICENSE-orig.txt'
adding license file 'LICENSE.txt'
writing manifest file 'hidapi.egg-info/SOURCES.txt'
Copying hidapi.egg-info to build/bdist.linux-x86_64/wheel/hidapi-0.14.0-py3.8.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/hidapi-0.14.0.dist-info/WHEEL
creating '/home/tkloczko/rpmbuild/BUILD/cython-hidapi-0.14.0/dist/.tmp-wgir8poa/hidapi-0.14.0-cp38-cp38-linux_x86_64.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
adding 'hid.cpython-38-x86_64-linux-gnu.so'
adding 'hidraw.cpython-38-x86_64-linux-gnu.so'
adding 'hidapi-0.14.0.dist-info/LICENSE-bsd.txt'
adding 'hidapi-0.14.0.dist-info/LICENSE-gpl3.txt'
adding 'hidapi-0.14.0.dist-info/LICENSE-orig.txt'
adding 'hidapi-0.14.0.dist-info/LICENSE.txt'
adding 'hidapi-0.14.0.dist-info/METADATA'
adding 'hidapi-0.14.0.dist-info/WHEEL'
adding 'hidapi-0.14.0.dist-info/top_level.txt'
adding 'hidapi-0.14.0.dist-info/RECORD'
removing build/bdist.linux-x86_64/wheel
Successfully built hidapi-0.14.0-cp38-cp38-linux_x86_64.whl

Other small thing ..

[tkloczko@pers-jacek cython-hidapi-0.14.0]$ grep -r setup\\.py
README.rst:    $ python setup.py build
README.rst:    $ python setup.py build --with-libusb
README.rst:    $ python setup.py build
README.rst:    $ sudo python setup.py install
hidapi.egg-info/PKG-INFO:    $ python setup.py build
hidapi.egg-info/PKG-INFO:    $ python setup.py build --with-libusb
hidapi.egg-info/PKG-INFO:    $ python setup.py build
hidapi.egg-info/PKG-INFO:    $ sudo python setup.py install
hidapi.egg-info/SOURCES.txt:setup.py

Q: Why README content is copied as it is to module metadata? That file contains many details which are not relevant to how to use module.