kpdemetriou / pqcrypto

👻 Post-quantum cryptography for Python.
BSD 3-Clause "New" or "Revised" License
58 stars 20 forks source link

Fails to install on macOS #1

Closed mouse07410 closed 4 years ago

mouse07410 commented 4 years ago

macOS 10.15.6, Xcode-11.7, Python-3.8.5.

$ sudo -EH pip3 install pqcrypto
Collecting pqcrypto
  Using cached pqcrypto-0.1.2.tar.gz (1.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting cffi<2.0.0,>=1.14.2
  Using cached cffi-1.14.2-cp38-cp38-macosx_10_9_x86_64.whl (176 kB)
Requirement already satisfied: pycparser in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from cffi<2.0.0,>=1.14.2->pqcrypto) (2.19)
Building wheels for collected packages: pqcrypto
  Building wheel for pqcrypto (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/local/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/tmpgymhwbqm
       cwd: /private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto
  Complete output (476 lines):
  Traceback (most recent call last):
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/utils/env.py", line 912, in _run
      output = subprocess.check_output(
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/utils/_compat.py", line 205, in run
      raise CalledProcessError(
  poetry.utils._compat.CalledProcessError: Command '['python', 'setup.py', 'build', '-b', 'build']' returned non-zero exit status 1.

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
      main()
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py", line 204, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/masonry/api.py", line 62, in build_wheel
      WheelBuilder.make_in(
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/masonry/builders/wheel.py", line 55, in make_in
      wb.build()
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/masonry/builders/wheel.py", line 81, in build
      self._build(zip_file)
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/masonry/builders/wheel.py", line 103, in _build
      self._env.run(
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/utils/env.py", line 879, in run
      return self._run(cmd, **kwargs)
    File "/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-build-env-h881v55v/overlay/lib/python3.8/site-packages/poetry/utils/env.py", line 916, in _run
      raise EnvCommandError(e, input=input_)
  poetry.utils.env.EnvCommandError: Command ['python', 'setup.py', 'build', '-b', 'build'] errored with the following return code 1, and output:
  WARNING: The pip package is not available, falling back to EasyInstall for handling setup_requires/test_requires; this is deprecated and will be removed in a future version.
  WARNING: The pip package is not available, falling back to EasyInstall for handling setup_requires/test_requires; this is deprecated and will be removed in a future version.
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.8
  creating build/lib.macosx-10.15-x86_64-3.8/pqcrypto
  copying pqcrypto/__init__.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto
  copying pqcrypto/common.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto
  package init file 'pqcrypto/kem/__init__.py' not found (or not a regular file)
  creating build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/mceliece460896.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/frodokem1344aes.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/lightsaber.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/mceliece6960119f.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/mceliece8192128f.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
  copying pqcrypto/kem/frodokem976shake.py -> build/lib.macosx-10.15-x86_64-3.8/pqcrypto/kem
. . . . .
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -O3 -std=gnu17 -march=native -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Isources/common -I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c /private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/aes256ctr.c -o build/temp.macosx-10.15-x86_64-3.8/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/aes256ctr.o -O3 -std=c99
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -O3 -std=gnu17 -march=native -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Isources/common -I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c /private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/encrypt.c -o build/temp.macosx-10.15-x86_64-3.8/private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/encrypt.o -O3 -std=c99
  In file included from /private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/encrypt.c:9:
  In file included from sources/common/randombytes.h:8:
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:546:7: error: conflicting types for 'encrypt'
  void     encrypt(char *, int) __DARWIN_ALIAS(encrypt);
           ^
  /private/var/folders/c6/lnc_0m093ys8w16md_fm1mnxhtfnj8/T/pip-install-1hzsrnnj/pqcrypto/sources/mceliece348864/vec/encrypt.h:8:6: note: previous declaration is here
  void encrypt(unsigned char * /*s*/, unsigned char * /*e*/, const unsigned char * /*pk*/);
       ^
  1 error generated.
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  ERROR: Failed building wheel for pqcrypto
Failed to build pqcrypto
ERROR: Could not build wheels for pqcrypto which use PEP 517 and cannot be installed directly
mouse07410 commented 4 years ago

This fix to the source code allows it to compile:

diff --git a/sources/common/randombytes.h b/sources/common/randombytes.h
index 37353cc..1a2a52f 100644
--- a/sources/common/randombytes.h
+++ b/sources/common/randombytes.h
@@ -5,7 +5,12 @@
 #ifdef _WIN32
 #include <CRTDEFS.H>
 #else
+#ifdef __APPLE__
+#include <stdlib.h>
+#include <stddef.h>
+#else /* __APPLE__ */
 #include <unistd.h>
+#endif /* __APPLE__ */
 #endif

 int randombytes(uint8_t *buf, size_t n);

Unfortunately, your README does not tell how to build/install from the local source tree, and until you apply and push the above fix - it won't even compile on Mac.

kpdemetriou commented 4 years ago

Thanks for bringing this up; could you confirm that it builds succesfully now? I have updated the README as requested.

mouse07410 commented 4 years ago

Thank you! I confirm that the current pqcrypto builds and installs from PyPI fine.

One more thing: for those proficient with Poetry, it's obvious that poetry build places the "wheel" in the dist/ subdirectory. Those who never touched that tool though - like myself - are stymied.

May I suggest one more enhancement for the README, something like:

    # Using poetry
    pip install poetry
    poetry build
    pip install dist/*.whl

and/or a few words about what poetry build produces, and how to actually get the resulting wheel installed and usable outside of the poetry environment.

Thanks!