Skip to content
Nicolas Gama edited this page Jun 12, 2024 · 5 revisions

Building in general

Installation

The library uses a classical cmake build mechanism: use cmake to create a build folder in the top level directory and run make from inside it. This assumes that the standard tool cmake is already installed on the system, and an up-to-date c/c++ compiler (i.e. g++ >=11.3.0) as well.

It will compile the shared library in optimized mode, and make install install it to the desired prefix folder (by default /usr/local/lib).

If you want to choose additional compile options (i.e. other installation folder, debug mode, tests), you need to run cmake manually and pass the desired options:

mkdir build
cd build
cmake ../src -CMAKE_INSTALL_PREFIX=/usr/
make

The available options are the following:

Variable Name values
CMAKE_INSTALL_PREFIX /usr/local installation folder (libs go in lib/ and headers in include/)
WARNING_PARANOID All warnings are shown and treated as errors. Off by default
ENABLE_TESTING Compiles unit tests and integration tests

Building for Windows

Compilation on msys2

The msys2 supports different subsystems: among them, MSYS, MINGW64, and UCRT64. The first one is a lightweight linux-like subsystem (derived from cygwin), all libs and binaries built under the MSYS toolchain will be linked against msys-2.dll, and they are meant to be used inside that environment. In the opposite, libs and binaries built under the MINGW64 or resp. UCRT64 toolchains will be linked against msvcrt.dll or resp. ucrt.dll, and can be released as standalone windows libs or programs. (more info about the subtle differences in https://www.msys2.org/docs/environments/)

Msys2 MINGW64 subsystem

Install Msys2 at https://www.msys2.org/.

Open MSYS2 MINGW64 Shell. Install the toolchain:

pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-cmake

And then gtest and benchmark (required only if ENABLE_TESTING is on):

pacman -S mingw-w64-x86_64-gtest
pacman -S mingw-w64-x86_64-benchmark

If you want to choose additional compile options (i.e. other installation folder, debug mode, tests), you need to run cmake manually and pass the desired options:

mkdir build
cd build
cmake ..
ninja

To execute binaries in the build\test, first copy spqlios\libspqlios.dll into in.

Msys2 UCRT64 subsystem

TODO?

Cross compilation on Ubuntu 24.04 with mingw64

in addition to the standard build-essentials and cmake, we need to apt-install the mingw-w64 compiler. We can use a toolchain file: ~/mingw.cmake containing:

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
set(CMAKE_C_COMPILER   x86_64-w64-mingw32-gcc-posix)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)

# where is the target environment located
set(CMAKE_FIND_ROOT_PATH  /usr/x86_64-w64-mingw32)
set(CMAKE_STAGING_PREFIX  /usr/local/mingw)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Here, by convention, we will install any dependencies in the (new) folder /usr/local/mingw.

It is a good idea to grant write access to the current unpriviledged user to this folder, such as chown -R user /usr/local/mingw this will avoid messing up with the actual system!

  1. installation of googletest: (skip if we don't intend to compile the tests)
// from the workdir
git clone https://github.com/google/googletest.git
cd googletest
mkdir build 
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw.cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local/mingw ..
make
make install # if the current user has write access to /usr/local/mingw, no sudo
  1. installation of google benchmarks (skip if we don't intend to compile the tests)
// from the workdir
git clone https://github.com/google/benchmark.git
cd benchmark
mkdir build 
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=~/perso/mingw.cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/local/mingw -DGOOGLETEST=../../googletest ..
make
make install # if the current user has write access to /usr/local/mingw, no sudo
  1. compilation of spqlios-arithmetic
// from the workdir
git clone https://github.com/tfhe/spqlios-arithmetic.git
cd spqlios-arithmetic
mkdir build 
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=~/perso/mingw.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mingw ..
make
make install # if the current user has write access to /usr/local/mingw, no sudo

If we don't need tests, use the cmake option -DENABLE_TESTING=OFF To avoid the libgcc.dll dependencies, consider adding -DCMAKE_SHARED_LINKER_FLAGS=-static: in this case, libspqlios.dll will only depend on msvcrt.dll, which is good for releases!

  1. If you want to run the tests with wine: make sure that wine has already be launched once without argument (this creates the ~/.wine) root. Only then, make sure that you have these environment variables (fine-tune the folder names of course).
export WINEPATH="/usr/lib/gcc/x86_64-w64-mingw32/13-posix;/usr/local/mingw/bin;/usr/x86_64-w64-mingw32/lib;<workdir>/spqlios-arithmetic/build/spqlios;<workdir>/spqlios-arithmetic/build/test"
export GTEST_COLOR=no

then, you can wine any .exe in the build folders!