diff --git a/buildscripts/winbuild.sh b/buildscripts/winbuild.sh index 989e59bd..1676aa60 100755 --- a/buildscripts/winbuild.sh +++ b/buildscripts/winbuild.sh @@ -18,7 +18,8 @@ function download_sources_32 { https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe \ https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x32.exe?raw=true \ https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true \ - https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win32.whl?raw=true + https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win32.whl?raw=true \ + https://web.archive.org/web/20190720195601/https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi } function download_sources_64 { @@ -64,8 +65,10 @@ function install_python(){ wine msiexec -i python-${PYTHON_VERSION}.msi /q /norestart # MSVCR 2008 required for Windows XP cd ${SRCPATH} || exit 1 - echo "Installing vc_redist (2008) for 32 bit " + echo "Installing vc_redist (2008) for 32 bit" wine vcredist_x86.exe /Q + echo "Installing vcpython27" + wine msiexec -i VCForPython27.msi /qn /norestart fi echo "Installing pytools 2020.2" # last version compatible with python 2 @@ -88,9 +91,11 @@ function install_openssl(){ if [ "${MACHINE_TYPE}" == 'x86_64' ]; then echo "Installing OpenSSL ${OPENSSL_VERSION} 64b" wine Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes + export OPENSSL_DIR="$HOME/.wine64/drive_c/OpenSSL-Win64" else echo "Installing OpenSSL ${OPENSSL_VERSION} 32b" wine Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes + export OPENSSL_DIR="C:\\OpenSSL-Win32" fi } @@ -130,8 +135,8 @@ function install_pyopencl() function build_dll(){ cd "${BASE_DIR}" || exit 1 - cd src/bitmsghash || exit 1 if [ "${MACHINE_TYPE}" == 'x86_64' ]; then + cd src/bitmsghash || exit 1 echo "Create dll" x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native \ "-I$HOME/.wine64/drive_c/OpenSSL-Win64/include" \ @@ -146,18 +151,20 @@ function build_dll(){ -fPIC -shared -lcrypt32 -leay32 -lwsock32 \ -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a else - echo "Create dll" - i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native \ - "-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \ - -I/usr/i686-w64-mingw32/include \ - "-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib" \ - -c bitmsghash.cpp - i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \ - -D_WIN32 -O3 -march=native \ - "-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \ - "-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW" \ - -fPIC -shared -lcrypt32 -leay32 -lwsock32 \ - -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a + echo "Create pyd" + # FIXME: check for VCPython and build dll if not found + wine python setup.py build_ext --inplace + # i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native \ + # "-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \ + # -I/usr/i686-w64-mingw32/include \ + # "-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib" \ + # -c bitmsghash.cpp + # i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o \ + # -D_WIN32 -O3 -march=native \ + # "-I$HOME/.wine32/drive_c/OpenSSL-Win32/include" \ + # "-L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW" \ + # -fPIC -shared -lcrypt32 -leay32 -lwsock32 \ + # -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a fi } diff --git a/packages/pyinstaller/bitmessagemain.spec b/packages/pyinstaller/bitmessagemain.spec index 082cc6fd..eb54f17b 100644 --- a/packages/pyinstaller/bitmessagemain.spec +++ b/packages/pyinstaller/bitmessagemain.spec @@ -11,7 +11,7 @@ arch = 32 if ctypes.sizeof(ctypes.c_voidp) == 4 else 64 cdrivePath = site_root[0:3] srcPath = os.path.join(spec_root[:-20], "src") sslName = 'OpenSSL-Win%i' % arch -openSSLPath = os.path.join(cdrivePath, sslName) +openSSLPath = os.getenv('OPENSSL_DIR') or os.path.join(cdrivePath, sslName) msvcrDllPath = os.path.join(cdrivePath, "windows", "system32") outPath = os.path.join(spec_root, "bitmessagemain") qtBase = "PyQt4" @@ -83,12 +83,19 @@ excluded_binaries = [ ] a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries]) +ext_lib = os.path.join('bitmsghash', 'bitmsghash%i.dll' % arch) + +if os.path.isfile(ext_lib): + ext_lib = (ext_lib, os.path.join(srcPath, ext_lib), 'BINARY') +else: + ext_lib = ( + os.path.join('bitmsghash', 'bitmsghash.pyd'), + os.path.join(srcPath, 'bitmsghash', 'bitmsghash.pyd'), 'EXTENSION') + a.binaries += [ # No effect: libeay32.dll will be taken from PyQt if installed ('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'), - (os.path.join('bitmsghash', 'bitmsghash%i.dll' % arch), - os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % arch), - 'BINARY'), + ext_lib, (os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'), (os.path.join('sslkeys', 'cert.pem'), diff --git a/setup.py b/setup.py index 0de2eb8c..b3f4eacb 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', @@ -87,11 +94,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