User:Sokwe/Compiling ikpx2 with MinGW-w64

From LifeWiki
Jump to navigation Jump to search

This is a tutorial for compiling ikpx2 natively on Windows using MinGW-w64. This is one of several options for compiling ikpx2 for Windows. You could alternatively compile ikpx2 under Windows Subsystem for Linux (WSL2) or under Cygwin. The method in this tutorial has two advantages:

  1. It does not require administrator rights, unlike installing WSL2.
  2. It seems to generate noticeably faster executables than Cygwin.

For details on using WSL2 or Cygwin, see Tutorials/Compiling.

This method was tested using the following commits:

Get Git for Windows

You can download 64-bit Git for Windows from https://git-scm.com/downloads/win. When running the installer, I recommend two settings in particular:

  • Under "Windows Explorer Integration", make sure "Open Git Bash here" is selected. This will allow you to use shift+right-click on a folder in the file explorer and select "Open Git Bash here", so you don't have to use cd to get to the desired folder.
  • On the screen labeled "Configuring the terminal emulator to use with Git Bash" select "Use MinTTY (the default terminal of MSYS2)".

Get MinGW-w64

MinGW-w64 contains the C++ compiler (called g++) that we will use to compile ikpx2. There are many ways to get MinGW-w64.

Here is one way to do this that works without needing administrator privileges:

  1. Download the latest release of MinGW-w64 using the UCRT runtime for win64 with POSIX threads from https://winlibs.com/#download-release. You will probably want to download the 7-zip archive, as it's much smaller than the zip archive while containing the exact same files.
  2. Navigate to the downloaded 7-zip or zip archive and extract it to wherever you want it stored (right click and select "Extract All..."). You should put it somewhere out of the way. If you don't have administrator privileges, I suggest C:\Users\<user-name>, where <user-name> is your Windows username. This will create a new folder called "mingw64".
  3. Inside the mingw64 folder is a folder called "bin". Add the full path of the "bin" folder to your PATH environment variable. You can get the full path by navigating into the "bin" folder using the file explorer and clicking on the top bar showing the path to the folder. This will highlight the full path, which you can then copy. If you don't have administrator privileges, you probably can't edit the system PATH environment variable, but you should still be able to edit your user PATH environment variable. Look online for instructions if it's still unclear.
  4. Test g++ by opening Git Bash and running the command
    g++ -v
    The last line of the output should begin with gcc version .... If so, then the g++ compiler is ready to use.

Get Python and lifelib

You can download the 64-bit Windows installer for Python from https://www.python.org/downloads/windows/. Before you press "Install Now" or "Customize installation", make sure that "Add python.exe to Path" is checked. Warning: do not get Python from the Microsoft store, as it is incompatible with Golly.

Now go to your Windows settings, search "manage app execution aliases", and make sure the python and python3 app installers are turned off.

Once Python is installed, open the Git Bash terminal and run the following command to install lifelib:

python -m pip install --upgrade python-lifelib

Download and compile ikpx2

Compiling ikpx2 doesn't quite work with MinGW-w64 as-is, so we will need to apply a couple of patches. Download ikpx2-mingw64-patches.zip from the link below, and extract it:

https://conwaylife.com/forums/download/file.php?id=7307

You should now have two files, mingw64-ikpx2.patch and mingw64-kissat.patch, which you will need later.

In the file explorer shift+right-click on the folder where you want the ikpx2 folder to be created, and select "Open Git Bash here". If this option isn't available, you can open Git Bash from the start menu and run

cd '<full-path-to-the-desired-folder>'

Now download ikpx2 with the command

git clone https://gitlab.com/apgoucher/ikpx2

and enter the newly created ikpx2 folder with

cd ikpx2

We now need to patch ikpx2, so use file explorer to copy the file mingw64-ikpx2.patch into the ikpx2 folder and run the command

git apply mingw64-ikpx2.patch

Now download the Windows port of kissat and enter the kissat folder using the following two commands:

git clone https://github.com/sfiruch/kissat.git
cd kissat

We will need to patch kissat as well, so copy mingw64-kissat.patch to the ikpx2/kissat folder and run

git apply mingw64-kissat.patch

Now move back up to the ikpx2 folder with

cd ..

You can now compile ikpx2 by running the script

./recompile.sh --rule <rulestring>

where <rulestring> is the desired rule you want to search. When the compilation is finished, it should print

**** build process completed successfully ****

If you want to search a different rule, you will need to run the recompile script again. The first time you run the script it might take a long time, because it needs to compile the kissat and cadical libraries, but subsequent runs of the script will take much less time, as it only needs to recompile ikpx2.