From ad6496e426f81bd1519dfbd9cc092298d6dae8c0 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 19 Feb 2020 18:00:10 +0200 Subject: [PATCH] Make it possible to build and use ext on windows - change ext attributes and c source for windows allowing to build pyd - remove trailing slashes in data_files - try to load pyd in proofofwork by ctypes.PyDLL() --- setup.py | 13 ++++++++++--- src/bitmsghash/bitmsghash.cpp | 5 +++++ src/proofofwork.py | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 77ec81c8..d0d733bc 100644 --- a/setup.py +++ b/setup.py @@ -59,6 +59,13 @@ if __name__ == "__main__": libraries=['pthread', 'crypto'], ) + if sys.platform[:3] == 'win': + bitmsghash.libraries = ['libeay32', 'ws2_32'] + openssl_dir = os.getenv('OPENSSL_DIR') + if openssl_dir: + bitmsghash.library_dirs = [os.path.join(openssl_dir, 'lib')] + bitmsghash.include_dirs = [os.path.join(openssl_dir, 'include')] + installRequires = ['six'] packages = [ 'pybitmessage', @@ -90,11 +97,11 @@ if __name__ == "__main__": packages += ['pybitmessage.fallback.umsgpack'] data_files = [ - ('share/applications/', + ('share/applications', ['desktop/pybitmessage.desktop']), - ('share/icons/hicolor/scalable/apps/', + ('share/icons/hicolor/scalable/apps', ['desktop/icons/scalable/pybitmessage.svg']), - ('share/icons/hicolor/24x24/apps/', + ('share/icons/hicolor/24x24/apps', ['desktop/icons/24x24/pybitmessage.png']) ] diff --git a/src/bitmsghash/bitmsghash.cpp b/src/bitmsghash/bitmsghash.cpp index 24775475..b65c3265 100644 --- a/src/bitmsghash/bitmsghash.cpp +++ b/src/bitmsghash/bitmsghash.cpp @@ -163,3 +163,8 @@ extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, un free(threaddata); return successval; } + +// workaround for building setuptools ext on Windows +// https://stackoverflow.com/questions/34689210 +void initbitmsghash() {} //Python 2.7 +void PyInit_bitmsghash() {} //Python 3.5 diff --git a/src/proofofwork.py b/src/proofofwork.py index f170aa5f..b2842462 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -298,7 +298,13 @@ def init(): bitmsglib = 'bitmsghash64.dll' try: # MSVS - bso = ctypes.WinDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib)) + libfile = os.path.join(paths.codePath(), "bitmsghash", bitmsglib) + if os.path.isfile(libfile): + bso = ctypes.WinDLL(libfile) + else: + bitmsglib = 'bitmsghash.pyd' + libfile = os.path.join(paths.codePath(), "bitmsghash", bitmsglib) + bso = ctypes.PyDLL(libfile) logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib) bmpow = bso.BitmessagePOW bmpow.restype = ctypes.c_ulonglong