Last active
October 25, 2021 19:09
-
-
Save franferrax/6be355eac5a7839d66a76135943fb9cc to your computer and use it in GitHub Desktop.
Create a POW (Python OpenSSL Wrappers) Wheel for Python 2.7.12, linking against OpenSSL 1.0.1h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM Check permissions | |
net session >nul 2>&1 || ( | |
echo Aborting: this script must be run elevated! | |
exit /b 1 | |
) | |
pushd "%UserProfile%\Downloads" | |
REM Install Python 2.7.12 | |
set f=python-2.7.12.msi | |
set u=https://www.python.org/ftp/python/2.7.12/%f% | |
curl -Lo "%f%" "%u%" && start /wait MsiExec /i "%f%" /qn /passive ADDLOCAL=ALL && del "%f%" | |
REM Install Microsoft Visual C++ Compiler Package for Python 2.7 | |
set f=VCForPython27.msi | |
set u=https://raw.githubusercontent.com/reider-roque/sulley-win-installer/master/%f% | |
curl -Lo "%f%" "%u%" && start /wait MsiExec /i "%f%" /qn /passive ADDLOCAL=ALL && del "%f%" | |
REM Install Visual C++ Redistributable Package | |
set f=vcredist_x86.exe | |
set u=http://download.microsoft.com/download/c/c/2/cc2df5f8-4454-44b4-802d-5ea68d086676/%f% | |
curl -Lo "%f%" "%u%" && start /wait %f% /install /passive && del "%f%" | |
REM Python simple replacement maker | |
set do_replacement=python -c "d=open(r'%%f%%','rb').read().replace(%%r%%);open(r'%%f%%','wb').write(d)" | |
REM Create a virtual environment | |
set m=C:\Python27\python.exe -m | |
%m% pip install --upgrade pip==20.3 | |
%m% pip install virtualenv==20.4.0 | |
%m% virtualenv venv && call venv\Scripts\activate.bat | |
REM Install and patch conan to work in Python 2.7 without user interaction | |
pip install conan==1.33.0 | |
set f=venv\Lib\site-packages\conans\client\command.py | |
set r='_warn_python_version(self):', '_warn_python_version(self):\r\n return' | |
call %do_replacement% | |
REM Install conan and download OpenSSL 1.0.1h | |
set h=6f2f3b0c15b05f704ad0dc3e210856b9e1d5f124 | |
conan download OpenSSL/1.0.1h@conan/stable:%h% | |
set openssldir=%UserProfile%\.conan\data\OpenSSL\1.0.1h\conan\stable\package\%h% | |
REM Patch stuff to make it build even when we know that no MD2 nor RC5 support will be available in runtime | |
curl -Lo "%openssldir%\include\openssl\md2.h" https://github.com/openssl/openssl/raw/OpenSSL_1_0_1h/crypto/md2/md2.h | |
set f=%openssldir%\include\openssl\opensslconf.h | |
set r='# define OPENSSL_NO_MD2', '/* # define OPENSSL_NO_MD2 */' | |
call %do_replacement% | |
set r='# define OPENSSL_NO_RC5', '/* # define OPENSSL_NO_RC5 */' | |
call %do_replacement% | |
REM Horrible hook for a forgotten include in POW.c | |
set f=%openssldir%\include\openssl\crypto.h | |
echo #include ^<openssl/ripemd.h^>>> "%f%" | |
REM Ignore missing functions when linking!!! | |
set _CL_=/I %openssldir%\include | |
set _LINK_=/LIBPATH:%openssldir%\lib /FORCE:UNRESOLVED | |
REM Create POW wheel | |
set unpacked=POW-0.7 | |
pip wheel https://sourceforge.net/projects/pow/files/POW/POW-0.7/POW-0.7.tar.gz/download | |
for %%f in (POW-*.whl) do wheel unpack "%%f" | |
xcopy /y /e "%openssldir%\bin\*.*" "%unpacked%\POW" | |
REM We shouldn't ship msvcr120.dll inside the wheel, here it is included as a 'just works' example | |
copy /y "%WinDir%\SysWOW64\msvcr120.dll" "%unpacked%\POW" | |
wheel pack "%unpacked%" && rd /s /q "%unpacked%" | |
REM Cleanup | |
rd /s /q %UserProfile%\.conan | |
call deactivate && rd /s /q venv | |
REM Final message | |
echo. && echo. && echo. | |
for %%f in (POW-*.whl) do echo Wheel created: %CD%\%%f | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute in a modern Windows 10 version (tested in 20H2 & 21H1), in an elevated command line, with: