To rebuild from sources on Windows, this is the general guide: https://devguide.python.org/setup/#windows-compiling. Note that //Python 2.7 uses Microsoft Visual Studio 2008, which is most easily obtained through an MSDN subscription. To use the build files in the PCbuild directory you will also need Visual Studio 2010, see the 2.7 readme for more details.//
VS 2010 we already use to build OpenSSL. VS 2008 Chocolatey package is broken apparently and can't install. You can get links for installing the Express edition from https://stackoverflow.com/a/30540499, but that didn't help. The Express edition apparently lacks the needed tools. More at https://stackoverflow.com/a/56088191.
I suggest following the default build instructions in the PCbuild/readme.txt file with both VS 2008 and 2010 full editions installed.
A starting diff:
diff --git a/chevah_build b/chevah_build
index 6842cdc0..35449c41 100755
--- a/chevah_build
+++ b/chevah_build
@@ -142,7 +142,7 @@ RHEL_PKGS="$COMMON_PKGS git openssl-devel zlib-devel libffi-devel ncurses-devel"
ALPINE_PKGS="$COMMON_PKGS \
git zlib-dev libffi-dev ncurses-dev linux-headers musl-dev openssl-dev"
# No automated Windows package management, but here's what it's needed.
-CHOCO_PKGS="vcpython27 make git StrawberryPerl nasm 7zip"
+CHOCO_PKGS="vcpython27 make git StrawberryPerl nasm 7zip svn"
# $ARCH can be used to force a 32bit build on a 64bit machine, e.g. by exporting
# ARCH in brink.sh as "x86" instead of "x64", or "ppc" instead of "ppc64".
@@ -167,12 +167,12 @@ case $OS in
# On Windows, python executable is installed at a different path.
LOCAL_PYTHON_BINARY=./$LOCAL_PYTHON_BINARY_DIST/lib/python
PYTHON_BIN=$INSTALL_FOLDER/lib/python
- # For Windows we don't build everything from source yet.
- # But what we build is done in a very different way, no CC/MAKE/etc.
+ # Windows deps are built differently. Also, no CC / MAKE / etc.
export BUILD_LIBEDIT="no"
export BUILD_GMP="no"
export BUILD_BZIP2="no"
# MSYS2's Perl is not good enough for building OpenSSL.
+ # Do no split these on several lines with '\', it breaks on Windows.
export PATH="/c/Strawberry/perl/bin/:$PATH:/c/Program Files/NASM/"
export BUILD_OPENSSL="yes"
# Extra libraries are installed only using PIP.
@@ -388,7 +388,7 @@ check_dependencies() {
;;
win)
# To not get confused by MSYS2's perl, we check for wperl.
- packages="git patch wperl nasm 7z"
+ packages="git patch wperl nasm 7z" # svn?
;;
*)
packages="$CC make m4 git patch"
@@ -509,10 +509,6 @@ command_build() {
fi
case $OS in
- win)
- build 'python' "Python-$PYTHON_BUILD_VERSION-windows" \
- ${PYTHON_BUILD_FOLDER}
- ;;
macos)
# The headers for zlib are missing on macOS 10.14+.
# Required CPPFLAGS are already set after building OpenSSL.
diff --git a/src/python/chevahbs b/src/python/chevahbs
index 4b49d99b..4d6c03ff 100755
--- a/src/python/chevahbs
+++ b/src/python/chevahbs
@@ -10,15 +10,9 @@
#
chevahbs_patch() {
# First we apply the generic patches.
- if [ "$OS" = "win" ]; then
- echo "No sources to patch in Windows."
- return
- fi
-
# Our own patch to avoid compiling certain modules.
echo "Applying disabled_modules.patch:"
execute patch < disabled_modules.patch
-
# Patch to disable Python 2 / OpenSSL 1.0.2 warnings from cryptography.
echo "Applying crypto_silence_warnings.patch:"
execute patch -p0 < crypto_silence_warnings.patch
@@ -29,6 +23,7 @@ chevahbs_patch() {
echo "Applying readline_libedit.patch:"
execute patch -p0 < readline_libedit.patch
fi
+
# And finally we apply the OS-specific patches.
case $OS in
aix*)
@@ -53,27 +48,16 @@ chevahbs_configure() {
CONFIG_ARGS="--disable-shared"
CONFIGURE_ENVIRONMENT=""
- if [ "$OS" != "win" ]; then
- echo "Copying our header files among Python's ones..."
- execute cp -r "$INSTALL_FOLDER"/include/* ./Include/
- fi
+ echo "Copying our header files among Python's ones..."
case $OS in
- "ubuntu1004")
- # On Ubuntu there are no libXXX.o, but rather linked against the
- # full version number.
- CONFIG_ARGS="${CONFIG_ARGS} \
- --with-bz2-version=1 \
- --with-crypt-version=1 \
- --with-openssl-version=0.9.8 \
- "
+ win)
+ execute cp -r "$INSTALL_FOLDER"/lib/include/* ./Include/
;;
- "ubuntu1204")
- CONFIG_ARGS="${CONFIG_ARGS} \
- --with-bz2-version=1 \
- --with-crypt-version=1 \
- --with-openssl-version=1.0.0 \
- "
+ *)
+ execute cp -r "$INSTALL_FOLDER"/include/* ./Include/
;;
+ esac
+ case $OS in
aix*)
# Workaround for http://bugs.python.org/issue21917
echo "import os; os.__dict__.pop('O_NOFOLLOW', None)" \
@@ -119,20 +103,24 @@ chevahbs_configure() {
chevahbs_compile() {
+ echo "Patching the git rev id into Python's version string..."
+ cp Modules/getbuildinfo.c Modules/getbuildinfo.c.orig
+ execute sed -e \
+ s/gitid\ =\ \"default\"/gitid\ =\ \"$PYTHON_PACKAGE_VERSION\"/g \
+ Modules/getbuildinfo.c.orig > Modules/getbuildinfo.c
+
case $OS in
win)
- echo "Skip make on Windows."
+ case $ARCH in
+ x86)
+ execute PCbuild/build.bat "/p:PlatformToolset=v100" -c Release -p Win32 -e --no-bsddb --no-tkinter
+ ;;
+ x64)
+ execute PCbuild/build.bat "/p:PlatformToolset=v100" -c Release -p x64 -e --no-bsddb --no-tkinter
+ ;;
+ esac
;;
*)
- echo "Patching the git rev id into Python's version string..."
- cp Modules/getbuildinfo.c Modules/getbuildinfo.c.orig
- VCS_ID="gitid"
- if [ $PYTHON_BUILD_VERSION == "2.7.8" ] ; then
- VCS_ID="hgid"
- fi
- execute sed -e \
- s/$VCS_ID\ =\ \"default\"/$VCS_ID\ =\ \"$PYTHON_PACKAGE_VERSION\"/g \
- Modules/getbuildinfo.c.orig > Modules/getbuildinfo.c
execute $MAKE
;;
esac
@@ -142,52 +130,6 @@ chevahbs_compile() {
chevahbs_install() {
install_folder=$1
case $OS in
- win)
- local destination=$INSTALL_FOLDER/lib
- local inst_ext="msi"
- local arch_dir=$ARCH
- if [ "$ARCH" = "x64" ]; then
- # Upstream installer filename ends in ".msi" or ".amd64.msi".
- inst_ext="amd64.msi"
- # VC redist x64 DLLs actually use "amd64" in filenames.
- arch_dir="amd64"
- fi
-
- # On Windows we don't build from source but rather create the
- # distribution from pre-compiled binaries.
- current_win_path=`pwd -W | sed 's|\/|\\\\|g'`
- install_win_path=`cd $INSTALL_FOLDER && pwd -W | sed 's|\/|\\\\|g'`
-
- echo "Extracting MSI to $install_win_path"
- execute msiexec //a \
- $current_win_path\\python-"$PYTHON_BUILD_VERSION"."$inst_ext" \
- //qn TARGETDIR=$install_win_path\\lib
-
- # Copy Windows redistributables
- local redistributables=../../win-tools/redistributables/
- echo "Copying redistributables for Windows"
- execute cp $redistributables/$REDISTRIBUTABLE_VERSION/$arch_dir/* \
- $destination
-
- wipe_manifest $destination/python.exe
- wipe_manifest $destination/pythonw.exe
- wipe_manifest $destination/python27.dll
-
- # Remove Python MSI installer.
- echo "Removing: $destination/python-installer.msi"
- execute rm -f --verbose $destination/python-installer.msi
-
- # add cp65001 as an utf-8 alias.
- execute mv \
- $destination/lib/encodings/aliases.py \
- $destination/lib/encodings/aliases.old
- execute \
- sed "s|# utf_8 codec|# utf_8 codec\n 'cp65001' : 'utf_8',|" < $destination/lib/encodings/aliases.old > $destination/lib/encodings/aliases.py
-
- # Patch to disable Python 2 / OpenSSL 1.0.2 warnings from cryptography.
- echo "Applying crypto_silence_warnings.patch:"
- execute patch -d $destination -p0 < crypto_silence_warnings.patch
- ;;
*)
if [ "${OS%alpine*}" = "" ]; then
# EMUTRAMP required for full functionality under a grsec kernel.
T5589 task was created by dumol on 2021-03-19 09:59:06Z.
While working on #138 it became obvious building Python 2.7 is far from trivial. Also, with the exception of the fixes for CVE-2021-3177 (https://github.com/ActiveState/cpython/pull/6 and https://github.com/ActiveState/cpython/pull/7), all ActivePython patches so far are for
.py
files, thus applicable to the upstream packages.To rebuild from sources on Windows, this is the general guide: https://devguide.python.org/setup/#windows-compiling. Note that //Python 2.7 uses Microsoft Visual Studio 2008, which is most easily obtained through an MSDN subscription. To use the build files in the PCbuild directory you will also need Visual Studio 2010, see the 2.7 readme for more details.//
VS 2010 we already use to build OpenSSL. VS 2008 Chocolatey package is broken apparently and can't install. You can get links for installing the Express edition from https://stackoverflow.com/a/30540499, but that didn't help. The Express edition apparently lacks the needed tools. More at https://stackoverflow.com/a/56088191.
I've tried building with VS 2010 and/or Visual C++ Compiler for Python 2.7, as suggested at https://bugs.python.org/msg293734, but with very limited results: https://chevah.com/buildbot/builders/python-package-win-2019/builds/377 and https://chevah.com/buildbot/builders/python-package-win-2016/builds/143.
I suggest following the default build instructions in the
PCbuild/readme.txt
file with both VS 2008 and 2010 full editions installed.A starting diff: