Build SWI-Prolog using Microsoft Visual Studio

The migration to CMake opens the route to build SWI-Prolog on Windows using Microsoft Visual Studio. I pushed some updates to swipl-devel that allowed me building swipl.exe for single-threaded use and without GMP. The CMake config run is

mkdir build.vs2019
cd build.vs2019
cmake -DMINGW_ROOT=z:/conan/win64 -DMULTI_THREADED=OFF -DUSE_GMP=OFF -DSWIPL_PACKAGES=OFF -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -A x64 ..

z:\conan\win64 is where I installed the zlib binary (dll and include), misusing the MinGW location handling for dependencies.

Status:

  • Builds swipl.exe which seems to work fine (minimal testing)
  • swipl-win.exe fails for some Windows resource handling issue.

I’m wondering whether there are people out there who wish to take this to the next level. Some of the stuff that needs to be done:

  • Think about the whole set of requirements. I considered using Conan. This deals with quite a few dependencies. Some problematic issues are GMP and ossp-uuid. Possibly more. Possibly there are better alternatives. The ports I found are in the table below.
Name Conan place Remarks
bdb https://github.com/bincrafters/conan-libdb
gmp gmp/6.1.2@bincrafters/stable Not for Windows
jpeg libjpeg/9c@bincrafters/stable
libarchive https://github.com/appimage-conan-community/conan-libarchive
libffi libffi/3.2.1@bincrafters/stable
libyaml libyaml/0.2.2@bincrafters/stable
openssl OpenSSL/latest_1.1.1x@conan/stable
pcre pcre2/10.32@bincrafters/stable
pthread-win32 ?
uuid libuuid/1.0.3@bincrafters/stable Not the OSSP version
zlib zlib/1.2.11@conan/stable
  • Cleanup warnings
  • CMake configure is really slow on Windows. Bypass checks for many functions, headers, etc we know are not on Windows anyway.
  • Test, packaging, etc.

If you think this is a worthwhile exercise and you have relevant expertise, please jump in.

What is the advantage of compiling with MS Visual Studio?

I think Jan is trying to say that for those who develop on Windows, like me, and want to build the code from source, this would be a better means in some scenarios. AFAIK there would be no advantage to building on Windows with MS Visual Studio vs building on Linux, Mac.

So why would someone want to build SWI-Prolog from source on Windows using MS Visual Studio?

  1. If the build process is solid, e.g. doesn’t cause problems and can take care of problems like unresolved file locations by issuing errors and warnings, then SWI-Prolog could be built simply by downloading the source from GitHub, bringing the source into MS Visual Studio, (community version is free), and then just press F5 and get a running version of SWI-Prolog.

  2. If you want to add some low level functionality in C and don’t develop on Linux, then being able to write the low level C on Windows and then build on Windows would nice.

  3. If you build from source and leave in the debug info, then you can track down some really low level bugs. Luckily I have not had to do this yet with SWI-Prolog.

  4. Would not have to do a cross build on Linux for the Windows version.

  5. Customize the Windows version.

1 Like

Unfortunately it won’t be that smooth. SWI-Prolog has quite a few external dependencies and some of these are hard to get for Windows. I’m looking into Conan for that, but for now it only solves about half the dependencies and some are known to be nasty, notably the GMP library. The options seem to be to compile it using MinGW and adjust it for use with MSVC or depend on some unofficial code that can be compiled on MSVC.

Help is appreciated!

1 Like