Skip to content

Commit

Permalink
Updated files to support Windows builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
casevh committed Jul 31, 2023
1 parent 2aed2ae commit 016dc98
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 316 deletions.
43 changes: 23 additions & 20 deletions mingw64/64bit.bat
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
@echo off
doskey py37=D:\64\Python37\python.exe $*
doskey py38=D:\64\Python38\python.exe $*
doskey py39=D:\64\Python39\python.exe $*
doskey py310=D:\64\Python310\python.exe $*
doskey py311=D:\64\Python311\python.exe $*

doskey py37_build=D:\64\Python37\python.exe setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py38_build=D:\64\Python38\python.exe setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py39_build=D:\64\Python39\python.exe setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py310_build=D:\64\Python310\python.exe setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py311_build=D:\64\Python311\python.exe setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel

doskey py37_install=cmd /c "for %f in (dist\gmpy2*37*) do D:\64\Python37\python.exe -m pip install %f --force-reinstall"
doskey py38_install=cmd /c "for %f in (dist\gmpy2*38*) do D:\64\Python38\python.exe -m pip install %f --force-reinstall"
doskey py39_install=cmd /c "for %f in (dist\gmpy2*39*) do D:\64\Python39\python.exe -m pip install %f --force-reinstall"
doskey py310_install=cmd /c "for %f in (dist\gmpy2*310*) do D:\64\Python310\python.exe -m pip install %f --force-reinstall"
doskey py311_install=cmd /c "for %f in (dist\gmpy2*311*) do D:\64\Python311\python.exe -m pip install %f --force-reinstall"

set Path=D:\mingw64\bin;%Path%
@echo off
doskey py37=py -3.7 $*
doskey py38=py -3.8 $*
doskey py39=py -3.9 $*
doskey py310=py -3.10 $*
doskey py311=py -3.11 $*
doskey py312=py -3.12 $*

doskey py37_build=py -3.7 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py38_build=py -3.8 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py39_build=py -3.9 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py310_build=py -3.10 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py311_build=py -3.11 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
doskey py312_build=py -3.12 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel

doskey py37_install=cmd /c "for %f in (dist\gmpy2*37*) do py -3.7 -m pip install %f --force-reinstall"
doskey py38_install=cmd /c "for %f in (dist\gmpy2*38*) do py -3.8 -m pip install %f --force-reinstall"
doskey py39_install=cmd /c "for %f in (dist\gmpy2*39*) do py -3.9 -m pip install %f --force-reinstall"
doskey py310_install=cmd /c "for %f in (dist\gmpy2*310*) do py -3.10 -m pip install %f --force-reinstall"
doskey py311_install=cmd /c "for %f in (dist\gmpy2*311*) do py -3.11 -m pip install %f --force-reinstall"
doskey py312_install=cmd /c "for %f in (dist\gmpy2*312*) do py -3.12 -m pip install %f --force-reinstall"

set Path=C:\mingw64\bin;%Path%
12 changes: 6 additions & 6 deletions mingw64/msys2_64_shared.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
PATH="/d/mingw64/bin:"$PATH
PATH="/c/mingw64/bin:"$PATH

GMP_VERSION=6.2.1
MPFR_VERSION=4.2.0
MPC_VERSION=1.3.1

cd /d/64
cd /c/64

mkdir src
mkdir shared

cd /d/64/src
cd /c/64/src

if [ ! -f gmp-${GMP_VERSION}.tar.lz ]; then
wget https://gmplib.org/download/gmp/gmp-${GMP_VERSION}.tar.lz
Expand All @@ -32,7 +32,7 @@ tar xf mpc-${MPC_VERSION}.tar.gz

cd gmp-${GMP_VERSION}/
make distclean
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/d/64/shared --enable-shared --disable-static --enable-fat --with-pic
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/c/64/shared --enable-shared --disable-static --enable-fat --with-pic
mv gmp.h gmp.original
sed 's/typedef\s*unsigned\s*long\s*int\s*mp_bitcnt_t/typedef unsigned long long int mp_bitcnt_t\n/g' gmp.original > gmp.h
make -j8
Expand All @@ -42,15 +42,15 @@ cd ..

cd mpfr-${MPFR_VERSION}/
make distclean
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/d/64/shared --enable-shared --disable-static --disable-decimal-float --disable-float128 --with-pic --with-gmp=/d/64/shared
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/c/64/shared --enable-shared --disable-static --disable-decimal-float --disable-float128 --with-pic --with-gmp=/c/64/shared
make -j8
make check
make install
cd ..

cd mpc-${MPC_VERSION}/
make distclean
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/d/64/shared --enable-shared --disable-static --with-pic --with-gmp=/d/64/shared --with-mpfr=/d/64/shared
./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=/c/64/shared --enable-shared --disable-static --with-pic --with-gmp=/c/64/shared --with-mpfr=/c/64/shared
make -j8
make check
make install
Expand Down
85 changes: 33 additions & 52 deletions mingw64/msys2_build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Installing MSYS2
================

Note: The following instructions assume MSYS2 and MinGW-w64 are installed as
D:\msys2 and D:\mingw64, respectively.
C:\msys2 and C:\mingw64, respectively.

Detailed MSYS2 installation instructions can be found at:

Expand All @@ -56,10 +56,10 @@ release cycles makeit difficult to provide a reproducible compliler. We will
be using MinGW-w64 as distributed by http://winlibs.com/. This documentation
was based on the following version:

https://github.com/brechtsanders/winlibs_mingw/releases/download/12.2.0-15.0.7-10.0.0-ucrt-r4/winlibs-x86_64-posix-seh-gcc-12.2.0-mingw-w64ucrt-10.0.0-r4.7z
https://github.com/brechtsanders/winlibs_mingw/releases/download/winlibs-x86_64-posix-seh-gcc-13.1.0-llvm-16.0.5-mingw-w64msvcrt-11.0.0-r5

Unzip the downloaded file and copy the "mingw64" to the desired location.
The following documentation assumes the files are copied to D:\mingw64.
The following documentation assumes the files are copied to C:\mingw64.

The build environment
=====================
Expand Down Expand Up @@ -100,7 +100,7 @@ The Windows build environment
Note: The following command is automatically run by the 64bit.bat file
documented below.

> set Path=D:\mingw64\bin;%Path%
> set Path=C:\mingw64\bin;%Path%

To verfiy the MinGW toolchain is accessible, the command "gcc -v" should
return information about the gcc compiler.
Expand All @@ -110,21 +110,11 @@ The Windows build environment

# Configure Windows command prompt - Python

The Python interpreter does not need to be accessible via the path. You can
specify the full path name to start a particular version. To simplify the
compilation of multiple versions of gmpy2, I have adopted the following
approach:

# 64-bit versions of Python are installed in D:\64
# Aliases are defined to create shortcuts for invoking a Python interpreter

I use the following batch file to configure a command prompt for 64-bit builds:

@echo off
doskey py35=D:\64\Python35\python.exe $*
doskey py36=D:\64\Python36\python.exe $*
doskey py37=D:\64\Python37\python.exe $*
doskey py38=D:\64\Python38\python.exe $*
doskey py37=py -3.7 $*
doskey py38=py -3.8 $*
doskey py39=D:\64\Python39\python.exe $*
doskey py310=D:\64\Python310\python.exe $*
set Path=D:\mingw64\bin;%Path%
Expand All @@ -135,66 +125,60 @@ The Windows build environment

Repeat as needed for different versions of Python

py36 -m pip install --upgrade pip
py36 -m pip install --upgrade setuptools
py36 -m pip install pytest wheel
py -3.7 -m pip install --upgrade pip setuptools pytest wheel

# Replace Python's cygwinccompiler.py with the numpy.distutils verion
# located in the <<gmpy2 source>>\ming64\distutils directory.

copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python35\Lib\distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python36\Lib\distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python37\Lib\distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python38\Lib\distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python39\Lib\distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python310\Lib\site-packages\setuptools\_distutils\.
copy /y mingw64\distutils\cygwinccompiler.py D:\64\Python311\Lib\site-packages\setuptools\_distutils\.
copy /y mingw64\distutils\cygwinccompiler.py %LOCALAPPDATA%\Programs\Python\Python37\Lib\site-packages\setuptools\_distutils\.

# Create the appropriate libpythonNN.a files. See gendef64.bat

cd D:\64\Python35\libs
gendef D:\64\Python35\python35.dll
dlltool --dllname D:\64\Python35\python35.dll --def python35.def --output-lib libpython35.a
cd %LOCALAPPDATA%\Programs\Python\Python37\libs
gendef ..\python37.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python37\python37.dll --def python37.def --output-lib libpython37.a

cd D:\64\Python36\libs
gendef D:\64\Python36\python36.dll
dlltool --dllname D:\64\Python36\python36.dll --def python36.def --output-lib libpython36.a
cd %LOCALAPPDATA%\Programs\Python\Python38\libs
gendef ..\python38.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python38\python38.dll --def python38.def --output-lib libpython38.a

cd D:\64\Python37\libs
gendef D:\64\Python37\python37.dll
dlltool --dllname D:\64\Python37\python37.dll --def python37.def --output-lib libpython37.a
cd %LOCALAPPDATA%\Programs\Python\Python39\libs
gendef ..\python39.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python39\python39.dll --def python39.def --output-lib libpython39.a

cd D:\64\Python38\libs
gendef D:\64\Python38\python38.dll
dlltool --dllname D:\64\Python38\python38.dll --def python38.def --output-lib libpython38.a
cd %LOCALAPPDATA%\Programs\Python\python310\libs
gendef ..\python310.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python310\python310.dll --def python310.def --output-lib libpython310.a

cd D:\64\Python39\libs
gendef D:\64\Python39\python39.dll
dlltool --dllname D:\64\Python39\python39.dll --def python39.def --output-lib libpython39.a
cd %LOCALAPPDATA%\Programs\Python\python311\libs
gendef ..\python311.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python311\python311.dll --def python311.def --output-lib libpython311.a

cd D:\64\Python310\libs
gendef D:\64\Python310\python310.dll
dlltool --dllname D:\64\Python310\python310.dll --def python310.def --output-lib libpython310.a
cd %LOCALAPPDATA%\Programs\Python\python312\libs
gendef ..\python312.dll
dlltool --dllname %LOCALAPPDATA%\Programs\Python\Python312\python312.dll --def python312.def --output-lib libpython312.a

# Copy the result of the compilation to the <<gmpy2 source>>\mingw64\shared directory

xcopy /s /y D:\64\shared D:\64\gmpy2\mingw64\shared
xcopy /s /y C:\64\shared\bin C:\64\gmpy\mingw64\shared\bin\.
xcopy /s /y C:\64\shared\lib C:\64\gmpy\mingw64\shared\lib\.
xcopy /s /y C:\64\shared\include C:\64\gmpy\mingw64\shared\include\.

# Copy the libgcc_s_seh-1.dll file from the mingw64 distribution to the
# <<gmpy2 source>>\mingw64\shared\bin directory.

copy /y D:\mingw64\bin\libgcc_s_seh-1.dll D:\64\gmpy2\mingw64\shared\bin
copy /y C:\mingw64\bin\libgcc_s_seh-1.dll C:\64\gmpy\mingw64\shared\bin

# Copy the libwinpthread-1.dll file from the mingw64 distribution to the
# <<gmpy2 source>>\mingw64\shared\bin directory.

copy /y D:\mingw64\bin\libwinpthread-1.dll D:\64\gmpy2\mingw64\shared\bin
copy /y C:\mingw64\bin\libwinpthread-1.dll C:\64\gmpy\mingw64\shared\bin

# To compile gmpy2

# Copy the additional DLL files to <<gmpy2 source>>\gmpy2

xcopy /y D:\64\gmpy2\mingw64\shared\bin\. D:\64\gmpy2\gmpy2\
xcopy /y C:\64\gmpy\mingw64\shared\bin\. C:\64\gmpy\gmpy2\

The contents should be similar to:

Expand All @@ -212,10 +196,7 @@ The contents should be similar to:

# Complile and create a binary wheel.

py27 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py35 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py36 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py37 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py -3.7 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py38 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py39 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
py310 setup.py build_ext -cmingw32 -Imingw64\shared\include -Lmingw64\shared\lib -f bdist_wheel
Expand Down
Binary file modified mingw64/shared/bin/libgcc_s_seh-1.dll
Binary file not shown.
Binary file modified mingw64/shared/bin/libgmp-10.dll
Binary file not shown.
Binary file modified mingw64/shared/bin/libmpc-3.dll
Binary file not shown.
Binary file modified mingw64/shared/bin/libmpfr-6.dll
Binary file not shown.
Binary file modified mingw64/shared/bin/libwinpthread-1.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion mingw64/shared/include/gmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef unsigned long int mp_bitcnt_t;
typedef unsigned long long int mp_bitcnt_t
;

/* For reference, note that the name __mpz_struct gets into C++ mangled
function names, which means although the "__" suggests an internal, we
Expand Down
Loading

0 comments on commit 016dc98

Please sign in to comment.