/ msys2_build.txt
msys2_build.txt
1 Building gmpy2 with MSYS2 and MinGW-w64 2 ======================================= 3 4 Note: These instructions are a work in progress! 5 6 From the MSYS2 home page: 7 8 http://sourceforge.net/projects/msys2/ 9 10 MSYS2 is a Cygwin-derived Posix-like environment for Windows. The name is a 11 contraction of Minimal SYStem 2, and aims to provide support to facilitate 12 using the bash shell, Autotools, revision control systems and the like for 13 building native Windows applications using MinGW-w64 toolchains. 14 15 Installing MSYS2 16 ================ 17 18 MSYS2 installation instructions can be found at: 19 20 http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/ 21 22 The examples assume the 64-bit version of MSYS2 is installed. 23 24 The following additional packages should also be installed: 25 26 $ pacman -S patch m4 lzip wget tar make diffutils 27 28 Installing MinGW-w64 29 ==================== 30 31 MSYS2 follows a "rolling-release" model. New versions of applications, 32 including MinGW-w64, are released frequently. The continual releases makes 33 it difficult to provide a reproducible compliler. We will be using MinGW-w64 34 as distributed by http://winlibs.com/. This documentation was based on the 35 following version: 36 37 https://github.com/brechtsanders/winlibs_mingw/releases/download/10.2.0-11.0.0-8.0.0-r7/winlibs-x86_64-posix-seh-gcc-10.2.0-mingw-w64-8.0.0-r7.7z 38 39 Unzip the downloaded file and copy and copy the "mingw64" to the desired 40 location. The documentation assumes the files are copied to C:\mingw64. 41 42 The build environment 43 ===================== 44 45 The build process is split into two phases. During phase 1 we use the MSYS2 46 shell environment and winlibs.com MinGW-w64 compiler suite to build GMP, MPFR, 47 and MPC. Once those libraries are build, we will use the Windows command prompt 48 and the same compiler to build the actual gmpy2 extension (DLL). 49 50 Commands that must be executed from an MSYS2 shell are preceded by "$". 51 Commands that must be executed from a Windows command prompt are preceded 52 by ">". You will need to run the commands *after* "$" or ">". 53 54 The MSYS2 environment provides three different command line operating 55 environments. 56 57 * MSYS2 MSYS 58 This is the general-purpose MSYS shell but it does not provide 59 access to the MinGW compiler suite. We will use this shell and 60 manually add the location of the winlibs.com version. 61 62 * MSYS2 MinGW 64-bit 63 This provides access to the 64-bit MinGW (optionally installed 64 through MSYS2) compiler suite. We will not use this because we can't 65 recreate the identical environment in the future. 66 67 * MSYS2 MinGW 32-bit 68 This provides access to the 32-bit MinGW (optionally installed 69 through MSYS2) compiler suite. We will not use this because we can't 70 recreate the identical environment in the future. 71 72 MSYS2 does include versions of GMP, MPFR, and MPC but we will compile our 73 own version directly from the source. We do this so we can create reproducible 74 builds. 75 76 Compiling GMP, MPFR, and MPC 77 ============================ 78 79 # Start the appropriate shell: MSYS2 MSYS 80 81 # Add the MinGW-w64 compiler to the PATH. 82 83 $ PATH="/c/mingw64/bin:"$PATH 84 85 # In you home directory, create directories for the various files that 86 # are created. 87 88 $ mkdir $HOME/64 89 $ mkdir $HOME/64/src 90 $ mkdir $HOME/64/static 91 $ mkdir $HOME/64/shared 92 93 # Download and uncompress GMP, MPFR, and MPC 94 95 $ cd $HOME/64/src 96 97 # Download GMP 98 $ wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz 99 $ tar xf gmp-6.2.1.tar.lz 100 101 # Download MPFR and any patches 102 $ wget http://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.bz2 103 $ tar xf mpfr-4.1.0.tar.bz2 104 $ cd mpfr-4.1.0/ 105 $ wget http://www.mpfr.org/mpfr-current/allpatches 106 $ patch -N -Z -p1 < allpatches 107 $ cd .. 108 109 # Download MPC 110 $ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz 111 $ tar xf mpc-1.1.0.tar.gz 112 113 # Compile GMP 114 $ cd gmp-6.2.0/ 115 $ ./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=$HOME/64/static --enable-static --disable-shared --enable-fat --with-pic 116 $ make 117 $ make check 118 $ make install 119 $ cd .. 120 121 # Compile MPFR 122 $ cd mpfr-4.1.0/ 123 $ ./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=$HOME/64/static --enable-static --disable-shared --disable-decimal-float --disable-float128 --with-pic --with-gmp=$HOME/64/static 124 $ make 125 $ make check 126 $ make install 127 $ cd .. 128 129 # Compile MPC 130 $ cd mpc-1.1.0/ 131 $ ./configure --build=x86_64-pc-mingw64 --host=x86_64-pc-mingw64 --prefix=$HOME/64/static --enable-static --disable-shared --with-pic --with-gmp=$HOME/64/static --with-mpfr=$HOME/64/static 132 $ make 133 $ make check 134 $ make install 135 $ cd .. 136 137 The Windows build environment 138 ============================= 139 140 # Configure Windows command prompt - GCC 141 142 > set Path=C:\mingw64\bin;%Path% 143 144 To verfiy the MinGW toolchain is accessible, the command "gcc -v" should 145 return information about the gcc compiler. 146 147 Note: All the remaining instructions assume this step has been completed and 148 that "gcc -v" returns information for the correct version of gcc. 149 150 # Configure Windows command prompt - Python 151 The Python interpreter does not need to be accessible via the path. You can 152 specify the full path name to start a particular version. To simplify the 153 compilation of multiple versions of gmpy2, I have adopted the following 154 approach: 155 156 # 64-bit versions of Python are installed in C:\64 157 # Aliases are defined to create shortcuts for invoking a Python interpreter 158 159 I use the following batch file to configure a command prompt for 64-bit builds: 160 161 @echo off 162 doskey py27=C:\64\Python27\python.exe $* 163 doskey py35=C:\64\Python35\python.exe $* 164 doskey py36=C:\64\Python36\python.exe $* 165 doskey py37=C:\64\Python37\python.exe $* 166 doskey py38=C:\64\Python38\python.exe $* 167 doskey py39=C:\64\Python39\python.exe $* 168 set Path=C:\mingw64\bin;%Path% 169 170 # Upgrade pip and setuptools 171 172 # Repeat as needed for different versions 173 py36 -m pip install --upgrade pip 174 py36 -m pip install --upgrade setuptools 175 176 177 # Replace Python's cygwinccompiler.py with the numpy.distutils verion 178 # located in the <<gmpy2 source>>\ming64\distutils directory. 179 180 # To compile gmpy2 181 182 py27 setup.py build_ext --msys2 --prefix=c:\msys64\mingwXX\opt 183 184 # To install to a local Python installation (after compiling) 185 py27 setup.py install 186 187 188 py27 setup.py build_ext -cmingw32 -Ic:\64\static\include -Lc:\64\static\lib 189 190 191 py27 setup.py build_ext -cmingw32 -Ic:\64\static\include -Lc:\64\static\lib -f install